11var Client = require ( '../' )
22var common = require ( './common' )
33var test = require ( 'tape' )
4+ var wrtc
45
56var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
67var peerId = new Buffer ( '01234567890123456789' )
@@ -25,7 +26,7 @@ function serverTest (t, serverType, serverFamily) {
2526 infoHash : infoHash ,
2627 length : torrentLength ,
2728 announce : [ announceUrl ]
28- } )
29+ } , { wrtc : wrtc } )
2930
3031 client1 . start ( )
3132
@@ -45,14 +46,19 @@ function serverTest (t, serverType, serverFamily) {
4546 t . equal ( swarm . complete , 0 )
4647 t . equal ( swarm . incomplete , 1 )
4748 t . equal ( Object . keys ( swarm . peers ) . length , 1 )
48- t . deepEqual ( swarm . peers [ hostname + ':6881' ] , {
49- type : serverType ,
50- ip : clientIp ,
51- port : 6881 ,
52- peerId : peerId . toString ( 'hex' ) ,
53- complete : false ,
54- socket : undefined
55- } )
49+
50+ if ( serverType !== 'ws' ) {
51+ t . deepEqual ( swarm . peers [ hostname + ':6881' ] , {
52+ type : serverType ,
53+ ip : clientIp ,
54+ port : 6881 ,
55+ peerId : peerId . toString ( 'hex' ) ,
56+ complete : false ,
57+ socket : undefined
58+ } )
59+ } else {
60+ t . equal ( swarm . peers [ peerId . toString ( 'hex' ) ] . complete , false )
61+ }
5662
5763 client1 . complete ( )
5864
@@ -73,7 +79,7 @@ function serverTest (t, serverType, serverFamily) {
7379 infoHash : infoHash ,
7480 length : torrentLength ,
7581 announce : [ announceUrl ]
76- } )
82+ } , { wrtc : wrtc } )
7783
7884 client2 . start ( )
7985
@@ -82,7 +88,7 @@ function serverTest (t, serverType, serverFamily) {
8288 } )
8389
8490 client2 . once ( 'peer' , function ( addr ) {
85- t . ok ( addr === hostname + ':6881' || addr === hostname + ':6882' )
91+ t . ok ( addr === hostname + ':6881' || addr === hostname + ':6882' || addr . id === peerId . toString ( 'hex' ) )
8692
8793 client2 . stop ( )
8894 client2 . once ( 'update' , function ( data ) {
@@ -109,6 +115,21 @@ function serverTest (t, serverType, serverFamily) {
109115 } )
110116}
111117
118+ test ( 'create daemon' , function ( t ) {
119+ wrtc = require ( 'electron-webrtc' ) ( )
120+ wrtc . electronDaemon . once ( 'ready' , t . end )
121+ } )
122+
123+ test ( 'websocket server' , function ( t ) {
124+ serverTest ( t , 'ws' , 'inet' )
125+ } )
126+
127+ // cleanup
128+ test ( 'cleanup electron-eval daemon' , function ( t ) {
129+ wrtc . close ( )
130+ t . end ( )
131+ } )
132+
112133test ( 'http ipv4 server' , function ( t ) {
113134 serverTest ( t , 'http' , 'inet' )
114135} )
0 commit comments