Новые события с пирами и комнатами, базовый форвардинг

This commit is contained in:
set
2026-03-16 17:08:56 +02:00
parent a9a1dc5895
commit e67bd3d824
5 changed files with 370 additions and 48 deletions

View File

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