Use trickle ICE (#136)

* Try trickle ice setup

* Fix typo

* Append auth to api.dev too
This commit is contained in:
Adam Sunderland
2023-06-20 16:51:12 -04:00
committed by GitHub
parent 0858d32c1e
commit efa3bc7ac6
2 changed files with 23 additions and 3 deletions

View File

@ -10,7 +10,7 @@ export const Stream = () => {
typeof RTCPeerConnection === 'undefined'
)
return
const url = 'wss://dev.api.kittycad.io/ws/modeling/commands'
const url = 'wss://api.dev.kittycad.io/ws/modeling/commands'
const [pc, socket] = [new RTCPeerConnection(), new WebSocket(url)]
// Connection opened
socket.addEventListener('open', (event) => {
@ -40,16 +40,20 @@ export const Stream = () => {
const message = JSON.parse(event.data)
if (message.type === 'SDPAnswer') {
pc.setRemoteDescription(new RTCSessionDescription(message.answer))
} else if (message.type === 'TrickleIce') {
console.log("got remote trickle ice");
pc.addIceCandidate(message.candidate);
} else if (message.type === 'IceServerInfo') {
console.log('received IceServerInfo')
pc.setConfiguration({
iceServers: message.ice_servers,
iceTransportPolicy: "relay",
})
pc.ontrack = function (event) {
if (videoRef.current) {
videoRef.current.srcObject = event.streams[0]
videoRef.current.autoplay = true
videoRef.current.muted = true
videoRef.current.autoplay = true
videoRef.current.controls = false
}
}
@ -64,6 +68,15 @@ export const Stream = () => {
offer: pc.localDescription,
})
)
} else {
console.log("sending trickle ice candidate");
const {
candidate
} = event;
socket.send(JSON.stringify({
type: "TrickleIce",
candidate: candidate.toJSON(),
}));
}
}
@ -73,6 +86,13 @@ export const Stream = () => {
})
pc.createOffer()
.then((d) => pc.setLocalDescription(d))
.then(() => {
console.log("sent SDPOffer begin");
socket.send(JSON.stringify({
type: "SDPOffer",
offer: pc.localDescription,
}));
})
.catch(console.log)
}
}

View File

@ -1,4 +1,4 @@
export default function withBaseUrl(path: string): string {
const baseUrl = 'https://dev.api.kittycad.io'
const baseUrl = 'https://api.dev.kittycad.io'
return baseUrl + path
}