mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
34 lines
667 B
Go
34 lines
667 B
Go
|
package main
|
||
|
|
||
|
import "github.com/dustin/go-broadcast"
|
||
|
|
||
|
var roomChannels = make(map[string]broadcast.Broadcaster)
|
||
|
|
||
|
func openListener(roomid string) chan interface{} {
|
||
|
listener := make(chan interface{})
|
||
|
room(roomid).Register(listener)
|
||
|
return listener
|
||
|
}
|
||
|
|
||
|
func closeListener(roomid string, listener chan interface{}) {
|
||
|
room(roomid).Unregister(listener)
|
||
|
close(listener)
|
||
|
}
|
||
|
|
||
|
func deleteBroadcast(roomid string) {
|
||
|
b, ok := roomChannels[roomid]
|
||
|
if ok {
|
||
|
b.Close()
|
||
|
delete(roomChannels, roomid)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func room(roomid string) broadcast.Broadcaster {
|
||
|
b, ok := roomChannels[roomid]
|
||
|
if !ok {
|
||
|
b = broadcast.NewBroadcaster(10)
|
||
|
roomChannels[roomid] = b
|
||
|
}
|
||
|
return b
|
||
|
}
|