Skip to content

Commit bf0ad9d

Browse files
author
nullagent
committed
match maker works on venue and client can connect to websocket now
1 parent a28c6f0 commit bf0ad9d

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const WebsocketComms = require('../../comms/websocket-comms')
99
const PeerInvite = require('./peer-invite')
1010

1111
class MatchMakerClient extends EventEmitter {
12-
constructor(identity, contacts, urlOrParty = 'https://postquantum.one/api/', wsUrlOrParty = 'https://postquantum.one/api/ws'){
12+
constructor(identity, contacts, urlOrParty = 'https://postquantum.one/api/', wsUrlOrParty = 'https://postquantum.one/ws'){
1313

1414
super()
1515

@@ -97,7 +97,7 @@ class MatchMakerClient extends EventEmitter {
9797
debug('waiting for websocket authorization')
9898
await this.wsParty.comms.authorized()
9999

100-
this.invitesRx = this.wsParty.ROSLIB.Topic({
100+
this.invitesRx = new this.wsParty.ROSLIB.Topic({
101101
ros : this.wsParty.comms.ros,
102102
name : '/invites/' + encodeURIComponent(this.restParty.identity.key.hash) + '/rx',
103103
messageType: 'Object'
@@ -106,7 +106,7 @@ class MatchMakerClient extends EventEmitter {
106106
this.invitesRx.subscribe( this.handleInviteRxMsg.bind(this) )
107107

108108

109-
this.invitesTx = this.wsParty.ROSLIB.Topic({
109+
this.invitesTx = new this.wsParty.ROSLIB.Topic({
110110
ros : this.wsParty.comms.ros,
111111
name : '/invites/' + encodeURIComponent(this.restParty.identity.key.hash) + '/tx',
112112
messageType: 'Object'

src/service/runner-router.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ class RunnerRouter {
5656
debug('getRunnerByDomain -', domain)
5757
const runner = this.runnersByDomain.get(domain)
5858
if(!runner){
59+
debug('\t', 'failed to locate domain runner, using default')
5960
return this.defaultRunner
6061
}
62+
63+
return runner
6164
}
6265

6366
/**
@@ -84,11 +87,13 @@ class RunnerRouter {
8487
debug('addRunner - ', partyId, domain)
8588

8689
if(!this.runnersByHost.has(partyId)){
90+
debug('adding to runnersByHost')
8791
this.runnersByHost.set(partyId, runner)
8892
}
8993

9094

9195
if(domain && !this.runnersByDomain.has(domain)){
96+
debug('adding to runnersByDomain map')
9297
this.runnersByDomain.set(domain, runner)
9398
}
9499
}

src/service/service-host-websocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ServiceHostWebsocket{
102102
debug('creating peer party')
103103

104104

105-
let hostRunner = this.runner.party ? this.runner : this.runner.getRunnerByDomain(req.hostname)
105+
let hostRunner = this.runner.party ? this.runner : this.runner.getRunnerByDomain(req.headers.host)
106106
let hostParty = hostRunner.party
107107

108108
let peer = new PeerParty({

src/venue/venue-host.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,46 @@ const VenueServiceSchema = require('./dataparty/@dataparty-venue.dataparty-schem
99
const VenueSrv = require('./dataparty/@dataparty-venue.dataparty-service.json')
1010

1111

12+
async function loadService(runnerRouter, settings, serviceFilePath){
13+
14+
debug('addService', settings, serviceFilePath)
15+
16+
const { enabled, workspace, domain, prefix, sendFullErrors, useNative, defaultConfig } = settings
17+
18+
if(!enabled){ return }
19+
20+
const serviceFile = JSON.parse( fs.readFileSync( serviceFilePath ) )
21+
22+
let party = new Dataparty.TingoParty({
23+
path: workspace+'/db',
24+
model: serviceFile.schemas,
25+
config: new Dataparty.Config.JsonFileConfig({basePath: workspace+'/config', ...defaultConfig}),
26+
noCache: false
27+
})
28+
29+
party.topics = new Dataparty.LocalTopicHost()
30+
31+
const service = new Dataparty.IService(serviceFile.package, serviceFile)
32+
33+
debug('loaded service')
34+
35+
debug('party db location', workspace)
36+
37+
let runner = new Dataparty.ServiceRunnerNode({
38+
party, service,
39+
sendFullErrors,
40+
useNative,
41+
prefix
42+
})
43+
44+
await party.start()
45+
await runner.start()
46+
47+
await runnerRouter.addRunner({domain, runner})
48+
49+
}
50+
51+
1252
async function main(){
1353

1454
const path = '/data/dataparty/venue-service'
@@ -86,9 +126,20 @@ async function main(){
86126

87127
debug('started')
88128
console.log('partying')
129+
130+
await loadService(runnerRouter, {
131+
enabled: true,
132+
domain: 'postquantum.one',
133+
prefix: 'api',
134+
workspace: '/data/dataparty/match-maker-service',
135+
sendFullErrors: true,
136+
useNative: false
137+
138+
}, '/home/ubuntu/match-maker/dataparty/@datapartyjs-match-maker.dataparty-service.json')
89139
}
90140

91141

142+
92143
main().catch(err=>{
93144
console.error(err)
94145
})

0 commit comments

Comments
 (0)