All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m34s
27 lines
348 B
Go
27 lines
348 B
Go
package main
|
|
|
|
import "sync"
|
|
|
|
type Room struct {
|
|
mu sync.Mutex
|
|
peers map[string]*Peer
|
|
}
|
|
|
|
func NewRoom() *Room {
|
|
return &Room{
|
|
peers: make(map[string]*Peer),
|
|
}
|
|
}
|
|
|
|
func (r *Room) Add(p *Peer) {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
r.peers[p.ID] = p
|
|
}
|
|
|
|
func (r *Room) Remove(id string) {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
delete(r.peers, id)
|
|
}
|