@@ -75,7 +75,7 @@ class PeerInvite extends EventEmitter {
7575 this . emit ( 'done' , this )
7676 }
7777
78- async accept ( mediaSrc ) {
78+ async accept ( mediaSrc , config ) {
7979 debug ( 'accepting invite' )
8080
8181 /*if(this.inviteDoc.toHash == matchMaker.wsParty.identity.key.hash){
@@ -97,7 +97,7 @@ class PeerInvite extends EventEmitter {
9797
9898 this . payload = payload . msg
9999
100- return await this . establish ( mediaSrc )
100+ return await this . establish ( { mediaSrc, config } )
101101 }
102102
103103 async reject ( ) {
@@ -158,43 +158,51 @@ class PeerInvite extends EventEmitter {
158158 this . topicSub = new party . ROSLIB . Topic ( {
159159 ros : party . comms . ros ,
160160 name : '/invite/' + this . id + '/session/' + ( actorField == 'to' ?'from' :'to' ) ,
161- messageType : 'SecureObject '
161+ messageType : 'Object '
162162 } )
163163
164164 this . topicPub = new party . ROSLIB . Topic ( {
165165 ros : party . comms . ros ,
166166 name : '/invite/' + this . id + '/session/' + actorField ,
167- messageType : 'SecureObject '
167+ messageType : 'Object '
168168 } )
169169
170170 this . topicSub . subscribe ( async ( msg ) => {
171171 debug ( this . topicSub . name , ' got message' , msg )
172172
173- let msgWorkAround = new dataparty_crypto . Message ( { } )
174- msgWorkAround . fromJSON ( msg . offer )
173+ for ( let i = 0 ; i < msg . offers . length ; i ++ ) {
175174
176- let offer = await party . privateIdentity . decrypt ( msgWorkAround )
177-
178- if ( offer . from . hash != otherIdentity . key . hash ) {
179- debug ( 'BAD IDENTITY' )
180- return
181- }
182-
183- //console.log(offer.msg)
184- if ( ! connected && this . peerParty ) {
185- this . peerParty . comms . socket . signal ( offer . msg )
175+ let msgWorkAround = new dataparty_crypto . Message ( { } )
176+ msgWorkAround . fromJSON ( msg . offers [ i ] )
177+
178+ let offer = await party . privateIdentity . decrypt ( msgWorkAround )
179+
180+ if ( offer . from . hash != otherIdentity . key . hash ) {
181+ debug ( 'BAD IDENTITY' )
182+ continue
183+ }
184+
185+ debug ( 'got webrtc offer' , offer . msg )
186+ if ( ! this . connected && this . peerParty ) {
187+ this . peerParty . comms . socket . signal ( offer . msg )
188+ }
186189 }
187190 } )
188191
189192 debug ( 'subscribed to - ' , this . topicSub . name )
190193
194+ if ( this . isSender ( ) ) {
195+ //await delay(500)
196+ }
197+
191198 this . peerParty = new PeerParty ( {
192199 comms : new RTCSocketComms ( {
193200 host : this . isSender ( ) ,
194201 session : this . payload . session ,
195202 rtcOptions : {
196203 initiator : this . isSender ( ) ,
197- stream : mediaSrc , //false,
204+ stream : mediaSrc ,
205+ //stream: this.isSender() ? mediaSrc : undefined, //false,
198206 trickle : true ,
199207 allowHalfTrickle : true ,
200208 config : {
@@ -233,6 +241,8 @@ class PeerInvite extends EventEmitter {
233241 } )
234242
235243
244+ let sendFreely = false
245+
236246 this . peerParty . comms . socket . on ( 'signal' , async ( data ) => {
237247
238248 if ( this . peerParty . comms . authed ) { return }
@@ -242,31 +252,32 @@ class PeerInvite extends EventEmitter {
242252
243253 const secureOffer = await party . privateIdentity . encrypt ( data , otherIdentity )
244254
245- if ( host ) {
255+ if ( host && ! sendFreely ) {
246256 //console.log('am host')
247- this . offers . push ( { offer : secureOffer . toJSON ( ) } )
257+ this . offers . push ( secureOffer . toJSON ( ) )
248258 } else {
249259 //console.log('am client')
250- this . topicPub . publish ( { offer : secureOffer . toJSON ( ) } )
260+ this . topicPub . publish ( { offers : [ secureOffer . toJSON ( ) ] } )
251261 }
252262 } )
253263
254264
255265 if ( host ) {
256266 console . log ( 'delay' )
257- await delay ( 2500 )
267+ await delay ( 250 )
268+ sendFreely = true
258269
259- console . log ( 'have offers' , offers )
270+ console . log ( 'sending offers' , this . offers )
260271
261- for ( let i = 0 ; i < offers . length ; i ++ ) {
272+ // for(let i=0; i < this. offers.length; i++){
262273
263- if ( this . peerParty . comms . authed || this . connected ) { break }
274+ // if(this.peerParty.comms.authed || this.connected){ break }
264275
265- this . topicPub . publish ( offers [ i ] )
276+ this . topicPub . publish ( { offers : this . offers } )
266277
267- await delay ( 1000 )
278+ // await delay(1000)
268279
269- }
280+ // }
270281 } else {
271282
272283 }
@@ -288,4 +299,4 @@ class PeerInvite extends EventEmitter {
288299
289300}
290301
291- module . exports = PeerInvite
302+ module . exports = PeerInvite
0 commit comments