ICE Candidate перевод в JSON
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
.env
|
.env
|
||||||
.vscode
|
.vscode
|
||||||
|
__debug*
|
||||||
25
boot/boot.go
25
boot/boot.go
@@ -1,12 +1,15 @@
|
|||||||
package boot
|
package boot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"g365sfu/bytebuffer"
|
||||||
"g365sfu/logger"
|
"g365sfu/logger"
|
||||||
"g365sfu/sfu"
|
"g365sfu/sfu"
|
||||||
"g365sfu/socket"
|
"g365sfu/socket"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/pion/webrtc/v4"
|
"github.com/pion/webrtc/v4"
|
||||||
)
|
)
|
||||||
@@ -28,8 +31,26 @@ func Bootstrap() {
|
|||||||
http.ListenAndServe(":"+port, nil)
|
http.ListenAndServe(":"+port, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnLocalICECandidate(roomID, peerID string, candidate webrtc.ICECandidateInit) {
|
func OnLocalICECandidate(roomID string, peerID string, candidate webrtc.ICECandidateInit) {
|
||||||
logger.LogInfoMessage("new local ICE candidate for peer " + peerID + " in room " + roomID)
|
room, exists := sfu.GetRoom(roomID)
|
||||||
|
if !exists {
|
||||||
|
logger.LogWarnMessage("tried to send local ICE candidate to non existing room " + roomID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonCandidate, _ := json.Marshal(candidate)
|
||||||
|
buffer := bytebuffer.Allocate(
|
||||||
|
1 + 4 + len([]byte(roomID)) + 4 + len([]byte(peerID)) + 4 + len(jsonCandidate),
|
||||||
|
)
|
||||||
|
buffer.Put(0x04)
|
||||||
|
buffer.PutUint32(uint32(len([]byte(roomID))))
|
||||||
|
buffer.PutBytes([]byte(roomID))
|
||||||
|
buffer.PutUint32(uint32(len([]byte(peerID))))
|
||||||
|
buffer.PutBytes([]byte(peerID))
|
||||||
|
candidateBytes := []byte(candidate.Candidate)
|
||||||
|
buffer.PutUint32(uint32(len(candidateBytes)))
|
||||||
|
buffer.PutBytes(candidateBytes)
|
||||||
|
buffer.Flip()
|
||||||
|
room.Server.Socket.WriteMessage(websocket.BinaryMessage, buffer.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnServerOffer(roomID string, peerID string, offer webrtc.SessionDescription) {
|
func OnServerOffer(roomID string, peerID string, offer webrtc.SessionDescription) {
|
||||||
|
|||||||
Reference in New Issue
Block a user