Добавление и обработка событий Peer_disconnected и Room_Delete
This commit is contained in:
28
boot/boot.go
28
boot/boot.go
@@ -4,8 +4,10 @@ import (
|
||||
"encoding/json"
|
||||
"g365sfu/bytebuffer"
|
||||
"g365sfu/logger"
|
||||
"g365sfu/network"
|
||||
"g365sfu/sfu"
|
||||
"g365sfu/socket"
|
||||
connection "g365sfu/socket/struct"
|
||||
"g365sfu/turn"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -58,7 +60,7 @@ func OnLocalICECandidate(roomID string, peerID string, candidate webrtc.ICECandi
|
||||
buffer := bytebuffer.Allocate(
|
||||
1 + 4 + len([]byte(roomID)) + 4 + len([]byte(peerID)) + 4 + len(jsonCandidate),
|
||||
)
|
||||
buffer.Put(0x04)
|
||||
buffer.Put(byte(network.ON_LOCAL_ICE_CANDIDATE))
|
||||
buffer.PutUint32(uint32(len([]byte(roomID))))
|
||||
buffer.PutBytes([]byte(roomID))
|
||||
buffer.PutUint32(uint32(len([]byte(peerID))))
|
||||
@@ -80,7 +82,7 @@ func OnServerOffer(roomID string, peerID string, offer webrtc.SessionDescription
|
||||
buffer := bytebuffer.Allocate(
|
||||
1 + 4 + len([]byte(roomID)) + 4 + len([]byte(peerID)) + 4 + len(jsonOffer),
|
||||
)
|
||||
buffer.Put(0x08)
|
||||
buffer.Put(byte(network.ON_SERVER_OFFER))
|
||||
buffer.PutUint32(uint32(len([]byte(roomID))))
|
||||
buffer.PutBytes([]byte(roomID))
|
||||
buffer.PutUint32(uint32(len([]byte(peerID))))
|
||||
@@ -91,32 +93,22 @@ func OnServerOffer(roomID string, peerID string, offer webrtc.SessionDescription
|
||||
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
|
||||
}
|
||||
func OnRoomDelete(roomID string, server *connection.Connection) {
|
||||
buffer := bytebuffer.Allocate(1 + 4 + len([]byte(roomID)))
|
||||
buffer.Put(0x10)
|
||||
buffer.Put(byte(network.ON_ROOM_DELETE))
|
||||
buffer.PutUint32(uint32(len([]byte(roomID))))
|
||||
buffer.PutBytes([]byte(roomID))
|
||||
buffer.Flip()
|
||||
room.Server.WriteBinary(buffer.Bytes())
|
||||
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
|
||||
}
|
||||
func OnPeerDisconnected(roomID string, peerID string, server *connection.Connection) {
|
||||
buffer := bytebuffer.Allocate(1 + 4 + len([]byte(roomID)) + 4 + len([]byte(peerID)))
|
||||
buffer.Put(0x11)
|
||||
buffer.Put(byte(network.ON_PEER_DISCONNECTED))
|
||||
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())
|
||||
server.WriteBinary(buffer.Bytes())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user