Skip to content

Commit

Permalink
add some adjustmet for transcription service
Browse files Browse the repository at this point in the history
  • Loading branch information
tyohan committed Sep 30, 2024
1 parent 982118c commit fcccc7e
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 215 deletions.
29 changes: 26 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type Client struct {
onRenegotiation func(context.Context, webrtc.SessionDescription) (webrtc.SessionDescription, error)
onAllowedRemoteRenegotiation func()
onTracksAvailableCallbacks []func([]ITrack)
onTracksReadyCallbacks []func([]ITrack)
onNetworkConditionChangedFunc func(networkmonitor.NetworkConditionType)
// onTrack is used by SFU to take action when a new track is added to the client
onTrack func(ITrack)
Expand Down Expand Up @@ -597,7 +598,7 @@ func NewClient(s *SFU, id string, name string, peerConnectionConfig webrtc.Confi
})

peerConnection.OnNegotiationNeeded(func() {
client.renegotiate()
client.renegotiate(false)
})

return client
Expand Down Expand Up @@ -684,7 +685,7 @@ func (c *Client) Negotiate(offer webrtc.SessionDescription) (*webrtc.SessionDesc
defer func() {
c.isInRemoteNegotiation.Store(false)
if c.negotiationNeeded.Load() {
c.renegotiate()
c.renegotiate(false)
}
}()

Expand Down Expand Up @@ -844,7 +845,7 @@ func (c *Client) OnRenegotiation(callback func(context.Context, webrtc.SessionDe
c.onRenegotiation = callback
}

func (c *Client) renegotiate() {
func (c *Client) renegotiate(offerFlexFec bool) {
c.log.Debug("client: renegotiate")
c.negotiationNeeded.Store(true)

Expand Down Expand Up @@ -901,6 +902,12 @@ func (c *Client) renegotiate() {
return
}

if offerFlexFec {
// munge the offer to include FlexFEC
// get the payload code of video track

}

// Sets the LocalDescription, and starts our UDP listeners
err = c.peerConnection.PC().SetLocalDescription(offer)
if err != nil {
Expand Down Expand Up @@ -1366,6 +1373,7 @@ func (c *Client) SetTracksSourceType(trackTypes map[string]TrackType) {
// broadcast to other clients available tracks from this client
c.log.Debugf("client: %s set source tracks %d", c.ID(), len(availableTracks))
c.sfu.onTracksAvailable(c.ID(), availableTracks)
c.onTracksReady(availableTracks)
}
}

Expand Down Expand Up @@ -1708,6 +1716,7 @@ func (c *Client) SFU() *SFU {

// OnTracksAvailable event is called when the SFU is trying to publish new tracks to the client.
// The client then can subscribe to the tracks by calling `client.SubscribeTracks()` method.
// The callback will receive the list of tracks from other clients that are available to subscribe.
func (c *Client) OnTracksAvailable(callback func([]ITrack)) {
c.mu.Lock()
defer c.mu.Unlock()
Expand All @@ -1720,6 +1729,20 @@ func (c *Client) onTracksAvailable(tracks []ITrack) {
}
}

// OnTracksReady event is called when the client's tracks are use from the client
// This can be use to hook a processing like transcription/video processing to client published tracks
func (c *Client) OnTracksReady(callback func([]ITrack)) {
c.mu.Lock()
defer c.mu.Unlock()
c.onTracksReadyCallbacks = append(c.onTracksReadyCallbacks, callback)
}

func (c *Client) onTracksReady(tracks []ITrack) {
for _, callback := range c.onTracksReadyCallbacks {
callback(tracks)
}
}

// OnVoiceDetected event is called when the SFU is detecting voice activity in the room.
// The callback will receive the voice activity data that can be use for visual indicator of current speaker.
func (c *Client) OnVoiceSentDetected(callback func(activity voiceactivedetector.VoiceActivity)) {
Expand Down
Loading

0 comments on commit fcccc7e

Please sign in to comment.