@@ -277,26 +277,23 @@ export class SFUMeetingManager {
277277 } ) ) ,
278278 ) ;
279279
280- const currentUserId = this . getCurrentUserId ( ) ;
281-
282280 for ( const producerInfo of existingProducers ) {
283- const pid =
281+ const participantId =
284282 producerInfo . participantId ||
285283 producerInfo . user_id ||
286284 producerInfo . userId ;
287285
288- if ( pid === currentUserId ) {
289- continue ;
290- }
291-
292- const metadata = { isScreen : ! ! producerInfo . isScreen } ;
293286 console . log ( "Subscribing to existing producer:" , {
294287 producerId : producerInfo . id ,
295- participantId : pid ,
288+ participantId,
296289 kind : producerInfo . kind ,
297290 isScreen : ! ! producerInfo . isScreen ,
298291 } ) ;
299- await this . subscribeToProducer ( producerInfo . id , pid , metadata ) ;
292+ await this . subscribeToRemoteProducer ( {
293+ producerId : producerInfo . id ,
294+ participantId,
295+ isScreen : producerInfo . isScreen ,
296+ } ) ;
300297 }
301298 } else {
302299 console . log ( "No existing producers found" ) ;
@@ -341,6 +338,20 @@ export class SFUMeetingManager {
341338 }
342339 }
343340
341+ async subscribeToRemoteProducer ( { producerId, participantId, isScreen } ) {
342+ if ( ! producerId || ! participantId ) {
343+ return null ;
344+ }
345+
346+ if ( participantId === this . getCurrentUserId ( ) ) {
347+ return null ;
348+ }
349+
350+ return this . subscribeToProducer ( producerId , participantId , {
351+ isScreen : ! ! isScreen ,
352+ } ) ;
353+ }
354+
344355 async handleNewConsumer ( consumer ) {
345356 const { participantId, kind, track, isScreen } = consumer ;
346357
@@ -486,16 +497,11 @@ export class SFUMeetingManager {
486497 continue ;
487498 }
488499
489- const isSelf = event . participantId === this . getCurrentUserId ( ) ;
490- const isScreen = ! ! event . isScreen ;
491- if ( ! isSelf ) {
492- const metadata = { isScreen } ;
493- await this . subscribeToProducer (
494- event . producerId ,
495- event . participantId ,
496- metadata ,
497- ) ;
498- }
500+ await this . subscribeToRemoteProducer ( {
501+ producerId : event . producerId ,
502+ participantId : event . participantId ,
503+ isScreen : event . isScreen ,
504+ } ) ;
499505 } catch ( error ) {
500506 console . warn ( "Failed to process buffered producer:" , error ) ;
501507 }
@@ -532,16 +538,11 @@ export class SFUMeetingManager {
532538 return ;
533539 }
534540
535- const isSelf = data . participantId === this . getCurrentUserId ( ) ;
536- const isScreen = ! ! data . isScreen ;
537- if ( ! isSelf ) {
538- const metadata = { isScreen } ;
539- await this . subscribeToProducer (
540- data . producerId ,
541- data . participantId ,
542- metadata ,
543- ) ;
544- }
541+ await this . subscribeToRemoteProducer ( {
542+ producerId : data . producerId ,
543+ participantId : data . participantId ,
544+ isScreen : data . isScreen ,
545+ } ) ;
545546 } ) ;
546547
547548 this . sfuClient . on ( "producer_closed" , ( data ) => {
0 commit comments