mirror of
https://gitlab.com/comunic/ComunicRTCProxy
synced 2024-12-26 05:28:53 +00:00
WIP
This commit is contained in:
parent
3a31b64c65
commit
d1a79f49ac
31
relay.go
31
relay.go
@ -21,6 +21,9 @@ const (
|
||||
|
||||
// CANDIDATE This is a candidate
|
||||
CANDIDATE = iota
|
||||
|
||||
// CloseConnection Requests the connection to be closed
|
||||
CloseConnection = iota
|
||||
)
|
||||
|
||||
type receivedSignal struct {
|
||||
@ -58,8 +61,20 @@ func onSignal(callHash, peerID string, data map[string]interface{}) {
|
||||
|
||||
if data["type"] == "SDP" {
|
||||
newSignal.sigType = SDP
|
||||
newSignal.offer.Type = webrtc.SDPTypeOffer
|
||||
newSignal.offer.SDP = data["data"].(map[string]interface{})["sdp"].(string)
|
||||
|
||||
// I have to re-encode data to initialize SDP
|
||||
var enc []byte
|
||||
enc, err := json.Marshal(data["data"])
|
||||
if err != nil {
|
||||
log.Printf("Could not re-encode candidate ! %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(enc, &newSignal.offer)
|
||||
if err != nil {
|
||||
log.Printf("Discarding invalid candidate: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
} else if data["type"] == "CANDIDATE" {
|
||||
newSignal.sigType = CANDIDATE
|
||||
@ -78,6 +93,11 @@ func onSignal(callHash, peerID string, data map[string]interface{}) {
|
||||
return
|
||||
}
|
||||
|
||||
} else if data["type"] == "CLOSE_CONN" {
|
||||
|
||||
// Close connection
|
||||
newSignal.sigType = CloseConnection
|
||||
|
||||
} else {
|
||||
log.Fatalf("Invalid signal type: %s !", data["type"])
|
||||
}
|
||||
@ -112,6 +132,13 @@ func onSignal(callHash, peerID string, data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request connections to be closed
|
||||
func onCloseConnection(callHash, peerID string) {
|
||||
onSignal(callHash, peerID, map[string]interface{}{
|
||||
"type": "CLOSE_CONN",
|
||||
})
|
||||
}
|
||||
|
||||
/// Close a connection
|
||||
func closeConnection(r activeRelay) {
|
||||
log.Printf("Closing call %s / id: %d", r.callHash, r.id)
|
||||
|
Loading…
Reference in New Issue
Block a user