diff --git a/src/croc/croc.go b/src/croc/croc.go index b199a7e0..564c36a3 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -237,6 +237,7 @@ func (c *Client) connectToRelay() (err error) { // create webrtc answer and send it over var payload []byte payload, err = base64.StdEncoding.DecodeString(wsmsg.Payload) + log.Debugf("offer recv: %s", payload) err = setRemoteDescription(c.rtc, payload) if err != nil { log.Error(err) @@ -332,9 +333,11 @@ func (c *Client) CreateOfferer(finished chan<- error) (pc *webrtc.PeerConnection ordered := false maxRetransmits := uint16(0) + var id uint16 = 5 options := &webrtc.DataChannelInit{ Ordered: &ordered, MaxRetransmits: &maxRetransmits, + ID: &id, } sendMoreCh := make(chan struct{}) diff --git a/src/webrtc/websend/index.html b/src/webrtc/websend/index.html index dfb589c3..bf54e80f 100644 --- a/src/webrtc/websend/index.html +++ b/src/webrtc/websend/index.html @@ -123,6 +123,7 @@ // websockets var socket; + var sendChannel; var pakeData; var croc = { "SharedSecret": "test1", @@ -184,20 +185,25 @@ croc.Key = croc.KeyAndSalt.Key; // create offer - pc.createOffer().then(d => { - pc.setLocalDescription(d) + sendChannel = pc.createDataChannel('data') + pc.createOffer().then(d => { + console.log(`send '[7] offer'`); + console.log(d); socket.send(writeWebsocketMessage("[7] offer", btoa(JSON.stringify(d)), croc.Key)); + pc.setLocalDescription(d); }).catch(log) } else if (data.Message == "[7] offer") { console.log(atob(data.Payload)); pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(data.Payload)))).catch(log) pc.createAnswer().then(d => { - console.log(d); + console.log("send '[8] answer'") socket.send(writeWebsocketMessage("[8] answer", btoa(JSON.stringify(d)), croc.Key)); pc.setLocalDescription(d); }).catch(log) } else if (data.Message == "[8] answer") { - pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(data.Payload)))).catch(log); + var localDesc = JSON.parse(atob(data.Payload)); + console.log("local description: " + localDesc); + pc.setRemoteDescription(new RTCSessionDescription(localDesc)).catch(log); } if (message != "") { console.log(`send '${message}'`);