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 This is a candidate
|
||||||
CANDIDATE = iota
|
CANDIDATE = iota
|
||||||
|
|
||||||
|
// CloseConnection Requests the connection to be closed
|
||||||
|
CloseConnection = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
type receivedSignal struct {
|
type receivedSignal struct {
|
||||||
@ -58,8 +61,20 @@ func onSignal(callHash, peerID string, data map[string]interface{}) {
|
|||||||
|
|
||||||
if data["type"] == "SDP" {
|
if data["type"] == "SDP" {
|
||||||
newSignal.sigType = 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" {
|
} else if data["type"] == "CANDIDATE" {
|
||||||
newSignal.sigType = CANDIDATE
|
newSignal.sigType = CANDIDATE
|
||||||
@ -78,6 +93,11 @@ func onSignal(callHash, peerID string, data map[string]interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if data["type"] == "CLOSE_CONN" {
|
||||||
|
|
||||||
|
// Close connection
|
||||||
|
newSignal.sigType = CloseConnection
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.Fatalf("Invalid signal type: %s !", data["type"])
|
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
|
/// Close a connection
|
||||||
func closeConnection(r activeRelay) {
|
func closeConnection(r activeRelay) {
|
||||||
log.Printf("Closing call %s / id: %d", r.callHash, r.id)
|
log.Printf("Closing call %s / id: %d", r.callHash, r.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user