Skip to content

Commit

Permalink
wsSend -> SendWS; emit WSCallJobState
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoile committed Mar 21, 2024
1 parent efacb91 commit 6785154
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions client/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (c *Client) joinCall() error {
if err := c.wsSend(wsEventJoin, CallJoinMessage{
if err := c.SendWS(wsEventJoin, CallJoinMessage{
ChannelID: c.cfg.ChannelID,
JobID: c.cfg.JobID,
}, false); err != nil {
Expand All @@ -19,15 +19,15 @@ func (c *Client) joinCall() error {
}

func (c *Client) leaveCall() error {
if err := c.wsSend(wsEventLeave, nil, false); err != nil {
if err := c.SendWS(wsEventLeave, nil, false); err != nil {
return fmt.Errorf("failed to send ws msg: %w", err)
}

return nil
}

func (c *Client) reconnectCall() error {
if err := c.wsSend(wsEventReconnect, CallReconnectMessage{
if err := c.SendWS(wsEventReconnect, CallReconnectMessage{
ChannelID: c.cfg.ChannelID,
OriginalConnID: c.originalConnID,
PrevConnID: c.currentConnID,
Expand Down
6 changes: 1 addition & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
WSDisconnectEvent = "WSDisconnect"
WSCallJoinEvent = "WSCallJoin"
WSCallRecordingState = "WSCallRecordingState"
WSCallJobState = "WSCallJobState"
WSJobStopEvent = "WSStopJobEvent"
RTCConnectEvent = "RTCConnect"
RTCDisconnectEvent = "RTCDisconnect"
Expand Down Expand Up @@ -140,11 +141,6 @@ func (c *Client) On(eventType EventType, h EventHandler) {
c.handlers[eventType] = h
}

// SendWs sends a websocket event to the server
func (c *Client) SendWs(ev string, msg any, binary bool) error {
return c.wsSend(ev, msg, binary)
}

func (c *Client) emit(eventType EventType, ctx any) {
c.mut.RLock()
handler := c.handlers[eventType]
Expand Down
6 changes: 3 additions & 3 deletions client/rtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Client) handleWSEventSignal(evData map[string]any) error {
return fmt.Errorf("failed to encode answer: %w", err)
}
w.Close()
return c.wsSend(wsEventSDP, map[string]any{
return c.SendWS(wsEventSDP, map[string]any{
"data": sdpData.Bytes(),
}, true)
case signalMsgAnswer:
Expand Down Expand Up @@ -158,7 +158,7 @@ func (c *Client) initRTCSession() error {
return
}

if err := c.wsSend(wsEventICE, map[string]any{
if err := c.SendWS(wsEventICE, map[string]any{
"data": string(data),
}, true); err != nil {
log.Printf(err.Error())
Expand Down Expand Up @@ -258,7 +258,7 @@ func (c *Client) initRTCSession() error {
return
}
w.Close()
err = c.wsSend(wsEventSDP, map[string]any{
err = c.SendWS(wsEventSDP, map[string]any{
"data": sdpData.Bytes(),
}, true)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion client/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
errCallEnded = errors.New("call ended")
)

func (c *Client) wsSend(ev string, msg any, binary bool) error {
func (c *Client) SendWS(ev string, msg any, binary bool) error {
c.mut.Lock()
defer c.mut.Unlock()

Expand Down Expand Up @@ -190,6 +190,10 @@ func (c *Client) handleWSMsg(msg ws.Message) error {
}
var recState CallJobState
recState.FromMap(data)
c.emit(WSCallJobState, recState)

// Below is deprecated as of v0.14.0, kept for compatibility with earlier versions
// of transcriber
if recState.Type != "recording" {
return nil
}
Expand Down

0 comments on commit 6785154

Please sign in to comment.