1- import { differenceBy , intersection } from 'lodash' ;
1+ import { differenceBy } from 'lodash' ;
22import { Constants } from 'stanza' ;
33
44import {
88 IExtendedMediaSession ,
99 IParticipantUpdate ,
1010 IParticipantsUpdate ,
11- IOnScreenParticipantsUpdate ,
12- ISpeakersUpdate ,
1311 IConversationParticipant ,
1412 IMediaRequestOptions ,
1513 IStartVideoSessionParams ,
@@ -26,35 +24,6 @@ import { ConversationUpdate } from '../conversations/conversation-update';
2624import { JsonRpcMessage } from 'genesys-cloud-streaming-client' ;
2725import { jwtDecode } from "jwt-decode" ;
2826
29- /**
30- * speakers is an array of audio track ids sending audio
31- */
32- export interface IMediaChangeEvent {
33- eventBody : {
34- id : string ,
35- participants : IMediaChangeEventParticipant [ ] ,
36- speakers : string [ ]
37- } ;
38- metadata : {
39- CorrelationId : string
40- } ;
41- }
42-
43- /**
44- * sinks represents outgoing paths for this track. For example, if we have a track that looks like { id: "1", mediaType: "audio", sinks: ["a", "b"] }
45- * then we know that the audio of track "1" can be heard on tracks "a" and "b". Another way to say this is whichever participants are receiving
46- * tracks "a" or "b" are hearing this participant
47- */
48- export interface IMediaChangeEventParticipant {
49- communicationId : string ;
50- userId : string ;
51- tracks : {
52- id : string ,
53- mediaType : 'audio' | 'video' ,
54- sinks ?: string [ ]
55- } [ ] ;
56- }
57-
5827export class VideoSessionHandler extends BaseSessionHandler {
5928 requestedSessions : { [ roomJid : string ] : boolean } = { } ;
6029 requestedMeetingSessions : { [ meetingId : string ] : boolean } = { } ;
@@ -165,91 +134,6 @@ export class VideoSessionHandler extends BaseSessionHandler {
165134 session . emit ( 'participantsUpdate' , update ) ;
166135 }
167136
168- updateParticipantsOnScreen ( session : VideoMediaSession , mediaUpdateEvent : IMediaChangeEvent ) {
169- const incomingVideoTrackIds = session . pc . getReceivers ( )
170- . filter ( ( receiver ) => receiver . track && receiver . track . kind === 'video' )
171- . map ( ( receiver ) => receiver . track . id ) ;
172-
173- /**
174- * Firefox messes the trackIds up from what is actually in the sdp offer.
175- * Need to pull it from the offer to accurately match the track.sinks
176- */
177- const incomingVideoMsidTrackId = this . getTrackIdFromSdp ( session . pc . remoteDescription . sdp , 'video' ) ;
178-
179- if ( incomingVideoMsidTrackId ) {
180- incomingVideoTrackIds . push ( incomingVideoMsidTrackId ) ;
181- }
182-
183- const onScreenParticipants : Array < { userId : string } > = [ ] ;
184- mediaUpdateEvent . eventBody . participants . forEach ( ( updateParticipant : IMediaChangeEventParticipant ) => {
185- const matchingVideoTracks = updateParticipant . tracks
186- . filter ( ( track ) => track . mediaType === 'video' )
187- . filter ( ( track ) => {
188- const intersectingTracks = intersection ( track . sinks , incomingVideoTrackIds ) ;
189- return intersectingTracks . length ;
190- } ) ;
191-
192- if ( matchingVideoTracks . length ) {
193- onScreenParticipants . push ( { userId : updateParticipant . userId } ) ;
194- }
195- } ) ;
196-
197- const lastUpdate : IOnScreenParticipantsUpdate = session . _lastOnScreenUpdate || { participants : [ ] } as any ;
198-
199- // send out an update if the onScreenParticipants count or items changed
200- if ( lastUpdate . participants . length === onScreenParticipants . length ) {
201- const changed = differenceBy ( lastUpdate . participants , onScreenParticipants , 'userId' ) . length ||
202- differenceBy ( lastUpdate . participants , onScreenParticipants , 'userId' ) . length ;
203-
204- if ( ! changed ) {
205- return ;
206- }
207- }
208-
209- const update : IOnScreenParticipantsUpdate = {
210- participants : onScreenParticipants
211- } ;
212-
213- session . _lastOnScreenUpdate = update ;
214- session . emit ( 'activeVideoParticipantsUpdate' , update ) ;
215- }
216-
217- updateSpeakers ( session : IExtendedMediaSession , mediaUpdateEvent : IMediaChangeEvent ) {
218- const incomingAudioTrackIds = session . pc . getReceivers ( )
219- . filter ( ( receiver ) => receiver . track && receiver . track . kind === 'audio' )
220- . map ( ( receiver ) => receiver . track . id ) ;
221-
222- /**
223- * Firefox messes the trackIds up from what is actually in the sdp offer.
224- * Need to pull it from the offer to accurately match the track.sinks
225- */
226- const incomingAudioMsidTrackId = this . getTrackIdFromSdp ( session . pc . remoteDescription . sdp , 'audio' ) ;
227-
228- if ( incomingAudioMsidTrackId ) {
229- incomingAudioTrackIds . push ( incomingAudioMsidTrackId ) ;
230- }
231-
232- const speakingParticipants : Array < { userId : string } > = [ ] ;
233- mediaUpdateEvent . eventBody . participants . forEach ( ( updateParticipant : IMediaChangeEventParticipant ) => {
234- const matchingAudioTracks = updateParticipant . tracks
235- . filter ( ( track ) => track . mediaType === 'audio' )
236- . filter ( ( track ) => {
237- const intersectingTracks = intersection ( track . sinks , incomingAudioTrackIds ) ;
238- return intersectingTracks . length ;
239- } ) ;
240-
241- if ( matchingAudioTracks . length ) {
242- speakingParticipants . push ( { userId : updateParticipant . userId } ) ;
243- }
244- } ) ;
245-
246- const update : ISpeakersUpdate = {
247- speakers : speakingParticipants
248- } ;
249-
250- session . emit ( 'speakersUpdate' , update ) ;
251- }
252-
253137 // triggers a propose from the backend
254138 async startSession ( startParams : IStartVideoSessionParams | IStartVideoMeetingSessionParams ) : Promise < { conversationId : string } > {
255139 if ( "jid" in startParams ) {
@@ -414,10 +298,6 @@ export class VideoSessionHandler extends BaseSessionHandler {
414298 }
415299
416300 session . _outboundStream = stream ;
417- // If using a JWT, we can't subscribe to the media change events.
418- if ( ! this . sdk . _config . jwt ) {
419- await this . sdk . _streamingConnection . notifications . subscribe ( `v2.conversations.${ session . conversationId } .media` , this . handleMediaChangeEvent . bind ( this , session ) ) ;
420- }
421301
422302 await this . addMediaToSession ( session , stream ) ;
423303
@@ -699,11 +579,6 @@ export class VideoSessionHandler extends BaseSessionHandler {
699579 }
700580 }
701581
702- handleMediaChangeEvent ( session : VideoMediaSession , event : IMediaChangeEvent ) : void {
703- this . updateParticipantsOnScreen ( session , event ) ;
704- this . updateSpeakers ( session , event ) ;
705- }
706-
707582 async startScreenShare ( session : VideoMediaSession ) : Promise < void > {
708583 session . _resurrectVideoOnScreenShareEnd = ! session . videoMuted ;
709584 try {
0 commit comments