mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
session websocket add event.
This commit is contained in:
parent
5b5e541cc0
commit
3ac1b481ad
@ -197,7 +197,7 @@ func (manager *SessionManagerCtx) ClearHost() {
|
|||||||
// broadcasts
|
// broadcasts
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{}) {
|
func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, exclude interface{}) {
|
||||||
manager.sessionsMu.Lock()
|
manager.sessionsMu.Lock()
|
||||||
defer manager.sessionsMu.Unlock()
|
defer manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
@ -212,13 +212,11 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{})
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := session.Send(v); err != nil {
|
session.Send(event, payload)
|
||||||
manager.logger.Warn().Err(err).Msgf("broadcasting event has failed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interface{}) {
|
func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface{}, exclude interface{}) {
|
||||||
manager.sessionsMu.Lock()
|
manager.sessionsMu.Lock()
|
||||||
defer manager.sessionsMu.Unlock()
|
defer manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
@ -233,9 +231,7 @@ func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interfac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := session.Send(v); err != nil {
|
session.Send(event, payload)
|
||||||
manager.logger.Warn().Err(err).Msgf("broadcasting admin event has failed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,12 +79,12 @@ func (session *SessionCtx) GetWebSocketPeer() types.WebSocketPeer {
|
|||||||
return session.websocketPeer
|
return session.websocketPeer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) Send(v interface{}) error {
|
func (session *SessionCtx) Send(event string, payload interface{}) {
|
||||||
if session.websocketPeer == nil {
|
if session.websocketPeer == nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.websocketPeer.Send(v)
|
session.websocketPeer.Send(event, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
@ -27,7 +27,7 @@ type Session interface {
|
|||||||
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
||||||
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
||||||
GetWebSocketPeer() WebSocketPeer
|
GetWebSocketPeer() WebSocketPeer
|
||||||
Send(v interface{}) error
|
Send(event string, payload interface{})
|
||||||
|
|
||||||
// webrtc
|
// webrtc
|
||||||
SetWebRTCPeer(webrtcPeer WebRTCPeer)
|
SetWebRTCPeer(webrtcPeer WebRTCPeer)
|
||||||
@ -47,8 +47,8 @@ type SessionManager interface {
|
|||||||
GetHost() Session
|
GetHost() Session
|
||||||
ClearHost()
|
ClearHost()
|
||||||
|
|
||||||
Broadcast(v interface{}, exclude interface{})
|
Broadcast(event string, payload interface{}, exclude interface{})
|
||||||
AdminBroadcast(v interface{}, exclude interface{})
|
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
||||||
|
|
||||||
OnCreated(listener func(session Session))
|
OnCreated(listener func(session Session))
|
||||||
OnDeleted(listener func(session Session))
|
OnDeleted(listener func(session Session))
|
||||||
|
Loading…
Reference in New Issue
Block a user