Skip to content

Commit

Permalink
Use stream ids instead of track ids (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Mar 24, 2022
1 parent f61fdcb commit 6e94eb6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
15 changes: 7 additions & 8 deletions server/channel_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ type callStats struct {
}

type callState struct {
ID string `json:"id"`
StartAt int64 `json:"create_at"`
Users map[string]*userState `json:"users,omitempty"`
ThreadID string `json:"thread_id"`
ScreenSharingID string `json:"screen_sharing_id"`
ScreenTrackID string `json:"screen_track_id"`
ScreenAudioTrackID string `json:"screen_audio_track_id"`
Stats callStats `json:"stats"`
ID string `json:"id"`
StartAt int64 `json:"create_at"`
Users map[string]*userState `json:"users,omitempty"`
ThreadID string `json:"thread_id"`
ScreenSharingID string `json:"screen_sharing_id"`
ScreenStreamID string `json:"screen_stream_id"`
Stats callStats `json:"stats"`
}

type channelState struct {
Expand Down
3 changes: 1 addition & 2 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ func (p *Plugin) removeUserSession(userID, channelID string) (channelState, chan

if state.Call.ScreenSharingID == userID {
state.Call.ScreenSharingID = ""
state.Call.ScreenTrackID = ""
state.Call.ScreenAudioTrackID = ""
state.Call.ScreenStreamID = ""
if call := p.getCall(channelID); call != nil {
call.setScreenSession(nil)
}
Expand Down
8 changes: 4 additions & 4 deletions server/sfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (p *Plugin) initRTCConn(userID string) {
p.LogDebug(fmt.Sprintf("%+v", remoteTrack.Codec().RTPCodecCapability))
p.LogDebug(fmt.Sprintf("Track has started, of type %d: %s", remoteTrack.PayloadType(), remoteTrack.Codec().MimeType))

trackID := remoteTrack.ID()
streamID := remoteTrack.StreamID()
state, err := p.kvGetChannelState(userSession.channelID)
if err != nil {
p.LogError(err.Error())
Expand All @@ -367,7 +367,7 @@ func (p *Plugin) initRTCConn(userID string) {

if remoteTrack.Codec().MimeType == rtpAudioCodec.MimeType {
trackType := "voice"
if trackID != "" && trackID == state.Call.ScreenAudioTrackID {
if streamID == state.Call.ScreenStreamID {
p.LogDebug("received screen sharing audio track")
trackType = "screen-audio"
}
Expand Down Expand Up @@ -432,8 +432,8 @@ func (p *Plugin) initRTCConn(userID string) {

}
} else if remoteTrack.Codec().MimeType == rtpVideoCodecVP8.MimeType {
if trackID == "" || trackID != state.Call.ScreenTrackID {
p.LogError("received unexpected video track", "trackID", trackID)
if streamID != state.Call.ScreenStreamID {
p.LogError("received unexpected video track", "streamID", streamID, "ScreenStreamID", state.Call.ScreenStreamID)
return
}

Expand Down
6 changes: 2 additions & 4 deletions server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ func (p *Plugin) handleClientMessageTypeScreen(msg clientMessage, channelID, use
return nil, fmt.Errorf("cannot start screen sharing, someone else is sharing already: %q", state.Call.ScreenSharingID)
}
state.Call.ScreenSharingID = userID
state.Call.ScreenTrackID = data["screenTrackID"]
state.Call.ScreenAudioTrackID = data["screenAudioTrackID"]
state.Call.ScreenStreamID = data["screenStreamID"]
} else {
if state.Call.ScreenSharingID != userID {
return nil, fmt.Errorf("cannot stop screen sharing, someone else is sharing already: %q", state.Call.ScreenSharingID)
}
state.Call.ScreenSharingID = ""
state.Call.ScreenTrackID = ""
state.Call.ScreenAudioTrackID = ""
state.Call.ScreenStreamID = ""
if call := p.getCall(channelID); call != nil {
call.setScreenSession(nil)
}
Expand Down
3 changes: 1 addition & 2 deletions webapp/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ export default class CallsClient extends EventEmitter {

this.ws.send('screen_on', {
data: JSON.stringify({
screenTrackID: screenTrack.id,
screenAudioTrackID: screenAudioTrack?.id,
screenStreamID: screenStream.id,
}),
});
}
Expand Down

0 comments on commit 6e94eb6

Please sign in to comment.