|
@@ -14,6 +14,7 @@ type HandleErrorFunc func(err error, context map[string]any)
|
|
type HandleCloseFunc func(i int, s string, context map[string]any) error
|
|
type HandleCloseFunc func(i int, s string, context map[string]any) error
|
|
type HandlePongFunc func(context map[string]any)
|
|
type HandlePongFunc func(context map[string]any)
|
|
type HandleMessageFunc func(message []byte, context map[string]any)
|
|
type HandleMessageFunc func(message []byte, context map[string]any)
|
|
|
|
+type BroadCastFilterCallback func(context map[string]any) bool
|
|
|
|
|
|
var managerInstance *Manager
|
|
var managerInstance *Manager
|
|
|
|
|
|
@@ -254,6 +255,20 @@ func (m *Manager) BroadCast(groupID string, msg []byte) error {
|
|
return melodyInstance.Broadcast(msg)
|
|
return melodyInstance.Broadcast(msg)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (m *Manager) BroadCastFilter(groupID string, msg []byte, filterCallback BroadCastFilterCallback) error {
|
|
|
|
+ m.melodyMapMutex.RLock()
|
|
|
|
+ defer m.melodyMapMutex.RUnlock()
|
|
|
|
+
|
|
|
|
+ melodyInstance, ok := m.melodyMap[groupID]
|
|
|
|
+ if !ok {
|
|
|
|
+ return errors.New("groupID尚未注册")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return melodyInstance.BroadcastFilter(msg, func(session *melody.Session) bool {
|
|
|
|
+ return filterCallback(session.Keys)
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
type InitOption func(*InitOptions)
|
|
type InitOption func(*InitOptions)
|
|
|
|
|
|
type InitOptions struct {
|
|
type InitOptions struct {
|