Skip to content

Commit 8d556f1

Browse files
author
nullagent
committed
match maker client working well
1 parent 802e912 commit 8d556f1

3 files changed

Lines changed: 120 additions & 22 deletions

File tree

src/party/peer/peer-invite.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ class PeerInvite extends EventEmitter {
147147
})
148148
}
149149

150-
async establish({mediaSrc, hostParty, config}){
150+
async establish({mediaSrc, hostParty, config, rtcSettings}){
151+
152+
if(!rtcSettings){
153+
rtcSettings = {}
154+
}
151155

152156
let host = this.isSender()
153157
let actorField = this.isSender() ? 'from' : 'to'
@@ -185,6 +189,11 @@ class PeerInvite extends EventEmitter {
185189
debug('got webrtc offer', offer.msg)
186190
if(!this.connected && this.peerParty){
187191
this.peerParty.comms.socket.signal(offer.msg)
192+
193+
this.emit('signal', {
194+
invite: this,
195+
data: offer.msg
196+
})
188197
}
189198
}
190199
})
@@ -203,8 +212,10 @@ class PeerInvite extends EventEmitter {
203212
initiator: this.isSender(),
204213
stream: mediaSrc,
205214
//stream: this.isSender() ? mediaSrc : undefined, //false,
206-
trickle: true,
207-
allowHalfTrickle: true,
215+
trickle: rtcSettings.trickle? rtcSettings.trickle : true,
216+
iceTransportPolicy : rtcSettings.iceTransportPolicy ? rtcSettings.iceTransportPolicy : 'all',
217+
allowHalfTrickle: rtcSettings.allowHalfTrickle? rtcSettings.allowHalfTrickle : true,
218+
iceCompleteTimeout: 30*1000,
208219
config: {
209220
iceServers: [
210221
{ urls: 'stun:st1.dataparty.xyz:3478'},
@@ -216,7 +227,7 @@ class PeerInvite extends EventEmitter {
216227
]
217228
}
218229
},
219-
trickle: true,
230+
trickle: rtcSettings.trickle? rtcSettings.trickle : true,
220231
discoverRemoteIdentity: false,
221232
remoteIdentity: otherIdentity
222233
}),
@@ -247,6 +258,11 @@ class PeerInvite extends EventEmitter {
247258

248259
if(this.peerParty.comms.authed){ return }
249260

261+
this.emit('offer', {
262+
invite: this,
263+
data
264+
})
265+
250266
debug(' >> offer signal trickle', data)
251267

252268

src/topics/host-topic.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class HostTopic {
99
this.type = type
1010
this.created = Date.now()
1111

12+
this.throttle = false
13+
1214
debug('new topic', path, '(', type, ')')
1315

1416
this.lastMessage = null
@@ -57,6 +59,7 @@ class HostTopic {
5759
throw new Error('published called before advertise')
5860
}
5961

62+
/*
6063
if(!this.sending && this.sendRequest){
6164
6265
this.sendRequest=false
@@ -72,11 +75,11 @@ class HostTopic {
7275
7376
return
7477
75-
}else if(!this.sendRequest && !this.sending) {
78+
}else if(!this.sendRequest && !this.sending) {*/
7679

7780
this.lastMessage = data
7881
this.lastMessageTime = Date.now()
79-
}
82+
//}
8083

8184

8285

src/venue/public/p2p-test.html

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,53 @@
44
<script src="node_modules/argon2-browser/dist/argon2-bundled.min.js"></script>
55

66
<title>p2p tester</title>
7+
8+
<style>
9+
10+
body {
11+
background-color: rgb(95, 95, 95);
12+
color:aliceblue;
13+
}
14+
15+
.bordered {
16+
border: 1px solid rgb(230, 230, 230);
17+
padding: 10px;
18+
margin: 0 auto;
19+
max-width: 320px;
20+
background-color: #141414cc;
21+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
22+
border-radius: 4px;
23+
}
24+
25+
p {
26+
color: #666;
27+
line-height: 1.6;
28+
}
29+
30+
video {
31+
height: 20vh
32+
}
33+
34+
textarea {
35+
width: 100vw;
36+
height: 20vh;
37+
white-space: pre;
38+
overflow-wrap: normal;
39+
overflow-x: scroll;
40+
background-color: #666;
41+
color: white;
42+
}
43+
</style>
744
</head>
845

946
<body>
1047

48+
<div>
49+
Trickle: <input type="checkbox" id="trickle-checkbox">
50+
HalfTrickle: <input type="checkbox" id="half-trickle-checkbox">
51+
TURN only: <input type="checkbox" id="turn-checkbox">
52+
</div>
53+
1154
<div>
1255
<input type="text" id="user-hash" placeholder="your user hash" readonly>
1356
<input type="text" id="user-call-hash" placeholder="user to call">
@@ -37,6 +80,16 @@ <h2>Remote</h2>
3780
<video id="remote-video"></video>
3881
</div>
3982

83+
<div>
84+
<h2>Offers Sent</h2>
85+
<textarea id="offerArea"></textarea>
86+
</div>
87+
88+
89+
<div>
90+
<h2>Offers recieved</h2>
91+
<textarea id="answerArea"></textarea>
92+
</div>
4093

4194
<script>
4295

@@ -63,6 +116,42 @@ <h2>Remote</h2>
63116
config: config
64117
})
65118

119+
async function setupDebug(active){
120+
// id="trickle-checkbox">
121+
// id="half-trickle-checkbox">
122+
// id="turn-checkbox">
123+
124+
let offerArea = document.getElementById('offerArea')
125+
let answerArea = document.getElementById('answerArea')
126+
127+
// let trickleCheckbox = document.getElementById('trickle-checkbox')
128+
// let halfTrickleCheckbox = document.getElementById('half-trickle-checkbox')
129+
// let turnCheckbox = document.getElementById('turn-checkbox')
130+
131+
active.on('signal', ({invite, data})=>{
132+
answerArea.value += '\n' + JSON.stringify(data)
133+
})
134+
135+
136+
active.on('offer', ({invite, data})=>{
137+
offerArea.value += '\n' + JSON.stringify(data)
138+
})
139+
140+
active.on('stream', invite => {
141+
// got remote video stream, now let's show it in a video tag
142+
console.log('showing remote video')
143+
var video = document.getElementById('remote-video')
144+
145+
if ('srcObject' in video) {
146+
video.srcObject = invite.incomingStream
147+
} else {
148+
video.src = window.URL.createObjectURL(invite.incomingStream) // for older browsers
149+
}
150+
151+
video.play()
152+
})
153+
}
154+
66155
async function callUser(){
67156
if(pendingInvite){ return }
68157

@@ -75,7 +164,7 @@ <h2>Remote</h2>
75164
action: 'call'
76165
})
77166

78-
pendingInvite.on('stream', invite => {
167+
/* pendingInvite.on('stream', invite => {
79168
// got remote video stream, now let's show it in a video tag
80169
console.log('showing remote video')
81170
var video = document.getElementById('remote-video')
@@ -87,7 +176,7 @@ <h2>Remote</h2>
87176
}
88177
89178
video.play()
90-
})
179+
})*/
91180

92181
pendingInvite.on('state-change', (invite)=>{
93182
console.log('state-change', invite.state, invite)
@@ -97,6 +186,8 @@ <h2>Remote</h2>
97186

98187
console.log('accepted')
99188

189+
setupDebug(pendingInvite)
190+
100191
localMediaSrc = await navigator.mediaDevices.getUserMedia({
101192
video: true,
102193
audio: true
@@ -122,6 +213,8 @@ <h2>Remote</h2>
122213

123214
async function acceptCall() {
124215

216+
setupDebug(pendingInvite)
217+
125218
localMediaSrc = await navigator.mediaDevices.getUserMedia({
126219
video: true,
127220
audio: true
@@ -139,20 +232,6 @@ <h2>Remote</h2>
139232
video.play()
140233

141234
await pendingInvite.accept(localMediaSrc, config)
142-
143-
pendingInvite.on('stream', invite => {
144-
// got remote video stream, now let's show it in a video tag
145-
console.log('showing remote video')
146-
var video = document.getElementById('remote-video')
147-
148-
if ('srcObject' in video) {
149-
video.srcObject = invite.incomingStream
150-
} else {
151-
video.src = window.URL.createObjectURL(invite.incomingStream) // for older browsers
152-
}
153-
154-
video.play()
155-
})
156235
}
157236

158237

0 commit comments

Comments
 (0)