Skip to content

Commit

Permalink
Handle stop job event (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Jan 9, 2024
1 parent d9fa87a commit fb9a4e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
22 changes: 17 additions & 5 deletions cmd/transcriber/call/transcriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func (t *Transcriber) Start(ctx context.Context) error {
})
t.client.On(client.RTCTrackEvent, t.handleTrack)
t.client.On(client.CloseEvent, func(_ any) error {
go func() {
t.done(t.handleClose())
}()
go t.done()
return nil
})

Expand All @@ -103,6 +101,20 @@ func (t *Transcriber) Start(ctx context.Context) error {
return nil
})

t.client.On(client.WSJobStopEvent, func(ctx any) error {
jobID, _ := ctx.(string)
if jobID == "" {
return fmt.Errorf("unexpected empty jobID")
}

if jobID == t.cfg.TranscriptionID {
slog.Info("received job stop event, exiting")
go t.done()
}

return nil
})

if err := t.client.Connect(); err != nil {
return fmt.Errorf("failed to connect: %w", err)
}
Expand Down Expand Up @@ -151,9 +163,9 @@ func (t *Transcriber) Err() error {
}
}

func (t *Transcriber) done(err error) {
func (t *Transcriber) done() {
t.doneOnce.Do(func() {
t.errCh <- err
t.errCh <- t.handleClose()
close(t.doneCh)
})
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.21.4
require (
github.com/mattermost/mattermost-plugin-calls/server/public v0.0.3
github.com/mattermost/mattermost/server/public v0.0.6
github.com/mattermost/rtcd v0.12.1-0.20231121174414-6a5686281335
github.com/mattermost/rtcd v0.12.1-0.20240105175112-64f91e1de8e0
github.com/pion/interceptor v0.1.25
github.com/pion/randutil v0.1.0
github.com/pion/rtp v1.8.3
github.com/pion/webrtc/v3 v3.2.21
Expand All @@ -32,7 +33,6 @@ require (
github.com/pion/datachannel v1.5.5 // indirect
github.com/pion/dtls/v2 v2.2.7 // indirect
github.com/pion/ice/v2 v2.3.11 // indirect
github.com/pion/interceptor v0.1.25 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.9 // indirect
github.com/pion/rtcp v1.2.12 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ github.com/mattermost/mattermost-plugin-calls/server/public v0.0.3 h1:KYs2mcdufW
github.com/mattermost/mattermost-plugin-calls/server/public v0.0.3/go.mod h1:9a5FoYxu9rPCvV4FEo0DkJSqqCZ80FCeB9Y4haBI2FQ=
github.com/mattermost/mattermost/server/public v0.0.6 h1:FUaJ+P36E3Tt12Umdm8p1h7sZNUeObDk3p3aFTaBkCo=
github.com/mattermost/mattermost/server/public v0.0.6/go.mod h1:Y7Ht1haGGrsuYzX73HhpSe2VnbGLuZj2/tsQslHd2/M=
github.com/mattermost/rtcd v0.12.1-0.20231121174414-6a5686281335 h1:PaE1X/fJftk0FgX9YjvToWnSuF4Mr77K5tuU90LRDSc=
github.com/mattermost/rtcd v0.12.1-0.20231121174414-6a5686281335/go.mod h1:SK7+TEIpUD/rx53RUiy5KotiBzv1h08PujbK87/jw6M=
github.com/mattermost/rtcd v0.12.1-0.20240105175112-64f91e1de8e0 h1:i3gCGvuCDA/p4hWl87eeXdnXvbanZx2uwyG++99NFKc=
github.com/mattermost/rtcd v0.12.1-0.20240105175112-64f91e1de8e0/go.mod h1:M2F8N5aipH6Rne8+CYp/QiaFLy6iru3nTt6u/FUxhXs=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down

0 comments on commit fb9a4e4

Please sign in to comment.