Skip to content

Commit 802e912

Browse files
author
nullagent
committed
testing
1 parent 0284e4c commit 802e912

8 files changed

Lines changed: 79 additions & 56 deletions

File tree

src/comms/peer-comms.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
const {Routines, Identity} = require('@dataparty/crypto')
23
const debug = require('debug')('dataparty.comms.peercomms')
34
const uuidv4 = require('uuid/v4')
@@ -10,7 +11,7 @@ const Joi = require('joi')
1011
const HostOp = require('./host/host-op')
1112
const HostProtocolScheme = require('./host/host-protocol-scheme')
1213

13-
const AUTH_TIMEOUT_MS = 3000
14+
const AUTH_TIMEOUT_MS = 25000
1415

1516
const HOST_SESSION_STATES = {
1617
AUTH_REQUIRED: 'AUTH_REQUIRED',
@@ -491,4 +492,4 @@ class PeerComms extends ISocketComms {
491492
}
492493

493494

494-
module.exports = PeerComms
495+
module.exports = PeerComms

src/comms/rtc-socket-comms.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class RTCSocketComms extends PeerComms {
1414
constructor({remoteIdentity, host, party, rtcOptions, trickle = false, ...options}){
1515
super({remoteIdentity, host, party, ...options})
1616

17+
debug('starting host=',host, ' uuid=', this.uuid)
18+
1719
this.rtcSettings = {
1820
trickle,
1921
initiator: host,

src/comms/websocket-comms.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class WebsocketComms extends PeerComms {
2020
this.uri = uri
2121
this.connection = connection
2222

23+
debug('starting host=',host, ' uuid=', this.uuid, ' uri=', this.uri)
24+
2325
if(this.host && !this.connection){
2426
throw new Error('existing connection expected')
2527
}

src/party/loki-cache.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ module.exports = class LokiCache extends EventEmitter {
133133

134134
// check if msg is already in cache
135135
if (cachedMsg) {
136-
collection.remove(cachedMsg)
137-
//collection.findAndRemove({
138-
// '$meta.id': id,
139-
//})
136+
try{
137+
collection.remove(cachedMsg)
138+
//collection.findAndRemove({
139+
// '$meta.id': id,
140+
//})
141+
}
142+
catch(err){
143+
debug('WARN', err)
144+
}
140145
}
141146

142147
// clone msg on insert - cache should follow backend

src/party/peer/match-maker-client.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const EventEmitter = require('eventemitter3')
22

3+
const debug = require('debug')('dataparty.match-maker-client')
4+
5+
36
const dataparty_crypto = require('@dataparty/crypto')
47
const LokiParty = require('../local/loki-party')
58
const PeerParty = require('./peer-party')
@@ -136,7 +139,9 @@ class MatchMakerClient extends EventEmitter {
136139
} else if(this.pendingInvites.rx[inviteId]) {
137140

138141
let invite = this.pendingInvites.rx[inviteId]
139-
invite.onInviteMsg(msg.invite)
142+
143+
debug('calling onInviteMsg')
144+
await invite.onInviteMsg(msg.invite)
140145
}
141146
}
142147

@@ -146,12 +151,12 @@ class MatchMakerClient extends EventEmitter {
146151
const inviteId = msg.invite.$meta.id
147152
let pending = this.pendingInvites.tx[inviteId]
148153

149-
if( pending &&
150-
//msg.invite.state == 'accepted' &&
151-
pending.inviteDoc.id == msg.invite.$meta.id
154+
if( pending
152155
){
153156

154-
pending.onInviteMsg(msg.invite)
157+
debug('calling onInviteMsg')
158+
159+
await pending.onInviteMsg(msg.invite)
155160

156161
}
157162
}

src/party/peer/peer-invite.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/service/service-host-websocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const debug = require('debug')('dataparty.service.host-websocket')
44
const ws = require('ws')
55
const WebSocketServer = ws.WebSocketServer
66

7-
const WATCHDOG_INTERVAL = 60*1000
7+
const WATCHDOG_INTERVAL = 30*1000
88

99
const Comms = require('../comms')
1010
const PeerParty = require('../party/peer/peer-party')

src/venue/public/p2p-test.html

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h2>Remote</h2>
113113

114114
video.play()
115115

116-
await establish({
116+
await pendingInvite.establish({
117117
mediaSrc: localMediaSrc,
118118
hostParty: hostLocal
119119
})
@@ -127,7 +127,18 @@ <h2>Remote</h2>
127127
audio: true
128128
})
129129

130-
await pendingInvite.accept(localMediaSrc)
130+
console.log('showing local video')
131+
var video = document.getElementById('local-video')
132+
133+
if ('srcObject' in video) {
134+
video.srcObject = localMediaSrc
135+
} else {
136+
video.src = window.URL.createObjectURL(localMediaSrc) // for older browsers
137+
}
138+
139+
video.play()
140+
141+
await pendingInvite.accept(localMediaSrc, config)
131142

132143
pendingInvite.on('stream', invite => {
133144
// got remote video stream, now let's show it in a video tag
@@ -144,20 +155,6 @@ <h2>Remote</h2>
144155
})
145156
}
146157

147-
async function finalizeCall(){
148-
149-
localMediaSrc = await navigator.mediaDevices.getUserMedia({
150-
video: true,
151-
audio: true
152-
})
153-
154-
155-
await pendingInvite.establish({
156-
mediaSrc: localMediaSrc,
157-
config
158-
//hostParty: hostLocal
159-
})
160-
}
161158

162159
async function cancelCall() {
163160
if(!pendingInvite){ return }

0 commit comments

Comments
 (0)