Skip to content

Commit 627d5f5

Browse files
author
nullagent
committed
match maker gui test
1 parent bf0ad9d commit 627d5f5

5 files changed

Lines changed: 100 additions & 22 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class MatchMakerClient extends EventEmitter {
186186

187187
const lookupData = { hash }
188188

189-
const lookupResult = await restParty.comms.call('key/lookup', lookupData, {
189+
const lookupResult = await this.restParty.comms.call('key/lookup', lookupData, {
190190
expectClearTextReply: false,
191191
sendClearTextRequest: false,
192192
useSessions: false
@@ -211,8 +211,8 @@ class MatchMakerClient extends EventEmitter {
211211

212212
let toIdentity = null
213213
if(typeof toHashOrIdentity == 'string'){
214-
const toIdentity = await lookupPublicKey(userCallHashInput.value)
215-
thisotherIdentity = toIdentity
214+
toIdentity = await this.lookupPublicKey(toHashOrIdentity)
215+
//this.otherIdentity = toIdentity
216216
} else {
217217
toIdentity = toHashOrIdentity
218218
}
@@ -239,7 +239,7 @@ class MatchMakerClient extends EventEmitter {
239239

240240
const invitePostData = {
241241
to: toIdentity.key.hash,
242-
from: party.identity.key.hash,
242+
from: this.wsParty.identity.key.hash,
243243
payload: JSON.stringify(secureInvite.toJSON())
244244
}
245245

src/party/peer/peer-invite.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PeerInvite extends EventEmitter {
2828
this.fromIdentity = fromIdentity
2929
this.matchMaker = matchMakerClient
3030
this.inviteDoc = inviteDoc
31-
this.latestDoc = null
31+
this.inviteMsg = null //this.latestDoc = null
3232
this.payload = null
3333

3434
this.topicSub = null
@@ -101,6 +101,10 @@ class PeerInvite extends EventEmitter {
101101
this.emit('done', this)
102102
}
103103

104+
get state(){
105+
return (this.inviteMsg || this.inviteDoc).state
106+
}
107+
104108
async onInviteMsg(inviteMsg){
105109

106110
debug('onInviteMsg', inviteMsg)
@@ -111,6 +115,8 @@ class PeerInvite extends EventEmitter {
111115
debug('\t', 'invite.state = ', inviteMsg.state)
112116
this.emit(inviteMsg.state, this)
113117

118+
this.emit('state-change', this)
119+
114120
if(this.inviteMsg && END_STATES.indexOf(this.inviteMsg.state) ){
115121
this.emit('done', this)
116122
}

src/service/service-host-websocket.js

Lines changed: 1 addition & 2 deletions
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 = 5*60*1000
7+
const WATCHDOG_INTERVAL = 60*1000
88

99
const Comms = require('../comms')
1010
const PeerParty = require('../party/peer/peer-party')
@@ -29,7 +29,6 @@ class ServiceHostWebsocket{
2929

3030
if(!server){
3131
settings = { port: this.port, ...this.wsSettings }
32-
3332
} else {
3433
settings = { noServer: true, ...this.wsSettings }
3534
}

src/service/service-runner-node.js

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class ServiceRunnerNode {
284284

285285
this.topics[name] = topic
286286

287-
const routablePath = Path.join(this.prefix, Path.normalize(name))
287+
const routablePath = Path.normalize(name)
288288

289289
let route = this.topicsRouter.add(name, routablePath/*, this.topicHandler(topic)*/)
290290

@@ -447,30 +447,53 @@ class ServiceRunnerNode {
447447
}
448448

449449
async getTopic(path){
450-
debug('looking up route', path)
450+
debug('looking up topic', path)
451451

452452
let p = new Promise(async (resolve,reject)=>{
453453

454-
let route = await this.topicsRouter.route(path, (event)=>{
454+
//debug('\tcalling route', path)
455+
//debug('\t', Object.keys(this.topics))
455456

456-
//debug(event)
457-
//debug('topic route callback')
457+
try{
458458

459+
//debug('tryin', this.topicsRouter.route)
460+
let routed = false
461+
462+
let route = await this.topicsRouter.route(path, (event)=>{
463+
464+
//debug(event)
465+
//debug('topic route callback - ', path)
466+
467+
468+
if(!event.route){
469+
debug('no such topic', path)
470+
//reject('no such topic')
471+
routed = true
472+
resolve(null)
473+
} else {
474+
debug('found route', event.route.name)
475+
}
459476

460-
if(!event.route){
461-
debug('no such topic', path)
462-
//reject('no such topic')
463-
resolve(null)
464-
} else {
465-
debug('found route', event.route.name)
466-
}
477+
routed = true
478+
479+
return resolve({ route: event.route, topic: event.route.data, arguments: event.arguments })
480+
481+
})
467482

468-
return resolve({ route: event.route, topic: event.route.data, arguments: event.arguments })
483+
debug('\trouting done', routed)
469484

470-
})
485+
if(!routed){
486+
return reject(null)
487+
}
488+
489+
} catch(err){
471490

472-
})
491+
debug(err)
473492

493+
return reject(err)
494+
}
495+
})
496+
474497
return await p
475498
}
476499

src/venue/public/p2p-test.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,58 @@ <h2>Remote</h2>
4242

4343
let matchMaker = null
4444

45+
let userHashInput = document.getElementById('user-hash')
46+
let userCallHashInput = document.getElementById('user-call-hash')
47+
let inviteIdInput = document.getElementById('invite-id')
48+
49+
let pendingInvite = null
50+
51+
async function callUser(){
52+
if(pendingInvite){ return }
53+
54+
pendingInvite = await matchMaker.createInvite( userCallHashInput.value, {
55+
type: 'webrtc',
56+
service: '@dataparty/video-chat',
57+
role: 'client'
58+
}, {
59+
roomId: '',
60+
action: 'call'
61+
})
62+
63+
pendingInvite.on('state-change', (invite)=>{
64+
console.log('state-change', invite.state, invite)
65+
})
66+
}
67+
68+
async function cancelCall() {
69+
if(!pendingInvite){ return }
70+
71+
await pendingInvite.cancel()
72+
}
73+
74+
async function rejectCall(){
75+
if(!pendingInvite){ return }
76+
77+
await pendingInvite.reject()
78+
}
79+
4580
async function init(){
4681
matchMaker = new Dataparty.MatchMakerClient(null, null)
82+
83+
await matchMaker.start()
84+
85+
let myHash = matchMaker.restParty.identity.key.hash
86+
87+
userHashInput.value = myHash
88+
89+
matchMaker.on('invited', invite=>{
90+
console.log('invited', invite)
91+
92+
pendingInvite = invite
93+
94+
95+
inviteIdInput.value = invite.id
96+
})
4797
}
4898

4999
init().catch((err)=>{

0 commit comments

Comments
 (0)