1 document
.title
= "Strapp.io Host"
2 const clients
= [] //TODO: Change to Map
3 if ("WebSocket" in window
) {
4 document
.addEventListener('DOMContentLoaded', (event
) => {
5 const wsock
= new WebSocket(`${_strapp_protocol}://${window.location.hostname}:${_strapp_port}`)
7 console
.log(`Strapped to ${_strapp_protocol}://${window.location.hostname}:${_strapp_port}`)
10 wsock
.onmessage
= (msg
) => {
11 /* Message is offer from client */
12 console
.log("Incoming connection " + msg
)
14 /* State machine to parse offer */
16 /* New Client Connection*/
17 hpc
= new RTCPeerConnection()
19 hpc
.createAnswer().then((offer
) => {
20 return hpc
.setLocalDescription(offer
)
22 return hpc
.setRemoteDescription(msg
.sdp
)
24 const hpk
= getPublicKey()
27 sdp
: hpc
.localDescription
31 sdp
: hpc
.localDescription
32 clientPubKey
: msg
.pubKey
39 document
.addEventListener('DOMContentLoaded', () => {
40 document
.body
.innerHTML
= 'Websockets not supported in your browser'