package session
import (
"sync"
"github.com/gorilla/websocket"
"github.com/pion/webrtc/v2"
)
type Session struct {
ID string
Name string
Admin bool
socket *websocket.Conn
peer *webrtc.PeerConnection
mu sync.Mutex
}
// TODO: write to peer data channel
func (session *Session) Write(v interface{}) error {
session.mu.Lock()
defer session.mu.Unlock()
return nil
func (session *Session) Send(v interface{}) error {
if session.socket != nil {
return session.socket.WriteJSON(v)
func (session *Session) destroy() error {
if session.peer != nil && session.peer.ConnectionState() == webrtc.PeerConnectionStateConnected {
if err := session.peer.Close(); err != nil {
return err
if err := session.socket.Close(); err != nil {