add files and ci
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m34s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m34s
This commit is contained in:
41
room.go
Normal file
41
room.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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) AddPeer(p *Peer) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
r.peers[p.ID] = p
|
||||
p.Room = r
|
||||
}
|
||||
|
||||
func (r *Room) RemovePeer(id string) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
delete(r.peers, id)
|
||||
}
|
||||
|
||||
func (r *Room) ForwardTrack(from *Peer, track *Track) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
for _, peer := range r.peers {
|
||||
if peer.ID == from.ID {
|
||||
continue
|
||||
}
|
||||
peer.AddTrack(track)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user