File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,22 @@ func (nsoc *NSocket) unsubscribe(namespace string, sess *melody.Session) {
127127 nsoc .rwMutex .Unlock ()
128128}
129129
130+ func (nsoc * NSocket ) unsubscribeFromAll (sess * melody.Session ) {
131+ nsoc .rwMutex .Lock ()
132+ for i , v := range nsoc .namespaces {
133+ tmp := []* melody.Session {}
134+ for _ , s := range v {
135+ if s == sess || s .IsClosed () {
136+ s .Close ()
137+ continue
138+ }
139+ tmp = append (tmp , s )
140+ }
141+ nsoc .namespaces [i ] = tmp
142+ }
143+ nsoc .rwMutex .Unlock ()
144+ }
145+
130146func New (config Config ) * NSocket {
131147 nsoc := & NSocket {
132148 rwMutex : sync.RWMutex {},
@@ -182,13 +198,15 @@ func New(config Config) *NSocket {
182198
183199 nsoc .melody .HandleDisconnect (func (s * melody.Session ) {
184200 fmt .Printf ("Client :%v Disconnected\n " , s .RemoteAddr ())
201+ nsoc .unsubscribeFromAll (s )
185202 events := nsoc .config .Namespace [Default ]
186203 f , ok := events [OnNamespaceDisconnect ]
187204 if ! ok {
188205 return
189206 }
190207 f (s , nil , nsoc )
191208 })
209+
192210 if config .AllowedOrigins != nil {
193211 nsoc .melody .Upgrader .CheckOrigin = func (r * http.Request ) (ok bool ) {
194212 origin := r .Header .Get ("origin" )
You can’t perform that action at this time.
0 commit comments