Hosting the viewer & webrtc logging (#271)

* might fix the stun server issue

* still debugging webrtc

* another turn server

* working on github actions

* updating actions file

* fixing actions

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* ga

* updating viewer

* update docs
This commit is contained in:
Ethan Weber authored and GitHub committed 2022-08-14 00:15:34 -07:00
1 parent 3083c201ed
commit 55ebaaf1b5
9 files changed
+127 -75

No files matched your search

@@ -36,15 +36,25 @@ export default function WebRtcWindow() {
username: 'openrelayproject',
credential: 'openrelayproject',
},
// extra STUN server(s):
// {
// urls: 'stun:stun.l.google.com:19302',
// },
// extra TURN server(s):
// {
// urls: 'turn:1830walnut.ddns.net',
// username: 'turnuser',
// credential: 'turnpassword',
// },
// {
// urls: 'turn:turn.nerfactory.com:3478',
// username: 'turnuser',
// credential: 'turnpassword',
// },
],
});
// connect video
pc.addEventListener('track', (evt) => {
dispatch({
type: 'write',
path: 'webrtcState/isConnected',
data: true,
});
if (evt.track.kind === 'video') {
[localVideoRef.current.srcObject] = evt.streams; // uses array destructuring
}
@@ -53,13 +63,16 @@ export default function WebRtcWindow() {
// for updating the status of the peer connection
pc.oniceconnectionstatechange = () => {
if (pc.iceConnectionState === 'connected') {
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState
console.log(`[webrtc] connectionState: ${ pc.connectionState}`);
if (pc.connectionState === 'connecting' || pc.connectionState === 'connected') {
console.log('[webrtc] connected');
dispatch({
type: 'write',
path: 'webrtcState/isConnected',
data: true,
});
} else if (pc.iceConnectionState === 'disconnected') {
} else {
dispatch({
type: 'write',
path: 'webrtcState/isConnected',
@@ -75,17 +88,22 @@ export default function WebRtcWindow() {
.createOffer()
.then((offer) => {
console.log('[webrtc] created offer');
console.log(offer);
return pcRef.current.setLocalDescription(offer);
})
.then(() => {
console.log('[webrtc] set local description');
// wait for ICE gathering to complete
console.log('[webrtc] set local description');
return new Promise((resolve) => {
if (pcRef.current.iceGatheringState === 'complete') {
console.log('[webrtc] ICE gathering complete');
resolve();
} else {
const checkState = () => {
console.log(
`[webrtc] iceGatheringState: ${
pcRef.current.iceGatheringState}`,
);
if (pcRef.current.iceGatheringState === 'complete') {
pcRef.current.removeEventListener(
'icegatheringstatechange',
@@ -94,6 +112,9 @@ export default function WebRtcWindow() {
resolve();
}
};
console.log(
'[webrtc] adding listener for `icegatheringstatechange`',
);
pcRef.current.addEventListener(
'icegatheringstatechange',
checkState,
@@ -125,7 +146,9 @@ export default function WebRtcWindow() {
// set the remote description when the offer is received
const cmd = msgpack.decode(new Uint8Array(originalCmd.data));
if (cmd.type === 'answer') {
console.log('[webrtc] received answer');
const answer = cmd.data;
console.log(answer);
pcRef.current.setRemoteDescription(answer);
}
});
@@ -133,7 +156,7 @@ export default function WebRtcWindow() {
websocket.addEventListener('open', () => {
// connect webrtc when the websocket is connected
pcRef.current = getRTCPeerConnection();
console.log('sending offer');
console.log('[webrtc] starting process');
sendOffer();
});
}, []); // empty dependency array means only run once