diff --git a/client/call.go b/client/call.go index 74fc3eb..a1dfb39 100644 --- a/client/call.go +++ b/client/call.go @@ -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 { @@ -19,7 +19,7 @@ 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) } @@ -27,7 +27,7 @@ func (c *Client) leaveCall() error { } 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, diff --git a/client/client.go b/client/client.go index 27a3a12..a8921da 100644 --- a/client/client.go +++ b/client/client.go @@ -24,6 +24,7 @@ const ( WSDisconnectEvent = "WSDisconnect" WSCallJoinEvent = "WSCallJoin" WSCallRecordingState = "WSCallRecordingState" + WSCallJobState = "WSCallJobState" WSJobStopEvent = "WSStopJobEvent" RTCConnectEvent = "RTCConnect" RTCDisconnectEvent = "RTCDisconnect" diff --git a/client/rtc.go b/client/rtc.go index 942f267..cb42e9f 100644 --- a/client/rtc.go +++ b/client/rtc.go @@ -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: @@ -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()) @@ -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 { diff --git a/client/types.go b/client/types.go index ec842a7..d3f0d20 100644 --- a/client/types.go +++ b/client/types.go @@ -17,6 +17,7 @@ type CallReconnectMessage struct { } type CallJobState struct { + Type string `json:"type"` InitAt int64 `json:"init_at"` StartAt int64 `json:"start_at"` EndAt int64 `json:"end_at"` @@ -24,11 +25,13 @@ type CallJobState struct { } func (cjs *CallJobState) FromMap(m map[string]any) { + jobType, _ := m["type"].(string) initAt, _ := m["init_at"].(float64) startAt, _ := m["start_at"].(float64) endAt, _ := m["end_at"].(float64) err, _ := m["err"].(string) + cjs.Type = jobType cjs.InitAt = int64(initAt) cjs.StartAt = int64(startAt) cjs.EndAt = int64(endAt) diff --git a/client/websocket.go b/client/websocket.go index 01aedec..0a019cf 100644 --- a/client/websocket.go +++ b/client/websocket.go @@ -28,17 +28,17 @@ const ( ) const ( - wsEventJoin = wsEvPrefix + "join" - wsEventLeave = wsEvPrefix + "leave" - wsEventReconnect = wsEvPrefix + "reconnect" - wsEventSignal = wsEvPrefix + "signal" - wsEventICE = wsEvPrefix + "ice" - wsEventSDP = wsEvPrefix + "sdp" - wsEventError = wsEvPrefix + "error" - wsEventUserLeft = wsEvPrefix + "user_left" - wsEventCallEnd = wsEvPrefix + "call_end" - wsEventCallRecordingState = wsEvPrefix + "call_recording_state" - wsEventJobStop = wsEvPrefix + "job_stop" + wsEventJoin = wsEvPrefix + "join" + wsEventLeave = wsEvPrefix + "leave" + wsEventReconnect = wsEvPrefix + "reconnect" + wsEventSignal = wsEvPrefix + "signal" + wsEventICE = wsEvPrefix + "ice" + wsEventSDP = wsEvPrefix + "sdp" + wsEventError = wsEvPrefix + "error" + wsEventUserLeft = wsEvPrefix + "user_left" + wsEventCallEnd = wsEvPrefix + "call_end" + wsEventCallJobState = wsEvPrefix + "call_job_state" + wsEventJobStop = wsEvPrefix + "job_stop" ) var ( @@ -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() @@ -183,14 +183,20 @@ func (c *Client) handleWSMsg(msg ws.Message) error { log.Printf("received call end event, closing client") return errCallEnded } - case wsEventCallRecordingState: - data, ok := ev.GetData()["recState"].(map[string]any) + case wsEventCallJobState: + data, ok := ev.GetData()["jobState"].(map[string]any) if !ok { return fmt.Errorf("invalid recording state") } - var recState CallJobState - recState.FromMap(data) - c.emit(WSCallRecordingState, recState) + var jobState CallJobState + jobState.FromMap(data) + c.emit(WSCallJobState, jobState) + + // Below is deprecated as of v0.14.0, kept for compatibility with earlier versions + // of transcriber + if jobState.Type == "recording" { + c.emit(WSCallRecordingState, jobState) + } case wsEventJobStop: jobID, _ := ev.GetData()["job_id"].(string) c.emit(WSJobStopEvent, jobID)