Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-56540 - Live Captions: add client.Send #130

Merged
merged 10 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading