Skip to content

Commit 0284e4c

Browse files
author
nullagent
committed
seems to work happily now
1 parent 627d5f5 commit 0284e4c

5 files changed

Lines changed: 119 additions & 10 deletions

File tree

src/comms/peer-comms.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class PeerComms extends ISocketComms {
7171

7272
setState(state) {
7373
this.state = state
74+
debug('state -', state)
7475
this.emit('state', this.state)
7576
}
7677

src/party/iparty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class IParty {
178178

179179
const identityBson = this._identity.toBSON(true)
180180
const identityBase64 = dataparty_crypto.Routines.Utils.base64.encode(identityBson)
181-
await this.config.write(path, identityBase64)
181+
await this.config.write('identity', identityBase64)
182182
}
183183

184184
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class MatchMakerClient extends EventEmitter {
148148

149149
if( pending &&
150150
//msg.invite.state == 'accepted' &&
151-
pending.$meta.id == msg.invite.$meta.id
151+
pending.inviteDoc.id == msg.invite.$meta.id
152152
){
153153

154154
pending.onInviteMsg(msg.invite)

src/party/peer/peer-invite.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const debug = require('debug')('dataparty.peer-invite')
44
const EventEmitter = require('eventemitter3')
55

6+
const dataparty_crypto = require('@dataparty/crypto')
7+
68
const PeerParty = require('./peer-party')
79
const RTCSocketComms = require('../../comms/rtc-socket-comms')
810

@@ -39,6 +41,8 @@ class PeerInvite extends EventEmitter {
3941
// host only
4042
this.offers = []
4143

44+
this.incomingStream = null
45+
4246
/*if(!this.isSender()){
4347
this.inviteDoc.
4448
}*/
@@ -74,13 +78,13 @@ class PeerInvite extends EventEmitter {
7478
async accept(mediaSrc){
7579
debug('accepting invite')
7680

77-
if(this.inviteDoc.toHash == party.identity.key.hash){
78-
otherIdentity = await this.matchMaker.lookupPublicKey(pendingCallInvite.fromHash)
81+
/*if(this.inviteDoc.toHash == matchMaker.wsParty.identity.key.hash){
82+
otherIdentity = await this.matchMaker.lookupPublicKey(this.inviteDoc.fromHash)
7983
} else {
80-
otherIdentity = await this.matchMaker.lookupPublicKey(pendingCallInvite.toHash)
81-
}
84+
otherIdentity = await this.matchMaker.lookupPublicKey(this.inviteDoc.toHash)
85+
}*/
8286

83-
let changedInvite = await setInviteState(this, 'accepted')
87+
let changedInvite = await this.matchMaker.setInviteState(this, 'accepted')
8488

8589
//console.log('pendingCall', changedInvite)
8690

@@ -222,9 +226,16 @@ class PeerInvite extends EventEmitter {
222226
this.emit('connected')
223227
})
224228

229+
230+
this.peerParty.comms.socket.on('stream', stream => {
231+
this.incomingStream = stream
232+
this.emit('stream', this)
233+
})
234+
235+
225236
this.peerParty.comms.socket.on('signal', async (data)=>{
226237

227-
if(pthis.eerParty.comms.authed){ return }
238+
if(this.peerParty.comms.authed){ return }
228239

229240
debug(' >> offer signal trickle', data)
230241

src/venue/public/p2p-test.html

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<div>
2525
<input type="text" id="invite-id" placeholder="invite id" readonly>
26-
<button onclick="answerCall()">Answer Call</button>
26+
<button onclick="acceptCall()">Answer Call</button>
2727
<button onclick="rejectCall()">Reject Call</button>
2828
</div>
2929

@@ -48,6 +48,21 @@ <h2>Remote</h2>
4848

4949
let pendingInvite = null
5050

51+
let localMediaSrc = null
52+
53+
let config = new Dataparty.Config.LocalStorageConfig({
54+
basePath:'',
55+
cloud: {
56+
uri: 'https://' + window.location.hostname + ':3000'
57+
}
58+
})
59+
60+
let hostLocal = new Dataparty.LokiParty({
61+
path: 'call-test',
62+
dbAdapter: new Dataparty.LokiParty.Loki.LokiMemoryAdapter(),
63+
config: config
64+
})
65+
5166
async function callUser(){
5267
if(pendingInvite){ return }
5368

@@ -60,9 +75,88 @@ <h2>Remote</h2>
6075
action: 'call'
6176
})
6277

78+
pendingInvite.on('stream', invite => {
79+
// got remote video stream, now let's show it in a video tag
80+
console.log('showing remote video')
81+
var video = document.getElementById('remote-video')
82+
83+
if ('srcObject' in video) {
84+
video.srcObject = invite.incomingStream
85+
} else {
86+
video.src = window.URL.createObjectURL(invite.incomingStream) // for older browsers
87+
}
88+
89+
video.play()
90+
})
91+
6392
pendingInvite.on('state-change', (invite)=>{
6493
console.log('state-change', invite.state, invite)
6594
})
95+
96+
pendingInvite.once('accepted', async (invite)=>{
97+
98+
console.log('accepted')
99+
100+
localMediaSrc = await navigator.mediaDevices.getUserMedia({
101+
video: true,
102+
audio: true
103+
})
104+
105+
console.log('showing local video')
106+
var video = document.getElementById('local-video')
107+
108+
if ('srcObject' in video) {
109+
video.srcObject = localMediaSrc
110+
} else {
111+
video.src = window.URL.createObjectURL(localMediaSrc) // for older browsers
112+
}
113+
114+
video.play()
115+
116+
await establish({
117+
mediaSrc: localMediaSrc,
118+
hostParty: hostLocal
119+
})
120+
})
121+
}
122+
123+
async function acceptCall() {
124+
125+
localMediaSrc = await navigator.mediaDevices.getUserMedia({
126+
video: true,
127+
audio: true
128+
})
129+
130+
await pendingInvite.accept(localMediaSrc)
131+
132+
pendingInvite.on('stream', invite => {
133+
// got remote video stream, now let's show it in a video tag
134+
console.log('showing remote video')
135+
var video = document.getElementById('remote-video')
136+
137+
if ('srcObject' in video) {
138+
video.srcObject = invite.incomingStream
139+
} else {
140+
video.src = window.URL.createObjectURL(invite.incomingStream) // for older browsers
141+
}
142+
143+
video.play()
144+
})
145+
}
146+
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+
})
66160
}
67161

68162
async function cancelCall() {
@@ -78,7 +172,10 @@ <h2>Remote</h2>
78172
}
79173

80174
async function init(){
81-
matchMaker = new Dataparty.MatchMakerClient(null, null)
175+
176+
await hostLocal.start()
177+
178+
matchMaker = new Dataparty.MatchMakerClient(hostLocal.privateIdentity, null)
82179

83180
await matchMaker.start()
84181

0 commit comments

Comments
 (0)