Новые события с пирами и комнатами, базовый форвардинг
This commit is contained in:
32
boot/boot.go
32
boot/boot.go
@@ -28,6 +28,8 @@ func Bootstrap() {
|
||||
}
|
||||
sfu.OnLocalICECandidate = OnLocalICECandidate
|
||||
sfu.OnServerOffer = OnServerOffer
|
||||
sfu.OnRoomDelete = OnRoomDelete
|
||||
sfu.OnPeerDisconnected = OnPeerDisconnected
|
||||
turnServer, err := turn.Start(turn.Config{
|
||||
ListenAddr: "0.0.0.0:3478",
|
||||
PublicIP: os.Getenv("TURN_PUBLIC_IP"),
|
||||
@@ -88,3 +90,33 @@ func OnServerOffer(roomID string, peerID string, offer webrtc.SessionDescription
|
||||
buffer.Flip()
|
||||
room.Server.WriteBinary(buffer.Bytes())
|
||||
}
|
||||
|
||||
func OnRoomDelete(roomID string) {
|
||||
room, exists := sfu.GetRoom(roomID)
|
||||
if !exists {
|
||||
logger.LogWarnMessage("tried to send room delete event to non existing room " + roomID)
|
||||
return
|
||||
}
|
||||
buffer := bytebuffer.Allocate(1 + 4 + len([]byte(roomID)))
|
||||
buffer.Put(0x10)
|
||||
buffer.PutUint32(uint32(len([]byte(roomID))))
|
||||
buffer.PutBytes([]byte(roomID))
|
||||
buffer.Flip()
|
||||
room.Server.WriteBinary(buffer.Bytes())
|
||||
}
|
||||
|
||||
func OnPeerDisconnected(roomID string, peerID string) {
|
||||
room, exists := sfu.GetRoom(roomID)
|
||||
if !exists {
|
||||
logger.LogWarnMessage("tried to send peer disconnected event to non existing room " + roomID)
|
||||
return
|
||||
}
|
||||
buffer := bytebuffer.Allocate(1 + 4 + len([]byte(roomID)) + 4 + len([]byte(peerID)))
|
||||
buffer.Put(0x11)
|
||||
buffer.PutUint32(uint32(len([]byte(roomID))))
|
||||
buffer.PutBytes([]byte(roomID))
|
||||
buffer.PutUint32(uint32(len([]byte(peerID))))
|
||||
buffer.PutBytes([]byte(peerID))
|
||||
buffer.Flip()
|
||||
room.Server.WriteBinary(buffer.Bytes())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user