Обработка пакетов SDP от клиента
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package socket
|
||||
|
||||
import (
|
||||
connection "g365sfu/socket/struct"
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Это хранилище для всех подключённых сокетов.
|
||||
@@ -13,20 +12,14 @@ import (
|
||||
|
||||
// Здесь содержатся только соединения прошедшие рукопожатие
|
||||
|
||||
type Connection struct {
|
||||
Identificator string
|
||||
//Подсоединенный сокет
|
||||
Socket *websocket.Conn
|
||||
}
|
||||
|
||||
// Потокобезопасное хранилище подключённых сокетов
|
||||
var (
|
||||
handshakeCompletedSockets = make(map[string]*Connection)
|
||||
handshakeCompletedSockets = make(map[string]*connection.Connection)
|
||||
socketsMutex = sync.RWMutex{}
|
||||
)
|
||||
|
||||
// Добавление сокета в хранилище
|
||||
func AddSocket(conn *Connection) {
|
||||
func AddSocket(conn *connection.Connection) {
|
||||
socketsMutex.Lock()
|
||||
defer socketsMutex.Unlock()
|
||||
handshakeCompletedSockets[conn.Identificator] = conn
|
||||
@@ -40,7 +33,7 @@ func RemoveSocket(identificator string) {
|
||||
}
|
||||
|
||||
// Получение сокета по идентификатору
|
||||
func GetSocket(identificator string) (*Connection, bool) {
|
||||
func GetSocket(identificator string) (*connection.Connection, bool) {
|
||||
socketsMutex.RLock()
|
||||
defer socketsMutex.RUnlock()
|
||||
conn, exists := handshakeCompletedSockets[identificator]
|
||||
@@ -48,10 +41,10 @@ func GetSocket(identificator string) (*Connection, bool) {
|
||||
}
|
||||
|
||||
// Получение всех сокетов
|
||||
func GetAllSockets() []*Connection {
|
||||
func GetAllSockets() []*connection.Connection {
|
||||
socketsMutex.RLock()
|
||||
defer socketsMutex.RUnlock()
|
||||
connections := make([]*Connection, 0, len(handshakeCompletedSockets))
|
||||
connections := make([]*connection.Connection, 0, len(handshakeCompletedSockets))
|
||||
for _, conn := range handshakeCompletedSockets {
|
||||
connections = append(connections, conn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user