@@ -30,6 +30,7 @@ describe('P2P JS SDK', function () {
3030 }
3131 }
3232 }
33+ deferred . reject ( ) ;
3334 } , timeout ) ;
3435 var interval = setInterval ( function ( ) {
3536 if ( latch . call ( latch ) ) {
@@ -58,6 +59,13 @@ describe('P2P JS SDK', function () {
5859 console . log ( type , msg ) ;
5960 }
6061
62+ function removeVideo ( ) {
63+ var videos = document . getElementsByClassName ( "video" ) ;
64+ for ( var i = 0 ; i < videos . length ; i ++ ) {
65+ document . body . removeChild ( videos [ i ] ) ;
66+ } ;
67+ }
68+
6169 var videoDetection = function ( streamId ) {
6270 window . setTimeout ( function ( ) {
6371 var framechecker = new VideoFrameChecker (
@@ -93,7 +101,7 @@ describe('P2P JS SDK', function () {
93101
94102 afterEach ( function ( ) {
95103 actorUser . close ( ) ;
96- actorUser . removeVideo ( actorUser . localStream ) ;
104+ removeVideo ( )
97105 detection = '' ;
98106 } ) ;
99107
@@ -342,7 +350,6 @@ describe('P2P JS SDK', function () {
342350 } )
343351 } ) ;
344352
345-
346353 it ( 'conncetWithSymolName' , function ( done ) {
347354 Q ( 'conncetWithSymolName' )
348355 . then ( function ( ) {
@@ -532,8 +539,6 @@ describe('P2P JS SDK', function () {
532539 actorUser1_datasender = e . origin ;
533540 actorUser1_data = e . message ;
534541 } ) ;
535- } )
536- . then ( function ( ) {
537542 actorUser2 = new TestClient ( userName2 , serverIP ) ;
538543 actorUser2 . bindListener ( "serverdisconnected" , function ( e ) {
539544 actorUser2 . request [ "server-disconnected_success" ] ++ ;
@@ -560,10 +565,9 @@ describe('P2P JS SDK', function () {
560565 afterEach ( function ( ) {
561566 Q ( 'afterEach' )
562567 . then ( function ( ) {
568+ removeVideo ( )
563569 actorUser1 . disconnect ( ) ;
564570 actorUser1 = undefined
565- } )
566- . then ( function ( ) {
567571 actorUser2 . disconnect ( ) ;
568572 actorUser2 = undefined
569573 } )
@@ -650,8 +654,6 @@ describe('P2P JS SDK', function () {
650654 } )
651655 . then ( function ( ) {
652656 actorUser1 . close ( ) ;
653- actorUser1 . removeVideo ( actorUser1 . localStream ) ;
654- actorUser2 . removeVideo ( User2RemoteStream )
655657 detection = '' ;
656658 } )
657659 . then ( function ( ) {
@@ -748,8 +750,6 @@ describe('P2P JS SDK', function () {
748750 } )
749751 . then ( function ( ) {
750752 actorUser1 . close ( ) ;
751- actorUser1 . removeVideo ( actorUser1 . localStream ) ;
752- actorUser2 . removeVideo ( User2RemoteStream )
753753 detection = '' ;
754754 } )
755755 . then ( function ( ) {
@@ -823,8 +823,6 @@ describe('P2P JS SDK', function () {
823823 } )
824824 . then ( function ( ) {
825825 actorUser1 . close ( ) ;
826- actorUser1 . removeVideo ( actorUser1 . localStream ) ;
827- actorUser2 . removeVideo ( User2RemoteStream )
828826 detection = '' ;
829827 } )
830828 . then ( function ( ) {
@@ -999,6 +997,10 @@ describe('P2P JS SDK', function () {
999997 return actorUser2 . request [ "streamended_success" ] === 1 ;
1000998 } , userName2 + "check wait: streamended_success" , waitInterval )
1001999 } )
1000+ . then ( function ( ) {
1001+ actorUser1 . close ( ) ;
1002+ detection = '' ;
1003+ } )
10021004 . then ( function ( ) {
10031005 console . log ( 'test end' ) ;
10041006 done ( ) ;
@@ -1100,11 +1102,229 @@ describe('P2P JS SDK', function () {
11001102 return actorUser2 . request [ "streamended_success" ] === 1 ;
11011103 } , userName2 + "check wait: streamended_success" , waitInterval )
11021104 } )
1105+ . then ( function ( ) {
1106+ actorUser1 . close ( ) ;
1107+ detection = '' ;
1108+ } )
11031109 . then ( function ( ) {
11041110 console . log ( 'test end' ) ;
11051111 done ( ) ;
11061112 } )
11071113 } ) ;
11081114 } ) ;
1109- } ) ;
11101115
1116+ describe ( 'publish Test' , function ( ) {
1117+ var actorUser1 = undefined ;
1118+ var actorUser2 = undefined ;
1119+ var User1RemoteId = "" ;
1120+ var User1RemoteStream = undefined ;
1121+ var User2RemoteId = "" ;
1122+ var User2RemoteStream = undefined ;
1123+ var actorUser1_datasender = undefined ;
1124+ var actorUser1_data = undefined ;
1125+ var actorUser2_datasender = undefined ;
1126+ var actorUser2_data = undefined ;
1127+
1128+ afterEach ( function ( ) {
1129+ Q ( 'afterEach' )
1130+ . then ( function ( ) {
1131+ actorUser2 . close ( ) ;
1132+ actorUser1 . close ( ) ;
1133+ removeVideo ( )
1134+ detection = '' ;
1135+ actorUser1 . disconnect ( ) ;
1136+ actorUser2 . disconnect ( ) ;
1137+ actorUser1 = undefined
1138+ actorUser2 = undefined
1139+ } )
1140+ } ) ;
1141+
1142+ var videoCodecList = [ "vp8" , "h264" ] ;
1143+ for ( i = 0 ; i < videoCodecList . length ; i ++ ) {
1144+ it ( 'publishEachOther' , function ( done ) {
1145+ Q ( 'publishEachOther' )
1146+ . then ( function ( ) {
1147+ // action
1148+ config = {
1149+ videoEncodings :[ {
1150+ codec :{
1151+ name :videoCodecList [ i ]
1152+ } ,
1153+ maxBitrate :1000
1154+ } ]
1155+ }
1156+ actorUser1 = new TestClient ( userName1 , serverIP , config ) ;
1157+ actorUser1 . bindListener ( "serverdisconnected" , function ( e ) {
1158+ actorUser1 . request [ "server-disconnected_success" ] ++ ;
1159+ } ) ;
1160+ actorUser1 . bindListener ( 'streamadded' , function ( e ) {
1161+ console . log ( "trigger streamadded " )
1162+ actorUser1 . request [ "streamadded_success" ] ++ ;
1163+ actorUser1 . showInPage ( e . stream ) ;
1164+ e . stream . addEventListener ( 'ended' , ( ) => {
1165+ console . log ( "stream is ended " )
1166+ actorUser1 . request [ "streamended_success" ] ++ ;
1167+ } )
1168+ User1RemoteId = e . stream . id ;
1169+ User1RemoteStream = e . stream ;
1170+ } ) ;
1171+ actorUser1 . bindListener ( "messagereceived" , function ( e ) {
1172+ actorUser1 . request [ "data-received_success" ] ++ ;
1173+ actorUser1_datasender = e . origin ;
1174+ actorUser1_data = e . message ;
1175+ } ) ;
1176+ actorUser2 = new TestClient ( userName2 , serverIP , config ) ;
1177+ actorUser2 . bindListener ( "serverdisconnected" , function ( e ) {
1178+ actorUser2 . request [ "server-disconnected_success" ] ++ ;
1179+ } ) ;
1180+ actorUser2 . bindListener ( 'streamadded' , function ( e ) {
1181+ console . log ( "trigger streamadded " )
1182+ actorUser2 . request [ "streamadded_success" ] ++ ;
1183+ actorUser2 . showInPage ( e . stream ) ;
1184+ e . stream . addEventListener ( 'ended' , ( ) => {
1185+ console . log ( "stream is ended " )
1186+ actorUser2 . request [ "streamended_success" ] ++ ;
1187+ } )
1188+ User2RemoteId = e . stream . id ;
1189+ User2RemoteStream = e . stream ;
1190+ } ) ;
1191+ actorUser2 . bindListener ( "messagereceived" , function ( e ) {
1192+ actorUser2 . request [ "data-received_success" ] ++ ;
1193+ actorUser2_datasender = e . origin ;
1194+ actorUser2_data = e . message ;
1195+ } ) ;
1196+ } )
1197+ // 1. User1Connect
1198+ . then ( function ( ) {
1199+ // action
1200+ actorUser1 . connect ( ) ;
1201+ } )
1202+ . then ( function ( ) {
1203+ // action
1204+ actorUser2 . connect ( ) ;
1205+ } )
1206+ . then ( function ( ) {
1207+ return waitsFor ( function ( ) {
1208+ //check action
1209+ return actorUser1 . request [ "connect_success" ] === 1 ;
1210+ } , userName1 + " check action: login " , waitInterval )
1211+ } )
1212+ . then ( function ( ) {
1213+ return waitsFor ( function ( ) {
1214+ //check action
1215+ return actorUser2 . request [ "connect_success" ] === 1 ;
1216+ } , userName2 + " check action: login " , waitInterval )
1217+ } )
1218+ . then ( function ( ) {
1219+ // action
1220+ actorUser1 . replaceAllowedRemoteIds ( userName2 ) ;
1221+ } )
1222+ . then ( function ( ) {
1223+ // action
1224+ actorUser2 . replaceAllowedRemoteIds ( userName1 ) ;
1225+ } )
1226+ . then ( function ( ) {
1227+ // action
1228+ actorUser1 . createLocalStream ( ) ;
1229+ } )
1230+ . then ( function ( ) {
1231+ return waitsFor ( function ( ) {
1232+ // check action
1233+ return actorUser1 . request [ "createLocal_success" ] === 1
1234+ } , userName1 + " check action: create localStream " , waitInterval )
1235+ } )
1236+ . then ( function ( ) {
1237+ // action
1238+ detection = "" ;
1239+ videoDetection ( "stream" + actorUser1 . request [ "localStreamId" ] ) ;
1240+ } )
1241+ . then ( function ( ) {
1242+ return waitsFor ( function ( ) {
1243+ //wait lock
1244+ return detection === true ;
1245+ } , userName1 + " create localstream is fail" , waitInterval )
1246+ } )
1247+ . then ( function ( ) {
1248+ //TODO change wrapper of publish
1249+ actorUser1 . publish ( userName2 ) ;
1250+ } )
1251+ . then ( function ( ) {
1252+ return waitsFor ( function ( ) {
1253+ //check action
1254+ return actorUser1 . request [ "publish_success" ] === 1 ;
1255+ } , userName1 + "check action: publish" , waitInterval )
1256+ } )
1257+ . then ( function ( ) {
1258+ return waitsFor ( function ( ) {
1259+ //check wait
1260+ return actorUser2 . request [ "streamadded_success" ] === 1 ;
1261+ } , userName2 + "check wait: stream-added" , waitInterval )
1262+ } )
1263+ . then ( function ( ) {
1264+ // action
1265+ detection = "" ;
1266+ videoDetection ( "stream" + User2RemoteId ) ;
1267+ } )
1268+ . then ( function ( ) {
1269+ return waitsFor ( function ( ) {
1270+ //wait lock
1271+ return detection === true ;
1272+ } , userName2 + " remote stream is good" , waitInterval )
1273+ } )
1274+
1275+ . then ( function ( ) {
1276+ // action
1277+ actorUser2 . createLocalStream ( ) ;
1278+ } )
1279+ . then ( function ( ) {
1280+ return waitsFor ( function ( ) {
1281+ // check action
1282+ return actorUser2 . request [ "createLocal_success" ] === 1
1283+ } , userName2 + " check action: create localStream " , waitInterval )
1284+ } )
1285+ . then ( function ( ) {
1286+ // action
1287+ detection = "" ;
1288+ videoDetection ( "stream" + actorUser2 . request [ "localStreamId" ] ) ;
1289+ } )
1290+ . then ( function ( ) {
1291+ return waitsFor ( function ( ) {
1292+ //wait lock
1293+ return detection === true ;
1294+ } , userName2 + " create localstream is fail" , waitInterval )
1295+ } )
1296+ . then ( function ( ) {
1297+ //TODO change wrapper of publish
1298+ actorUser2 . publish ( userName1 ) ;
1299+ } )
1300+ . then ( function ( ) {
1301+ return waitsFor ( function ( ) {
1302+ //check action
1303+ return actorUser2 . request [ "publish_success" ] === 1 ;
1304+ } , userName2 + "check action: publish" , waitInterval )
1305+ } )
1306+ . then ( function ( ) {
1307+ return waitsFor ( function ( ) {
1308+ //check wait
1309+ return actorUser1 . request [ "streamadded_success" ] === 1 ;
1310+ } , userName1 + "check wait: stream-added" , waitInterval )
1311+ } )
1312+ . then ( function ( ) {
1313+ // action
1314+ detection = "" ;
1315+ videoDetection ( "stream" + User2RemoteId ) ;
1316+ } )
1317+ . then ( function ( ) {
1318+ return waitsFor ( function ( ) {
1319+ //wait lock
1320+ return detection === true ;
1321+ } , userName1 + " remote stream is good" , waitInterval )
1322+ } )
1323+ . then ( function ( ) {
1324+ console . log ( 'test end' ) ;
1325+ done ( ) ;
1326+ } )
1327+ } ) ;
1328+ }
1329+ } ) ;
1330+ } ) ;
0 commit comments