remove event from messages.

This commit is contained in:
Miroslav Šedivý 2021-09-01 21:58:39 +02:00
parent 3ac1b481ad
commit 49c48b3200
12 changed files with 144 additions and 173 deletions

View File

@ -44,8 +44,8 @@ func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) {
} }
h.sessions.AdminBroadcast( h.sessions.AdminBroadcast(
event.BORADCAST_STATUS,
message.BroadcastStatus{ message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
IsActive: broadcast.Started(), IsActive: broadcast.Started(),
URL: broadcast.Url(), URL: broadcast.Url(),
}, nil) }, nil)
@ -63,8 +63,8 @@ func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) {
broadcast.Stop() broadcast.Stop()
h.sessions.AdminBroadcast( h.sessions.AdminBroadcast(
event.BORADCAST_STATUS,
message.BroadcastStatus{ message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
IsActive: broadcast.Started(), IsActive: broadcast.Started(),
URL: broadcast.Url(), URL: broadcast.Url(),
}, nil) }, nil)

View File

@ -47,8 +47,8 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
} }
h.sessions.Broadcast( h.sessions.Broadcast(
event.SCREEN_UPDATED,
message.ScreenSize{ message.ScreenSize{
Event: event.SCREEN_UPDATED,
Width: data.Width, Width: data.Width,
Height: data.Height, Height: data.Height,
Rate: data.Rate, Rate: data.Rate,

View File

@ -11,12 +11,10 @@ import (
///////////////////////////// /////////////////////////////
type SystemWebRTC struct { type SystemWebRTC struct {
Event string `json:"event,omitempty"`
Videos []string `json:"videos"` Videos []string `json:"videos"`
} }
type SystemInit struct { type SystemInit struct {
Event string `json:"event,omitempty"`
SessionId string `json:"session_id"` SessionId string `json:"session_id"`
ControlHost ControlHost `json:"control_host"` ControlHost ControlHost `json:"control_host"`
ScreenSize ScreenSize `json:"screen_size"` ScreenSize ScreenSize `json:"screen_size"`
@ -27,13 +25,11 @@ type SystemInit struct {
} }
type SystemAdmin struct { type SystemAdmin struct {
Event string `json:"event,omitempty"`
ScreenSizesList []ScreenSize `json:"screen_sizes_list"` ScreenSizesList []ScreenSize `json:"screen_sizes_list"`
BroadcastStatus BroadcastStatus `json:"broadcast_status"` BroadcastStatus BroadcastStatus `json:"broadcast_status"`
} }
type SystemDisconnect struct { type SystemDisconnect struct {
Event string `json:"event,omitempty"`
Message string `json:"message"` Message string `json:"message"`
} }
@ -42,24 +38,20 @@ type SystemDisconnect struct {
///////////////////////////// /////////////////////////////
type SignalProvide struct { type SignalProvide struct {
Event string `json:"event,omitempty"`
SDP string `json:"sdp"` SDP string `json:"sdp"`
ICEServers []types.ICEServer `json:"iceservers"` ICEServers []types.ICEServer `json:"iceservers"`
Video string `json:"video"` Video string `json:"video"`
} }
type SignalCandidate struct { type SignalCandidate struct {
Event string `json:"event,omitempty"` webrtc.ICECandidateInit
*webrtc.ICECandidateInit
} }
type SignalAnswer struct { type SignalAnswer struct {
Event string `json:"event,omitempty"` SDP string `json:"sdp"`
SDP string `json:"sdp"`
} }
type SignalVideo struct { type SignalVideo struct {
Event string `json:"event,omitempty"`
Video string `json:"video"` Video string `json:"video"`
} }
@ -68,24 +60,20 @@ type SignalVideo struct {
///////////////////////////// /////////////////////////////
type SessionID struct { type SessionID struct {
Event string `json:"event,omitempty"` ID string `json:"id"`
ID string `json:"id"`
} }
type MemberProfile struct { type MemberProfile struct {
Event string `json:"event,omitempty"` ID string `json:"id"`
ID string `json:"id"` types.MemberProfile
*types.MemberProfile
} }
type SessionState struct { type SessionState struct {
Event string `json:"event,omitempty"` ID string `json:"id"`
ID string `json:"id"` types.SessionState
*types.SessionState
} }
type SessionData struct { type SessionData struct {
Event string `json:"event,omitempty"`
ID string `json:"id"` ID string `json:"id"`
Profile types.MemberProfile `json:"profile"` Profile types.MemberProfile `json:"profile"`
State types.SessionState `json:"state"` State types.SessionState `json:"state"`
@ -96,29 +84,25 @@ type SessionData struct {
///////////////////////////// /////////////////////////////
type ControlHost struct { type ControlHost struct {
Event string `json:"event,omitempty"`
HasHost bool `json:"has_host"` HasHost bool `json:"has_host"`
HostID string `json:"host_id,omitempty"` HostID string `json:"host_id,omitempty"`
} }
// TODO: New. // TODO: New.
type ControlMove struct { type ControlMove struct {
Event string `json:"event,omitempty"` X uint16 `json:"x"`
X uint16 `json:"x"` Y uint16 `json:"y"`
Y uint16 `json:"y"`
} }
// TODO: New. // TODO: New.
type ControlScroll struct { type ControlScroll struct {
Event string `json:"event,omitempty"` X int16 `json:"x"`
X int16 `json:"x"` Y int16 `json:"y"`
Y int16 `json:"y"`
} }
// TODO: New. // TODO: New.
type ControlKey struct { type ControlKey struct {
Event string `json:"event,omitempty"` Key uint32 `json:"key"`
Key uint32 `json:"key"`
} }
///////////////////////////// /////////////////////////////
@ -126,10 +110,9 @@ type ControlKey struct {
///////////////////////////// /////////////////////////////
type ScreenSize struct { type ScreenSize struct {
Event string `json:"event,omitempty"` Width int `json:"width"`
Width int `json:"width"` Height int `json:"height"`
Height int `json:"height"` Rate int16 `json:"rate"`
Rate int16 `json:"rate"`
} }
///////////////////////////// /////////////////////////////
@ -137,8 +120,7 @@ type ScreenSize struct {
///////////////////////////// /////////////////////////////
type ClipboardData struct { type ClipboardData struct {
Event string `json:"event,omitempty"` Text string `json:"text"`
Text string `json:"text"`
} }
///////////////////////////// /////////////////////////////
@ -146,15 +128,13 @@ type ClipboardData struct {
///////////////////////////// /////////////////////////////
type KeyboardMap struct { type KeyboardMap struct {
Event string `json:"event,omitempty"`
Layout string `json:"layout"` Layout string `json:"layout"`
Variant string `json:"variant"` Variant string `json:"variant"`
} }
type KeyboardModifiers struct { type KeyboardModifiers struct {
Event string `json:"event,omitempty"` CapsLock *bool `json:"capslock"`
CapsLock *bool `json:"capslock"` NumLock *bool `json:"numlock"`
NumLock *bool `json:"numlock"`
} }
///////////////////////////// /////////////////////////////
@ -162,7 +142,6 @@ type KeyboardModifiers struct {
///////////////////////////// /////////////////////////////
type BroadcastStatus struct { type BroadcastStatus struct {
Event string `json:"event,omitempty"`
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
} }
@ -172,7 +151,6 @@ type BroadcastStatus struct {
///////////////////////////// /////////////////////////////
type SendUnicast struct { type SendUnicast struct {
Event string `json:"event,omitempty"`
Sender string `json:"sender"` Sender string `json:"sender"`
Receiver string `json:"receiver"` Receiver string `json:"receiver"`
Subject string `json:"subject"` Subject string `json:"subject"`
@ -180,7 +158,6 @@ type SendUnicast struct {
} }
type SendBroadcast struct { type SendBroadcast struct {
Event string `json:"event,omitempty"`
Sender string `json:"sender"` Sender string `json:"sender"`
Subject string `json:"subject"` Subject string `json:"subject"`
Body interface{} `json:"body"` Body interface{} `json:"body"`

View File

@ -141,16 +141,11 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
return return
} }
ICECandidateInit := candidate.ToJSON() session.Send(
err := session.Send( event.SIGNAL_CANDIDATE,
message.SignalCandidate{ message.SignalCandidate{
Event: event.SIGNAL_CANDIDATE, ICECandidateInit: candidate.ToJSON(),
ICECandidateInit: &ICECandidateInit,
}) })
if err != nil {
logger.Warn().Err(err).Msg("sending ice candidate failed")
}
}) })
} }

View File

@ -22,10 +22,11 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
activeSession = host activeSession = host
go manager.sessions.Broadcast(message.SessionID{ go manager.sessions.Broadcast(
Event: event.FILE_CHOOSER_DIALOG_OPENED, event.FILE_CHOOSER_DIALOG_OPENED,
ID: host.ID(), message.SessionID{
}, nil) ID: host.ID(),
}, nil)
}) })
// when dialog closes, everyone should be notified. // when dialog closes, everyone should be notified.
@ -34,9 +35,9 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
activeSession = nil activeSession = nil
go manager.sessions.Broadcast(message.SessionID{ go manager.sessions.Broadcast(
Event: event.FILE_CHOOSER_DIALOG_CLOSED, event.FILE_CHOOSER_DIALOG_CLOSED,
}, nil) message.SessionID{}, nil)
}) })
// when new user joins, and someone holds dialog, he shouldd be notified about it. // when new user joins, and someone holds dialog, he shouldd be notified about it.
@ -45,17 +46,13 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
return return
} }
logger := manager.logger.With().Str("session_id", session.ID()).Logger() manager.logger.Debug().Str("session_id", session.ID()).Msg("sending file chooser dialog status to a new session")
logger.Debug().Msg("sending file chooser dialog status to a new session")
if err := session.Send(message.SessionID{ session.Send(
Event: event.FILE_CHOOSER_DIALOG_OPENED, event.FILE_CHOOSER_DIALOG_OPENED,
ID: activeSession.ID(), message.SessionID{
}); err != nil { ID: activeSession.ID(),
logger.Warn().Err(err). })
Str("event", event.FILE_CHOOSER_DIALOG_OPENED).
Msg("could not send event")
}
}) })
// when user, that holds dialog, disconnects, it should be closed. // when user, that holds dialog, disconnects, it should be closed.

View File

@ -41,12 +41,14 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
if !h.sessions.ImplicitHosting() { if !h.sessions.ImplicitHosting() {
// tell session if there is a host // tell session if there is a host
if host := h.sessions.GetHost(); host != nil { if host := h.sessions.GetHost(); host != nil {
return session.Send( session.Send(
event.CONTROL_HOST,
message.ControlHost{ message.ControlHost{
Event: event.CONTROL_HOST,
HasHost: true, HasHost: true,
HostID: host.ID(), HostID: host.ID(),
}) })
return nil
} }
} }

View File

@ -23,8 +23,8 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
} }
h.sessions.Broadcast( h.sessions.Broadcast(
event.SCREEN_UPDATED,
message.ScreenSize{ message.ScreenSize{
Event: event.SCREEN_UPDATED,
Width: payload.Width, Width: payload.Width,
Height: payload.Height, Height: payload.Height,
Rate: payload.Rate, Rate: payload.Rate,

View File

@ -15,22 +15,26 @@ func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.
return nil return nil
} }
return receiver.Send(message.SendUnicast{ receiver.Send(
Event: event.SEND_UNICAST, event.SEND_UNICAST,
Sender: session.ID(), message.SendUnicast{
Receiver: receiver.ID(), Sender: session.ID(),
Subject: payload.Subject, Receiver: receiver.ID(),
Body: payload.Body, Subject: payload.Subject,
}) Body: payload.Body,
} })
func (h *MessageHandlerCtx) sendBroadcast(session types.Session, payload *message.SendBroadcast) error { return nil
h.sessions.Broadcast(message.SendBroadcast{ }
Event: event.SEND_BROADCAST,
Sender: session.ID(), func (h *MessageHandlerCtx) sendBroadcast(session types.Session, payload *message.SendBroadcast) error {
Subject: payload.Subject, h.sessions.Broadcast(
Body: payload.Body, event.SEND_BROADCAST,
}, []string{session.ID()}) message.SendBroadcast{
Sender: session.ID(),
Subject: payload.Subject,
Body: payload.Body,
}, []string{session.ID()})
return nil return nil
} }

View File

@ -8,8 +8,8 @@ import (
func (h *MessageHandlerCtx) SessionCreated(session types.Session) error { func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
h.sessions.Broadcast( h.sessions.Broadcast(
event.SESSION_CREATED,
message.SessionData{ message.SessionData{
Event: event.SESSION_CREATED,
ID: session.ID(), ID: session.ID(),
Profile: session.Profile(), Profile: session.Profile(),
State: session.State(), State: session.State(),
@ -20,9 +20,9 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
func (h *MessageHandlerCtx) SessionDeleted(session types.Session) error { func (h *MessageHandlerCtx) SessionDeleted(session types.Session) error {
h.sessions.Broadcast( h.sessions.Broadcast(
event.SESSION_DELETED,
message.SessionID{ message.SessionID{
Event: event.SESSION_DELETED, ID: session.ID(),
ID: session.ID(),
}, nil) }, nil)
return nil return nil
@ -53,26 +53,22 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
} }
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error { func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
profile := session.Profile()
h.sessions.Broadcast( h.sessions.Broadcast(
event.SESSION_PROFILE,
message.MemberProfile{ message.MemberProfile{
Event: event.SESSION_PROFILE,
ID: session.ID(), ID: session.ID(),
MemberProfile: &profile, MemberProfile: session.Profile(),
}, nil) }, nil)
return nil return nil
} }
func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error { func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
state := session.State()
h.sessions.Broadcast( h.sessions.Broadcast(
event.SESSION_STATE,
message.SessionState{ message.SessionState{
Event: event.SESSION_STATE,
ID: session.ID(), ID: session.ID(),
SessionState: &state, SessionState: session.State(),
}, nil) }, nil)
return nil return nil

View File

@ -25,13 +25,15 @@ func (h *MessageHandlerCtx) signalRequest(session types.Session, payload *messag
return err return err
} }
return session.Send( session.Send(
event.SIGNAL_PROVIDE,
message.SignalProvide{ message.SignalProvide{
Event: event.SIGNAL_PROVIDE,
SDP: offer.SDP, SDP: offer.SDP,
ICEServers: h.webrtc.ICEServers(), ICEServers: h.webrtc.ICEServers(),
Video: payload.Video, Video: payload.Video,
}) })
return nil
} }
func (h *MessageHandlerCtx) signalRestart(session types.Session) error { func (h *MessageHandlerCtx) signalRestart(session types.Session) error {
@ -48,11 +50,13 @@ func (h *MessageHandlerCtx) signalRestart(session types.Session) error {
return err return err
} }
return session.Send( session.Send(
event.SIGNAL_RESTART,
message.SignalAnswer{ message.SignalAnswer{
Event: event.SIGNAL_RESTART, SDP: offer.SDP,
SDP: offer.SDP,
}) })
return nil
} }
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error { func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
@ -76,7 +80,7 @@ func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *mess
return nil return nil
} }
return peer.SignalCandidate(*payload.ICECandidateInit) return peer.SignalCandidate(payload.ICECandidateInit)
} }
func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.SignalVideo) error { func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.SignalVideo) error {
@ -93,9 +97,11 @@ func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.
return err return err
} }
return session.Send( session.Send(
event.SIGNAL_VIDEO,
message.SignalVideo{ message.SignalVideo{
Event: event.SIGNAL_VIDEO,
Video: payload.Video, Video: payload.Video,
}) })
return nil
} }

View File

@ -33,9 +33,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
} }
} }
return session.Send( session.Send(
event.SYSTEM_INIT,
message.SystemInit{ message.SystemInit{
Event: event.SYSTEM_INIT,
SessionId: session.ID(), SessionId: session.ID(),
ControlHost: controlHost, ControlHost: controlHost,
ScreenSize: message.ScreenSize{ ScreenSize: message.ScreenSize{
@ -50,6 +50,8 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
Videos: h.capture.VideoIDs(), Videos: h.capture.VideoIDs(),
}, },
}) })
return nil
} }
func (h *MessageHandlerCtx) systemAdmin(session types.Session) error { func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
@ -65,13 +67,15 @@ func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
} }
broadcast := h.capture.Broadcast() broadcast := h.capture.Broadcast()
return session.Send( session.Send(
event.SYSTEM_ADMIN,
message.SystemAdmin{ message.SystemAdmin{
Event: event.SYSTEM_ADMIN,
ScreenSizesList: screenSizesList, ScreenSizesList: screenSizesList,
BroadcastStatus: message.BroadcastStatus{ BroadcastStatus: message.BroadcastStatus{
IsActive: broadcast.Started(), IsActive: broadcast.Started(),
URL: broadcast.Url(), URL: broadcast.Url(),
}, },
}) })
return nil
} }

View File

@ -105,20 +105,19 @@ func (manager *WebSocketManagerCtx) Start() {
}) })
manager.sessions.OnHostChanged(func(session types.Session) { manager.sessions.OnHostChanged(func(session types.Session) {
msg := message.ControlHost{ payload := message.ControlHost{
Event: event.CONTROL_HOST,
HasHost: session != nil, HasHost: session != nil,
} }
if msg.HasHost { if payload.HasHost {
msg.HostID = session.ID() payload.HostID = session.ID()
} }
manager.sessions.Broadcast(msg, nil) manager.sessions.Broadcast(event.CONTROL_HOST, payload, nil)
manager.logger.Debug(). manager.logger.Debug().
Bool("has_host", msg.HasHost). Bool("has_host", payload.HasHost).
Str("host_id", msg.HostID). Str("host_id", payload.HostID).
Msg("session host changed") Msg("session host changed")
}) })
@ -128,22 +127,20 @@ func (manager *WebSocketManagerCtx) Start() {
return return
} }
manager.logger.Debug().Msg("sync clipboard")
data, err := manager.desktop.ClipboardGetText() data, err := manager.desktop.ClipboardGetText()
if err != nil { if err != nil {
manager.logger.Warn().Err(err).Msg("could not get clipboard content") manager.logger.Warn().Err(err).Msg("could not get clipboard content")
return return
} }
if err := session.Send(message.ClipboardData{ session.Send(
Event: event.CLIPBOARD_UPDATED, event.CLIPBOARD_UPDATED,
Text: data.Text, message.ClipboardData{
// TODO: Send HTML? Text: data.Text,
}); err != nil { // TODO: Send HTML?
manager.logger.Warn().Err(err).Msg("could not sync clipboard") })
return
}
manager.logger.Debug().Msg("session sync clipboard")
}) })
manager.fileChooserDialogEvents() manager.fileChooserDialogEvents()
@ -161,13 +158,10 @@ func (manager *WebSocketManagerCtx) AddHandler(handler types.WebSocketHandler) {
} }
func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request, checkOrigin types.CheckOrigin) { func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request, checkOrigin types.CheckOrigin) {
// add request data to logger context manager.logger.Debug().
logger := manager.logger.With().
Str("address", r.RemoteAddr). Str("address", r.RemoteAddr).
Str("agent", r.UserAgent()). Str("agent", r.UserAgent()).
Logger() Msg("attempting to upgrade connection")
logger.Debug().Msg("attempting to upgrade connection")
upgrader := websocket.Upgrader{ upgrader := websocket.Upgrader{
CheckOrigin: checkOrigin, CheckOrigin: checkOrigin,
@ -175,49 +169,60 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
connection, err := upgrader.Upgrade(w, r, nil) connection, err := upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {
logger.Error().Err(err).Msg("failed to upgrade connection") manager.logger.Error().Err(err).Msg("failed to upgrade connection")
return return
} }
session, err := manager.sessions.Authenticate(r) session, err := manager.sessions.Authenticate(r)
if err != nil { if err != nil {
logger.Debug().Err(err).Msg("authentication failed") manager.logger.Warn().Err(err).Msg("authentication failed")
// TODO: Refactor, return error code. // TODO: Better handling...
if err = connection.WriteJSON( raw, err := json.Marshal(message.SystemDisconnect{
message.SystemDisconnect{ Message: err.Error(),
})
if err != nil {
manager.logger.Error().Err(err).Msg("failed to create disconnect event")
}
err = connection.WriteJSON(
types.WebSocketMessage{
Event: event.SYSTEM_DISCONNECT, Event: event.SYSTEM_DISCONNECT,
Message: err.Error(), Payload: raw,
}); err != nil { })
logger.Error().Err(err).Msg("failed to send disconnect event")
if err != nil {
manager.logger.Error().Err(err).Msg("failed to send disconnect event")
} }
if err := connection.Close(); err != nil { if err := connection.Close(); err != nil {
logger.Warn().Err(err).Msg("connection closed with an error") manager.logger.Warn().Err(err).Msg("connection closed with an error")
} }
return return
} }
// use session id with defeault logger context // use session id with defeault logger context
logger = manager.logger.With().Str("session_id", session.ID()).Logger() logger := manager.logger.With().Str("session_id", session.ID()).Logger()
// create new peer
peer := &WebSocketPeerCtx{
logger: logger,
session: session,
connection: connection,
}
if !session.Profile().CanConnect { if !session.Profile().CanConnect {
logger.Debug().Msg("connection disabled") logger.Warn().Msg("connection disabled")
// TODO: Refactor, return error code. peer.Send(
if err = connection.WriteJSON( event.SYSTEM_DISCONNECT,
message.SystemDisconnect{ message.SystemDisconnect{
Event: event.SYSTEM_DISCONNECT,
Message: "connection disabled", Message: "connection disabled",
}); err != nil { })
logger.Error().Err(err).Msg("failed to send disconnect event")
}
if err := connection.Close(); err != nil {
logger.Warn().Err(err).Msg("connection closed with an error")
}
peer.Destroy()
return return
} }
@ -225,32 +230,17 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
logger.Warn().Msg("already connected") logger.Warn().Msg("already connected")
if !manager.sessions.MercifulReconnect() { if !manager.sessions.MercifulReconnect() {
// TODO: Refactor, return error code. peer.Send(
if err = connection.WriteJSON( event.SYSTEM_DISCONNECT,
message.SystemDisconnect{ message.SystemDisconnect{
Event: event.SYSTEM_DISCONNECT,
Message: "already connected", Message: "already connected",
}); err != nil { })
logger.Error().Err(err).Msg("failed to send disconnect event")
}
if err := connection.Close(); err != nil {
logger.Warn().Err(err).Msg("connection closed with an error")
}
peer.Destroy()
return return
} }
logger.Info().Msg("replacing peer connection") logger.Info().Msg("replacing peer connection")
// destroy previous peer connection
session.GetWebSocketPeer().Destroy()
}
peer := &WebSocketPeerCtx{
logger: logger,
session: session,
connection: connection,
} }
session.SetWebSocketPeer(peer) session.SetWebSocketPeer(peer)