From fb9a4e444cbf2304ce1561a99415c2cdeff2d57f Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Tue, 9 Jan 2024 14:56:55 -0600 Subject: [PATCH] Handle stop job event (#16) --- cmd/transcriber/call/transcriber.go | 22 +++++++++++++++++----- go.mod | 4 ++-- go.sum | 4 ++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/transcriber/call/transcriber.go b/cmd/transcriber/call/transcriber.go index 1662cad..91d32bc 100644 --- a/cmd/transcriber/call/transcriber.go +++ b/cmd/transcriber/call/transcriber.go @@ -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 }) @@ -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) } @@ -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) }) } diff --git a/go.mod b/go.mod index c111f25..36af69f 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 053bf0d..781015c 100644 --- a/go.sum +++ b/go.sum @@ -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=