@@ -61,6 +61,8 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
61
61
this . _sdpResolvers = [ ] ; // [{finish, resolve, reject}]
62
62
this . _sdpResolveNum = 0 ;
63
63
this . _remoteMediaStreams = new Map ( ) ; // Key is subscription ID, value is MediaStream.
64
+
65
+ this . _createPeerConnection ( ) ;
64
66
}
65
67
66
68
/**
@@ -129,14 +131,29 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
129
131
mid : t . mid ,
130
132
} ;
131
133
} ) ;
132
- const publicationId =
133
- await this . _signaling . sendSignalingMessage ( 'publish' , {
134
- media : { tracks : trackOptions } ,
135
- attributes : stream . attributes ,
136
- transport : { id : this . _id , type : 'webrtc' } ,
137
- } ) . id ;
134
+ const publicationResp =
135
+ await this . _signaling . sendSignalingMessage ( 'publish' , {
136
+ media : { tracks : trackOptions } ,
137
+ attributes : stream . attributes ,
138
+ transport : { id : this . _id , type : 'webrtc' } ,
139
+ } ) ;
140
+ const publicationId = publicationResp . id ;
138
141
this . _publishTransceivers . get ( internalId ) . id = publicationId ;
139
142
this . _reverseIdMap . set ( publicationId , internalId ) ;
143
+
144
+ if ( this . _id && this . _id !== publicationResp . transportId ) {
145
+ Logger . warning ( 'Server returns conflict ID: ' + publicationResp
146
+ . transportId ) ;
147
+ return ;
148
+ }
149
+ this . _id = publicationResp . transportId ;
150
+
151
+ const messageEvent = new MessageEvent ( 'id' , {
152
+ message : publicationId ,
153
+ origin : this . _remoteId ,
154
+ } ) ;
155
+ this . dispatchEvent ( messageEvent ) ;
156
+
140
157
await this . _signaling . sendSignalingMessage (
141
158
'soac' , { id : this . _id , signaling : offer } ) ;
142
159
return new Promise ( ( resolve , reject ) => {
@@ -223,7 +240,6 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
223
240
}
224
241
}
225
242
const mediaOptions = { } ;
226
- this . _createPeerConnection ( ) ;
227
243
if ( stream . mediaStream . getAudioTracks ( ) . length > 0 && options . audio !==
228
244
false && options . audio !== null ) {
229
245
if ( stream . mediaStream . getAudioTracks ( ) . length > 1 ) {
@@ -373,20 +389,21 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
373
389
} ) ;
374
390
} ) . then ( ( data ) => {
375
391
const publicationId = data . id ;
376
- const messageEvent = new MessageEvent ( 'id' , {
377
- message : publicationId ,
378
- origin : this . _remoteId ,
379
- } ) ;
380
- this . dispatchEvent ( messageEvent ) ;
381
-
382
392
this . _publishTransceivers . get ( internalId ) . id = publicationId ;
383
393
this . _reverseIdMap . set ( publicationId , internalId ) ;
384
394
385
395
if ( this . _id && this . _id !== data . transportId ) {
386
396
Logger . warning ( 'Server returns conflict ID: ' + data . transportId ) ;
397
+ return ;
387
398
}
388
399
this . _id = data . transportId ;
389
400
401
+ const messageEvent = new MessageEvent ( 'id' , {
402
+ message : publicationId ,
403
+ origin : this . _remoteId ,
404
+ } ) ;
405
+ this . dispatchEvent ( messageEvent ) ;
406
+
390
407
// Modify local SDP before sending
391
408
if ( options ) {
392
409
transceivers . forEach ( ( { type, transceiver, option} ) => {
@@ -511,7 +528,6 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
511
528
512
529
const offerOptions = { } ;
513
530
const transceivers = [ ] ;
514
- this . _createPeerConnection ( ) ;
515
531
if ( typeof this . pc . addTransceiver === 'function' ) {
516
532
// |direction| seems not working on Safari.
517
533
if ( mediaOptions . audio ) {
@@ -577,19 +593,20 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
577
593
} ) ;
578
594
} ) . then ( ( data ) => {
579
595
const subscriptionId = data . id ;
580
- const messageEvent = new MessageEvent ( 'id' , {
581
- message : subscriptionId ,
582
- origin : this . _remoteId ,
583
- } ) ;
584
- this . dispatchEvent ( messageEvent ) ;
585
-
586
596
this . _subscribeTransceivers . get ( internalId ) . id = subscriptionId ;
587
597
this . _reverseIdMap . set ( subscriptionId , internalId ) ;
588
598
if ( this . _id && this . _id !== data . transportId ) {
589
599
Logger . warning ( 'Server returns conflict ID: ' + data . transportId ) ;
600
+ return ;
590
601
}
591
602
this . _id = data . transportId ;
592
603
604
+ const messageEvent = new MessageEvent ( 'id' , {
605
+ message : subscriptionId ,
606
+ origin : this . _remoteId ,
607
+ } ) ;
608
+ this . dispatchEvent ( messageEvent ) ;
609
+
593
610
// Modify local SDP before sending
594
611
if ( options ) {
595
612
transceivers . forEach ( ( { type, transceiver, option} ) => {
@@ -898,6 +915,8 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
898
915
899
916
_createPeerConnection ( ) {
900
917
if ( this . pc ) {
918
+ Logger . warning ( 'A PeerConnection was created. Cannot create again for ' +
919
+ 'the same PeerConnectionChannel.' ) ;
901
920
return ;
902
921
}
903
922
0 commit comments