This commit is contained in:
Pierre HUBERT 2020-04-11 17:57:32 +02:00
parent 3a31b64c65
commit d1a79f49ac

View File

@ -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)