Skip to content

Commit a28c6f0

Browse files
author
nullagent
committed
web app tester loading
1 parent 7cfe384 commit a28c6f0

4 files changed

Lines changed: 79 additions & 7 deletions

File tree

src/party/iparty.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class IParty {
3434

3535
this._actor = {id: undefined, type: undefined}
3636
this._actors = []
37-
this._identity = undefined
37+
this._identity = null
3838
this.started = false
3939

4040
/**
@@ -167,7 +167,9 @@ class IParty {
167167
* @type {module:dataparty/Types.Identity}
168168
*/
169169
get identity(){
170-
if (!this.hasIdentity()){ return undefined }
170+
if (!this.hasIdentity()){ return null }
171+
172+
171173
return dataparty_crypto.Identity.fromBSON(this._identity.toBSON())
172174
}
173175

@@ -234,7 +236,7 @@ class IParty {
234236
* @method module:Party.IParty.hasIdentity
235237
*/
236238
hasIdentity(){
237-
return this._identity != undefined
239+
return !this._identity ? false : true
238240
}
239241

240242
/**
@@ -251,11 +253,14 @@ class IParty {
251253
* @method module:Party.IParty.loadIdentity
252254
*/
253255
async loadIdentity(){
256+
debug('loadIdentity')
254257
const path = 'identity'
255258
const cfgIdenStr = await this.config.read(path)
256259

260+
debug('cfgStr', cfgIdenStr)
261+
257262
if (!cfgIdenStr){
258-
debug('generated new identity')
263+
debug('generating new identity')
259264

260265
await this.resetIdentity()
261266
} else {
@@ -264,6 +269,7 @@ class IParty {
264269
this._identity = dataparty_crypto.Identity.fromBSON(identityBson)
265270
debug('loaded identity (bson)')
266271
} catch (err){
272+
console.log(err)
267273
this._identity = dataparty_crypto.Identity.fromString( JSON.stringify(cfgIdenStr) )
268274
debug('loaded identity (json)')
269275
}
@@ -275,11 +281,13 @@ class IParty {
275281
* @method module:Party.IParty.resetIdentity
276282
*/
277283
async resetIdentity(){
284+
debug('resetIdentity')
278285
const path = 'identity'
279286
await this.config.write(path, null)
280287

281-
this._identity = new dataparty_crypto.Identity({id: 'primary'})
282-
await this._identity.initialize()
288+
this._identity = await dataparty_crypto.Identity.fromRandomSeed({id: 'primary'})
289+
290+
//await this._identity.initialize()
283291

284292
const identityBson = this._identity.toBSON(true)
285293
const identityBase64 = dataparty_crypto.Routines.Utils.base64.encode(identityBson)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class MatchMakerClient extends EventEmitter {
6767
debug('starting restParty')
6868
await this.restParty.start()
6969

70+
if(!this.restParty.comms){
71+
this.restParty.comms = new Dataparty.Comms.RestComms({
72+
party:this.restParty,
73+
config: this.restParty.config
74+
})
75+
}
76+
7077
await this.announcePublicKeys()
7178
}
7279

src/party/peer/peer-invite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function delay(ms){
1919
})
2020
}
2121

22-
class PeerInvite extends EvetEmitter {
22+
class PeerInvite extends EventEmitter {
2323
constructor(inviteDoc, toIdentity, matchMakerClient, fromIdentity){
2424
super()
2525

src/venue/public/p2p-test.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<html>
2+
<head>
3+
<script src="dist/dataparty-browser.js"></script>
4+
<script src="node_modules/argon2-browser/dist/argon2-bundled.min.js"></script>
5+
6+
<title>p2p tester</title>
7+
</head>
8+
9+
<body>
10+
11+
<div>
12+
<input type="text" id="user-hash" placeholder="your user hash" readonly>
13+
<input type="text" id="user-call-hash" placeholder="user to call">
14+
<select id="invite-role">
15+
<option value="host">Host</option>
16+
<option vlaue="client">Client</option>
17+
</select>
18+
<button onclick="callUser()">Start Call</button>
19+
<button onclick="cancelCall()">Cancel Call</button>
20+
</div>
21+
22+
<br>
23+
24+
<div>
25+
<input type="text" id="invite-id" placeholder="invite id" readonly>
26+
<button onclick="answerCall()">Answer Call</button>
27+
<button onclick="rejectCall()">Reject Call</button>
28+
</div>
29+
30+
<div>
31+
<h2>Local</h2>
32+
<video id="local-video"></video>
33+
</div>
34+
35+
<div>
36+
<h2>Remote</h2>
37+
<video id="remote-video"></video>
38+
</div>
39+
40+
41+
<script>
42+
43+
let matchMaker = null
44+
45+
async function init(){
46+
matchMaker = new Dataparty.MatchMakerClient(null, null)
47+
}
48+
49+
init().catch((err)=>{
50+
console.error('crashed', err)
51+
})
52+
53+
</script>
54+
55+
56+
</body>
57+
</html>

0 commit comments

Comments
 (0)