Обработка Offers от сервера
This commit is contained in:
@@ -157,5 +157,51 @@ func processData(data <-chan []byte, connection *connection.Connection) {
|
||||
connection.Socket.WriteMessage(websocket.BinaryMessage, response.Bytes())
|
||||
continue
|
||||
}
|
||||
|
||||
//ICE-candidate пришел от участника комнаты
|
||||
if packetId == 0x06 {
|
||||
roomIdLen, _ := buffer.GetUint32()
|
||||
roomIDBytes, _ := buffer.GetBytes(int(roomIdLen))
|
||||
roomID := string(roomIDBytes)
|
||||
peerIdLen, _ := buffer.GetUint32()
|
||||
peerIDBytes, _ := buffer.GetBytes(int(peerIdLen))
|
||||
peerID := string(peerIDBytes)
|
||||
candidateLength, _ := buffer.GetUint32()
|
||||
candidateBytes, _ := buffer.GetBytes(int(candidateLength))
|
||||
var candidate webrtc.ICECandidateInit
|
||||
err := json.Unmarshal(candidateBytes, &candidate)
|
||||
if err != nil {
|
||||
logger.LogWarnMessage("failed to unmarshal ICE candidate from peer " + peerID + " in room " + roomID + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
err = sfu.AddICECandidate(roomID, peerID, candidate)
|
||||
if err != nil {
|
||||
logger.LogWarnMessage("failed to add ICE candidate from peer " + peerID + " in room " + roomID + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// SDP ANSWER от клиента при renegotiation
|
||||
if packetId == 0x07 {
|
||||
roomIdLen, _ := buffer.GetUint32()
|
||||
roomIDBytes, _ := buffer.GetBytes(int(roomIdLen))
|
||||
roomID := string(roomIDBytes)
|
||||
peerIdLen, _ := buffer.GetUint32()
|
||||
peerIDBytes, _ := buffer.GetBytes(int(peerIdLen))
|
||||
peerID := string(peerIDBytes)
|
||||
answerLength, _ := buffer.GetUint32()
|
||||
answerBytes, _ := buffer.GetBytes(int(answerLength))
|
||||
var answer webrtc.SessionDescription
|
||||
err := json.Unmarshal(answerBytes, &answer)
|
||||
if err != nil {
|
||||
logger.LogWarnMessage("failed to unmarshal answer from peer " + peerID + " in room " + roomID + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
err = sfu.HandleClientAnswer(roomID, peerID, answer)
|
||||
if err != nil {
|
||||
logger.LogWarnMessage("failed to handle client answer from peer " + peerID + " in room " + roomID + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user