@@ -475,7 +475,6 @@ test('basic connection establishment', function(t) {
475
475
var pc2 = new RTCPeerConnection ( null ) ;
476
476
var ended = false ;
477
477
478
- pc1 . createDataChannel ( 'somechannel' ) ;
479
478
pc1 . oniceconnectionstatechange = function ( ) {
480
479
if ( pc1 . iceConnectionState === 'connected' ||
481
480
pc1 . iceConnectionState === 'completed' ) {
@@ -507,67 +506,73 @@ test('basic connection establishment', function(t) {
507
506
addCandidate ( pc1 , event ) ;
508
507
} ;
509
508
510
- pc1 . createOffer (
511
- function ( offer ) {
512
- t . pass ( 'pc1.createOffer' ) ;
513
- pc1 . setLocalDescription ( offer ,
514
- function ( ) {
515
- t . pass ( 'pc1.setLocalDescription' ) ;
516
-
517
- offer = new RTCSessionDescription ( offer ) ;
518
- t . pass ( 'created RTCSessionDescription from offer' ) ;
519
- pc2 . setRemoteDescription ( offer ,
520
- function ( ) {
521
- t . pass ( 'pc2.setRemoteDescription' ) ;
522
- pc2 . createAnswer (
523
- function ( answer ) {
524
- t . pass ( 'pc2.createAnswer' ) ;
525
- pc2 . setLocalDescription ( answer ,
526
- function ( ) {
527
- t . pass ( 'pc2.setLocalDescription' ) ;
528
- answer = new RTCSessionDescription ( answer ) ;
529
- t . pass ( 'created RTCSessionDescription from answer' ) ;
530
- pc1 . setRemoteDescription ( answer ,
531
- function ( ) {
532
- t . pass ( 'pc1.setRemoteDescription' ) ;
533
- } ,
534
- function ( err ) {
535
- t . fail ( 'pc1.setRemoteDescription ' + err . toString ( ) ) ;
536
- }
537
- ) ;
538
- } ,
539
- function ( err ) {
540
- t . fail ( 'pc2.setLocalDescription ' + err . toString ( ) ) ;
541
- }
542
- ) ;
543
- } ,
544
- function ( err ) {
545
- t . fail ( 'pc2.createAnswer ' + err . toString ( ) ) ;
546
- }
547
- ) ;
548
- } ,
549
- function ( err ) {
550
- t . fail ( 'pc2.setRemoteDescription ' + err . toString ( ) ) ;
551
- }
552
- ) ;
553
- } ,
554
- function ( err ) {
555
- t . fail ( 'pc1.setLocalDescription ' + err . toString ( ) ) ;
556
- }
557
- ) ;
558
- } ,
559
- function ( err ) {
560
- t . fail ( 'pc1 failed to create offer ' + err . toString ( ) ) ;
561
- }
562
- ) ;
509
+ var constraints = { video : true , fake : true } ;
510
+ navigator . mediaDevices . getUserMedia ( constraints )
511
+ . then ( function ( stream ) {
512
+ pc1 . addStream ( stream ) ;
513
+
514
+ pc1 . createOffer (
515
+ function ( offer ) {
516
+ t . pass ( 'pc1.createOffer' ) ;
517
+ pc1 . setLocalDescription ( offer ,
518
+ function ( ) {
519
+ t . pass ( 'pc1.setLocalDescription' ) ;
520
+
521
+ offer = new RTCSessionDescription ( offer ) ;
522
+ t . pass ( 'created RTCSessionDescription from offer' ) ;
523
+ pc2 . setRemoteDescription ( offer ,
524
+ function ( ) {
525
+ t . pass ( 'pc2.setRemoteDescription' ) ;
526
+ pc2 . createAnswer (
527
+ function ( answer ) {
528
+ t . pass ( 'pc2.createAnswer' ) ;
529
+ pc2 . setLocalDescription ( answer ,
530
+ function ( ) {
531
+ t . pass ( 'pc2.setLocalDescription' ) ;
532
+ answer = new RTCSessionDescription ( answer ) ;
533
+ t . pass ( 'created RTCSessionDescription from answer' ) ;
534
+ pc1 . setRemoteDescription ( answer ,
535
+ function ( ) {
536
+ t . pass ( 'pc1.setRemoteDescription' ) ;
537
+ } ,
538
+ function ( err ) {
539
+ t . fail ( 'pc1.setRemoteDescription ' +
540
+ err . toString ( ) ) ;
541
+ }
542
+ ) ;
543
+ } ,
544
+ function ( err ) {
545
+ t . fail ( 'pc2.setLocalDescription ' + err . toString ( ) ) ;
546
+ }
547
+ ) ;
548
+ } ,
549
+ function ( err ) {
550
+ t . fail ( 'pc2.createAnswer ' + err . toString ( ) ) ;
551
+ }
552
+ ) ;
553
+ } ,
554
+ function ( err ) {
555
+ t . fail ( 'pc2.setRemoteDescription ' + err . toString ( ) ) ;
556
+ }
557
+ ) ;
558
+ } ,
559
+ function ( err ) {
560
+ t . fail ( 'pc1.setLocalDescription ' + err . toString ( ) ) ;
561
+ }
562
+ ) ;
563
+ } ,
564
+ function ( err ) {
565
+ t . fail ( 'pc1 failed to create offer ' + err . toString ( ) ) ;
566
+ }
567
+ ) ;
568
+ } ) ;
563
569
} ) ;
564
570
565
571
test ( 'basic connection establishment with promise' , function ( t ) {
566
572
var pc1 = new RTCPeerConnection ( null ) ;
567
573
var pc2 = new RTCPeerConnection ( null ) ;
568
574
var ended = false ;
569
575
570
- pc1 . createDataChannel ( 'somechannel' ) ;
571
576
pc1 . oniceconnectionstatechange = function ( ) {
572
577
if ( pc1 . iceConnectionState === 'connected' ||
573
578
pc1 . iceConnectionState === 'completed' ) {
@@ -594,6 +599,70 @@ test('basic connection establishment with promise', function(t) {
594
599
addCandidate ( pc1 , event ) ;
595
600
} ;
596
601
602
+ var constraints = { video : true , fake : true } ;
603
+ navigator . mediaDevices . getUserMedia ( constraints )
604
+ . then ( function ( stream ) {
605
+ pc1 . addStream ( stream ) ;
606
+ pc1 . createOffer ( ) . then ( function ( offer ) {
607
+ t . pass ( 'pc1.createOffer' ) ;
608
+ return pc1 . setLocalDescription ( offer ) ;
609
+ } ) . then ( function ( ) {
610
+ t . pass ( 'pc1.setLocalDescription' ) ;
611
+ return pc2 . setRemoteDescription ( pc1 . localDescription ) ;
612
+ } ) . then ( function ( ) {
613
+ t . pass ( 'pc2.setRemoteDescription' ) ;
614
+ return pc2 . createAnswer ( ) ;
615
+ } ) . then ( function ( answer ) {
616
+ t . pass ( 'pc2.createAnswer' ) ;
617
+ return pc2 . setLocalDescription ( answer ) ;
618
+ } ) . then ( function ( ) {
619
+ t . pass ( 'pc2.setLocalDescription' ) ;
620
+ return pc1 . setRemoteDescription ( pc2 . localDescription ) ;
621
+ } ) . then ( function ( ) {
622
+ t . pass ( 'pc1.setRemoteDescription' ) ;
623
+ } ) . catch ( function ( err ) {
624
+ t . fail ( err . toString ( ) ) ;
625
+ } ) ;
626
+ } ) ;
627
+ } ) ;
628
+
629
+ test ( 'basic connection establishment with datachannel' , function ( t ) {
630
+ var pc1 = new RTCPeerConnection ( null ) ;
631
+ var pc2 = new RTCPeerConnection ( null ) ;
632
+ var ended = false ;
633
+ if ( typeof pc1 . createDataChannel !== 'function' ) {
634
+ t . pass ( 'datachannel is not supported.' ) ;
635
+ t . end ( ) ;
636
+ return ;
637
+ }
638
+
639
+ pc1 . oniceconnectionstatechange = function ( ) {
640
+ if ( pc1 . iceConnectionState === 'connected' ||
641
+ pc1 . iceConnectionState === 'completed' ) {
642
+ t . pass ( 'P2P connection established' ) ;
643
+ if ( ! ended ) {
644
+ ended = true ;
645
+ t . end ( ) ;
646
+ }
647
+ }
648
+ } ;
649
+
650
+ var addCandidate = function ( pc , event ) {
651
+ if ( event . candidate ) {
652
+ var cand = new RTCIceCandidate ( event . candidate ) ;
653
+ pc . addIceCandidate ( cand ) . catch ( function ( err ) {
654
+ t . fail ( 'addIceCandidate ' + err . toString ( ) ) ;
655
+ } ) ;
656
+ }
657
+ } ;
658
+ pc1 . onicecandidate = function ( event ) {
659
+ addCandidate ( pc2 , event ) ;
660
+ } ;
661
+ pc2 . onicecandidate = function ( event ) {
662
+ addCandidate ( pc1 , event ) ;
663
+ } ;
664
+
665
+ pc1 . createDataChannel ( 'somechannel' ) ;
597
666
pc1 . createOffer ( ) . then ( function ( offer ) {
598
667
t . pass ( 'pc1.createOffer' ) ;
599
668
return pc1 . setLocalDescription ( offer ) ;
@@ -734,10 +803,12 @@ test('getStats promise', function(t) {
734
803
t . ok ( typeof q === 'object' , 'getStats with a selector returns a Promise' ) ;
735
804
} ) ;
736
805
737
- test ( 'iceTransportPolicy is translated to iceTransports' , function ( t ) {
806
+ test ( 'iceTransportPolicy relay functionality' , function ( t ) {
807
+ // iceTransportPolicy is renamed to iceTransports in Chrome by
808
+ // adapter, this tests that when not setting any TURN server,
809
+ // no candidates are generated.
738
810
if ( m . webrtcDetectedBrowser === 'firefox' ) {
739
- // not implemented yet.
740
- t . pass ( 'iceTransportPolicy is not implemented by Firefox yet.' ) ;
811
+ t . pass ( 'iceTransportPolicy is not implemented in Firefox yet.' ) ;
741
812
t . end ( ) ;
742
813
return ;
743
814
}
@@ -747,11 +818,10 @@ test('iceTransportPolicy is translated to iceTransports', function(t) {
747
818
// Since we try to gather only relay candidates without specifying
748
819
// a TURN server, we should not get any candidates.
749
820
var candidates = [ ] ;
750
- pc1 . createDataChannel ( 'somechannel' ) ;
751
821
pc1 . onicecandidate = function ( event ) {
752
822
if ( ! event . candidate ) {
753
823
if ( candidates . length === 0 ) {
754
- t . pass ( 'iceTransportPolicy was translated to iceTransport ' ) ;
824
+ t . pass ( 'no candidates were gathered. ' ) ;
755
825
t . end ( ) ;
756
826
} else {
757
827
t . fail ( 'got unexpected candidates. ' + JSON . stringify ( candidates ) ) ;
@@ -761,10 +831,15 @@ test('iceTransportPolicy is translated to iceTransports', function(t) {
761
831
}
762
832
} ;
763
833
764
- pc1 . createOffer ( ) . then ( function ( offer ) {
765
- return pc1 . setLocalDescription ( offer ) ;
766
- } ) . catch ( function ( err ) {
767
- t . fail ( err . toString ( ) ) ;
834
+ var constraints = { video : true , fake : true } ;
835
+ navigator . mediaDevices . getUserMedia ( constraints )
836
+ . then ( function ( stream ) {
837
+ pc1 . addStream ( stream ) ;
838
+ pc1 . createOffer ( ) . then ( function ( offer ) {
839
+ return pc1 . setLocalDescription ( offer ) ;
840
+ } ) . catch ( function ( err ) {
841
+ t . fail ( err . toString ( ) ) ;
842
+ } ) ;
768
843
} ) ;
769
844
} ) ;
770
845
0 commit comments