mirror of https://github.com/schollz/croc.git
works
This commit is contained in:
parent
bf8bfbc237
commit
fe97a0b2fa
|
@ -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{})
|
||||
|
|
|
@ -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}'`);
|
||||
|
|
Loading…
Reference in New Issue