Rename group package and defaults to halls
This commit is contained in:
+17
-17
@@ -17,7 +17,7 @@ import (
|
||||
"git.stormux.org/storm/skald/codecs"
|
||||
"git.stormux.org/storm/skald/conn"
|
||||
"git.stormux.org/storm/skald/estimator"
|
||||
"git.stormux.org/storm/skald/group"
|
||||
"git.stormux.org/storm/skald/hall"
|
||||
"git.stormux.org/storm/skald/ice"
|
||||
"git.stormux.org/storm/skald/jitter"
|
||||
"git.stormux.org/storm/skald/packetcache"
|
||||
@@ -193,8 +193,8 @@ func (down *rtpDownConnection) getTracks() []*rtpDownTrack {
|
||||
return tracks
|
||||
}
|
||||
|
||||
func newDownConn(c group.Client, id string, remote conn.Up) (*rtpDownConnection, error) {
|
||||
api, err := c.Group().API()
|
||||
func newDownConn(c hall.Client, id string, remote conn.Up) (*rtpDownConnection, error) {
|
||||
api, err := c.Hall().API()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -504,7 +504,7 @@ func (up *rtpUpTrack) hasRtcpFb(tpe, parameter string) bool {
|
||||
|
||||
type rtpUpConnection struct {
|
||||
id string
|
||||
client group.Client
|
||||
client hall.Client
|
||||
label string
|
||||
pc *webrtc.PeerConnection
|
||||
iceCandidates []*webrtc.ICECandidateInit
|
||||
@@ -599,7 +599,7 @@ func (up *rtpUpConnection) flushICECandidates() error {
|
||||
}
|
||||
|
||||
// pushConnNow pushes a connection to all of the clients in a group
|
||||
func pushConnNow(up *rtpUpConnection, g *group.Group, cs []group.Client) {
|
||||
func pushConnNow(up *rtpUpConnection, g *hall.Hall, cs []hall.Client) {
|
||||
up.mu.Lock()
|
||||
up.pushed = true
|
||||
replace := up.replace
|
||||
@@ -616,12 +616,12 @@ func pushConnNow(up *rtpUpConnection, g *group.Group, cs []group.Client) {
|
||||
}
|
||||
|
||||
// pushConn schedules a call to pushConnNow
|
||||
func pushConn(up *rtpUpConnection, g *group.Group, cs []group.Client) {
|
||||
func pushConn(up *rtpUpConnection, g *hall.Hall, cs []hall.Client) {
|
||||
up.mu.Lock()
|
||||
up.pushed = false
|
||||
up.mu.Unlock()
|
||||
|
||||
go func(g *group.Group, cs []group.Client) {
|
||||
go func(g *hall.Hall, cs []hall.Client) {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
up.mu.Lock()
|
||||
pushed := up.pushed
|
||||
@@ -633,14 +633,14 @@ func pushConn(up *rtpUpConnection, g *group.Group, cs []group.Client) {
|
||||
}(g, cs)
|
||||
}
|
||||
|
||||
func newUpConn(c group.Client, id string, label string, offer string) (*rtpUpConnection, error) {
|
||||
func newUpConn(c hall.Client, id string, label string, offer string) (*rtpUpConnection, error) {
|
||||
var o sdp.SessionDescription
|
||||
err := o.Unmarshal([]byte(offer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
api, err := c.Group().API()
|
||||
api, err := c.Hall().API()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -686,10 +686,10 @@ func newUpConn(c group.Client, id string, label string, offer string) (*rtpUpCon
|
||||
|
||||
up.mu.Unlock()
|
||||
|
||||
pushConn(up, c.Group(), c.Group().GetClients(c))
|
||||
pushConn(up, c.Hall(), c.Hall().GetClients(c))
|
||||
})
|
||||
|
||||
pushConn(up, c.Group(), c.Group().GetClients(c))
|
||||
pushConn(up, c.Hall(), c.Hall().GetClients(c))
|
||||
go rtcpUpSender(up)
|
||||
|
||||
return up, nil
|
||||
@@ -890,7 +890,7 @@ func sadd(x, y uint64) uint64 {
|
||||
|
||||
func maxUpBitrate(t *rtpUpTrack) uint64 {
|
||||
minrate := ^uint64(0)
|
||||
maxrate := uint64(group.MinBitrate)
|
||||
maxrate := uint64(hall.MinBitrate)
|
||||
maxsid := 0
|
||||
maxtid := 0
|
||||
local := t.getLocal()
|
||||
@@ -902,8 +902,8 @@ func maxUpBitrate(t *rtpUpTrack) uint64 {
|
||||
if maxtid < tid {
|
||||
maxtid = tid
|
||||
}
|
||||
if r < group.MinBitrate {
|
||||
r = group.MinBitrate
|
||||
if r < hall.MinBitrate {
|
||||
r = hall.MinBitrate
|
||||
}
|
||||
if minrate > r {
|
||||
minrate = r
|
||||
@@ -997,14 +997,14 @@ func sendUpRTCP(up *rtpUpConnection) error {
|
||||
if t.Kind() == webrtc.RTPCodecTypeAudio {
|
||||
rate = sadd(rate, 100*1024)
|
||||
} else if t.Label() == "l" {
|
||||
rate = sadd(rate, group.LowBitrate)
|
||||
rate = sadd(rate, hall.LowBitrate)
|
||||
} else {
|
||||
rate = sadd(rate, maxUpBitrate(t))
|
||||
}
|
||||
}
|
||||
|
||||
if rate > group.MaxBitrate {
|
||||
rate = group.MaxBitrate
|
||||
if rate > hall.MaxBitrate {
|
||||
rate = hall.MaxBitrate
|
||||
}
|
||||
if len(ssrcs) > 0 {
|
||||
packets = append(packets,
|
||||
|
||||
+103
-103
@@ -20,7 +20,7 @@ import (
|
||||
"git.stormux.org/storm/skald/conn"
|
||||
"git.stormux.org/storm/skald/diskwriter"
|
||||
"git.stormux.org/storm/skald/estimator"
|
||||
"git.stormux.org/storm/skald/group"
|
||||
"git.stormux.org/storm/skald/hall"
|
||||
"git.stormux.org/storm/skald/ice"
|
||||
"git.stormux.org/storm/skald/token"
|
||||
"git.stormux.org/storm/skald/unbounded"
|
||||
@@ -33,7 +33,7 @@ func errorToWSCloseMessage(id string, err error) (*clientMessage, []byte) {
|
||||
switch e := err.(type) {
|
||||
case *websocket.CloseError:
|
||||
code = websocket.CloseNormalClosure
|
||||
case group.ProtocolError:
|
||||
case hall.ProtocolError:
|
||||
code = websocket.CloseProtocolError
|
||||
m = &clientMessage{
|
||||
Type: "usermessage",
|
||||
@@ -43,7 +43,7 @@ func errorToWSCloseMessage(id string, err error) (*clientMessage, []byte) {
|
||||
Value: e.Error(),
|
||||
}
|
||||
text = e.Error()
|
||||
case group.UserError, group.KickError:
|
||||
case hall.UserError, hall.KickError:
|
||||
code = websocket.CloseNormalClosure
|
||||
m = errorMessage(id, err)
|
||||
text = e.Error()
|
||||
@@ -60,7 +60,7 @@ func isWSNormalError(err error) bool {
|
||||
}
|
||||
|
||||
type webClient struct {
|
||||
group *group.Group
|
||||
hall *hall.Hall
|
||||
addr net.Addr
|
||||
id string
|
||||
username string
|
||||
@@ -77,8 +77,8 @@ type webClient struct {
|
||||
up map[string]*rtpUpConnection
|
||||
}
|
||||
|
||||
func (c *webClient) Group() *group.Group {
|
||||
return c.group
|
||||
func (c *webClient) Hall() *hall.Hall {
|
||||
return c.hall
|
||||
}
|
||||
|
||||
func (c *webClient) Addr() net.Addr {
|
||||
@@ -130,7 +130,7 @@ type clientMessage struct {
|
||||
Token string `json:"token,omitempty"`
|
||||
Privileged bool `json:"privileged,omitempty"`
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
Status *group.Status `json:"status,omitempty"`
|
||||
Status *hall.Status `json:"status,omitempty"`
|
||||
Data map[string]interface{} `json:"data,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Value interface{} `json:"value,omitempty"`
|
||||
@@ -229,7 +229,7 @@ func delUpConn(c *webClient, id string, userId string, push bool) error {
|
||||
replace := conn.getReplace(false)
|
||||
|
||||
delete(c.up, id)
|
||||
g := c.group
|
||||
g := c.hall
|
||||
c.mu.Unlock()
|
||||
|
||||
conn.mu.Lock()
|
||||
@@ -386,9 +386,9 @@ func addDownTrackUnlocked(conn *rtpDownConnection, remoteTrack *rtpUpTrack) erro
|
||||
// replace the RTCP feedback types with the ones we understand
|
||||
remoteCodec := remoteTrack.Codec()
|
||||
if strings.HasPrefix(strings.ToLower(remoteCodec.MimeType), "video/") {
|
||||
remoteCodec.RTCPFeedback = group.VideoRTCPFeedback
|
||||
remoteCodec.RTCPFeedback = hall.VideoRTCPFeedback
|
||||
} else {
|
||||
remoteCodec.RTCPFeedback = group.AudioRTCPFeedback
|
||||
remoteCodec.RTCPFeedback = hall.AudioRTCPFeedback
|
||||
}
|
||||
|
||||
local, err := webrtc.NewTrackLocalStaticRTP(
|
||||
@@ -408,7 +408,7 @@ func addDownTrackUnlocked(conn *rtpDownConnection, remoteTrack *rtpUpTrack) erro
|
||||
}
|
||||
|
||||
codec := local.Codec()
|
||||
ptype, err := group.CodecPayloadType(local.Codec())
|
||||
ptype, err := hall.CodecPayloadType(local.Codec())
|
||||
if err != nil {
|
||||
log.Printf("Couldn't determine ptype for codec %v: %v",
|
||||
codec.MimeType, err)
|
||||
@@ -726,31 +726,31 @@ func parseRequested(r interface{}) (map[string][]string, error) {
|
||||
}
|
||||
|
||||
func (c *webClient) setRequested(requested map[string][]string) error {
|
||||
if c.group == nil {
|
||||
if c.hall == nil {
|
||||
return errors.New("attempted to request with no group joined")
|
||||
}
|
||||
c.requested = requested
|
||||
|
||||
requestConns(c, c.group, "")
|
||||
requestConns(c, c.hall, "")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *webClient) setRequestedStream(down *rtpDownConnection, requested []string) error {
|
||||
var remoteClient group.Client
|
||||
var remoteClient hall.Client
|
||||
remote, ok := down.remote.(*rtpUpConnection)
|
||||
if ok {
|
||||
remoteClient = remote.client
|
||||
}
|
||||
down.requested = requested
|
||||
return remoteClient.RequestConns(c, c.group, remote.id)
|
||||
return remoteClient.RequestConns(c, c.hall, remote.id)
|
||||
}
|
||||
|
||||
func (c *webClient) RequestConns(target group.Client, g *group.Group, id string) error {
|
||||
func (c *webClient) RequestConns(target hall.Client, g *hall.Hall, id string) error {
|
||||
c.action(requestConnsAction{g, target, id})
|
||||
return nil
|
||||
}
|
||||
|
||||
func requestConns(target group.Client, g *group.Group, id string) {
|
||||
func requestConns(target hall.Client, g *hall.Hall, id string) {
|
||||
clients := g.GetClients(target)
|
||||
for _, c := range clients {
|
||||
c.RequestConns(target, g, id)
|
||||
@@ -817,7 +817,7 @@ func requestedTracks(c *webClient, requested []string, tracks []conn.UpTrack) ([
|
||||
return ts, limitSid
|
||||
}
|
||||
|
||||
func (c *webClient) PushConn(g *group.Group, id string, up conn.Up, tracks []conn.UpTrack, replace string) error {
|
||||
func (c *webClient) PushConn(g *hall.Hall, id string, up conn.Up, tracks []conn.UpTrack, replace string) error {
|
||||
c.action(pushConnAction{g, id, up, tracks, replace})
|
||||
return nil
|
||||
}
|
||||
@@ -854,7 +854,7 @@ func StartClient(conn *websocket.Conn, addr net.Addr) (err error) {
|
||||
),
|
||||
)
|
||||
conn.Close()
|
||||
err = group.ProtocolError("client didn't handshake")
|
||||
err = hall.ProtocolError("client didn't handshake")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -883,7 +883,7 @@ func StartClient(conn *websocket.Conn, addr net.Addr) (err error) {
|
||||
m, e := errorToWSCloseMessage(c.id, err)
|
||||
if isWSNormalError(err) {
|
||||
err = nil
|
||||
} else if _, ok := err.(group.KickError); ok {
|
||||
} else if _, ok := err.(hall.KickError); ok {
|
||||
err = nil
|
||||
}
|
||||
if m != nil {
|
||||
@@ -896,7 +896,7 @@ func StartClient(conn *websocket.Conn, addr net.Addr) (err error) {
|
||||
}
|
||||
|
||||
type pushConnAction struct {
|
||||
group *group.Group
|
||||
hall *hall.Hall
|
||||
id string
|
||||
conn conn.Up
|
||||
tracks []conn.UpTrack
|
||||
@@ -904,8 +904,8 @@ type pushConnAction struct {
|
||||
}
|
||||
|
||||
type requestConnsAction struct {
|
||||
group *group.Group
|
||||
target group.Client
|
||||
hall *hall.Hall
|
||||
target hall.Client
|
||||
id string
|
||||
}
|
||||
|
||||
@@ -939,7 +939,7 @@ type kickAction struct {
|
||||
message string
|
||||
}
|
||||
|
||||
var errEmptyId = group.ProtocolError("empty id")
|
||||
var errEmptyId = hall.ProtocolError("empty id")
|
||||
|
||||
func member(v string, l []string) bool {
|
||||
for _, w := range l {
|
||||
@@ -1108,14 +1108,14 @@ func pushDownConn(c *webClient, id string, up conn.Up, tracks []conn.UpTrack, re
|
||||
func handleAction(c *webClient, a any) error {
|
||||
switch a := a.(type) {
|
||||
case pushConnAction:
|
||||
if c.group == nil || c.group != a.group {
|
||||
if c.hall == nil || c.hall != a.hall {
|
||||
log.Printf("Got connectsions for wrong group")
|
||||
return nil
|
||||
}
|
||||
return pushDownConn(c, a.id, a.conn, a.tracks, a.replace)
|
||||
case requestConnsAction:
|
||||
g := c.group
|
||||
if g == nil || a.group != g {
|
||||
g := c.hall
|
||||
if g == nil || a.hall != g {
|
||||
log.Printf("Misdirected pushConns")
|
||||
return nil
|
||||
}
|
||||
@@ -1148,7 +1148,7 @@ func handleAction(c *webClient, a any) error {
|
||||
tracks[i] = t.remote
|
||||
}
|
||||
c.PushConn(
|
||||
c.group,
|
||||
c.hall,
|
||||
down.remote.Id(), down.remote,
|
||||
tracks, "",
|
||||
)
|
||||
@@ -1163,8 +1163,8 @@ func handleAction(c *webClient, a any) error {
|
||||
}
|
||||
|
||||
case pushClientAction:
|
||||
if a.group != c.group.Name() {
|
||||
log.Printf("got client for wrong group")
|
||||
if a.group != c.hall.Name() {
|
||||
log.Printf("got client for wrong hall")
|
||||
return nil
|
||||
}
|
||||
perms := append([]string(nil), a.permissions...)
|
||||
@@ -1178,11 +1178,11 @@ func handleAction(c *webClient, a any) error {
|
||||
Data: a.data,
|
||||
})
|
||||
case joinedAction:
|
||||
var status *group.Status
|
||||
var status *hall.Status
|
||||
var data map[string]interface{}
|
||||
var g *group.Group
|
||||
var g *hall.Hall
|
||||
if a.group != "" {
|
||||
g = group.Get(a.group)
|
||||
g = hall.Get(a.group)
|
||||
if g != nil {
|
||||
s := g.Status(true, nil)
|
||||
status = &s
|
||||
@@ -1230,7 +1230,7 @@ func handleAction(c *webClient, a any) error {
|
||||
switch a.kind {
|
||||
case "op":
|
||||
c.permissions = addnew("op", c.permissions)
|
||||
g := c.Group()
|
||||
g := c.Hall()
|
||||
if g != nil && g.Description().AllowRecording {
|
||||
c.permissions = addnew("record", c.permissions)
|
||||
}
|
||||
@@ -1246,11 +1246,11 @@ func handleAction(c *webClient, a any) error {
|
||||
case "unshutup":
|
||||
c.permissions = addnew("message", c.permissions)
|
||||
default:
|
||||
return group.UserError("unknown permission")
|
||||
return hall.UserError("unknown permission")
|
||||
}
|
||||
c.action(permissionsChangedAction{})
|
||||
case permissionsChangedAction:
|
||||
g := c.Group()
|
||||
g := c.Hall()
|
||||
if g == nil {
|
||||
return errors.New("Permissions changed in no group")
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ func handleAction(c *webClient, a any) error {
|
||||
user := c.Username()
|
||||
d := c.Data()
|
||||
clients := g.GetClients(nil)
|
||||
go func(clients []group.Client) {
|
||||
go func(clients []hall.Client) {
|
||||
for _, cc := range clients {
|
||||
cc.PushClient(
|
||||
g.Name(), "change", id, user, perms, d,
|
||||
@@ -1292,7 +1292,7 @@ func handleAction(c *webClient, a any) error {
|
||||
}
|
||||
}(clients)
|
||||
case kickAction:
|
||||
return group.KickError{
|
||||
return hall.KickError{
|
||||
a.id, a.username, a.message,
|
||||
}
|
||||
default:
|
||||
@@ -1313,7 +1313,7 @@ func failUpConnection(c *webClient, id string, message string) error {
|
||||
}
|
||||
}
|
||||
if message != "" {
|
||||
err := c.error(group.UserError(message))
|
||||
err := c.error(hall.UserError(message))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1322,7 +1322,7 @@ func failUpConnection(c *webClient, id string, message string) error {
|
||||
}
|
||||
|
||||
func leaveGroup(c *webClient) {
|
||||
if c.group == nil {
|
||||
if c.hall == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1337,11 +1337,11 @@ func leaveGroup(c *webClient) {
|
||||
}
|
||||
}
|
||||
|
||||
group.DelClient(c)
|
||||
hall.DelClient(c)
|
||||
c.permissions = nil
|
||||
c.data = nil
|
||||
c.requested = make(map[string][]string)
|
||||
c.group = nil
|
||||
c.hall = nil
|
||||
}
|
||||
|
||||
func closeDownConn(c *webClient, id string, message string) error {
|
||||
@@ -1357,7 +1357,7 @@ func closeDownConn(c *webClient, id string, message string) error {
|
||||
return err
|
||||
}
|
||||
if message != "" {
|
||||
err := c.error(group.UserError(message))
|
||||
err := c.error(hall.UserError(message))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1375,10 +1375,10 @@ func (c *webClient) Joined(group, kind string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func kickClient(g *group.Group, id string, user *string, dest string, message string) error {
|
||||
func kickClient(g *hall.Hall, id string, user *string, dest string, message string) error {
|
||||
client := g.GetClient(dest)
|
||||
if client == nil {
|
||||
return group.UserError("no such user")
|
||||
return hall.UserError("no such user")
|
||||
}
|
||||
|
||||
return client.Kick(id, user, message)
|
||||
@@ -1387,14 +1387,14 @@ func kickClient(g *group.Group, id string, user *string, dest string, message st
|
||||
func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
if m.Source != "" {
|
||||
if m.Source != c.Id() {
|
||||
return group.ProtocolError("spoofed client id")
|
||||
return hall.ProtocolError("spoofed client id")
|
||||
}
|
||||
}
|
||||
|
||||
if m.Type != "join" {
|
||||
if m.Username != nil {
|
||||
if *m.Username != c.Username() {
|
||||
return group.ProtocolError("spoofed username")
|
||||
return hall.ProtocolError("spoofed username")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1402,25 +1402,25 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
switch m.Type {
|
||||
case "join":
|
||||
if m.Kind == "leave" {
|
||||
if c.group == nil || c.group.Name() != m.Group {
|
||||
return group.UserError("you are not joined")
|
||||
if c.hall == nil || c.hall.Name() != m.Group {
|
||||
return hall.UserError("you are not joined")
|
||||
}
|
||||
leaveGroup(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
if m.Kind != "join" {
|
||||
return group.ProtocolError("unknown kind")
|
||||
return hall.ProtocolError("unknown kind")
|
||||
}
|
||||
|
||||
if c.group != nil {
|
||||
return group.ProtocolError(
|
||||
if c.hall != nil {
|
||||
return hall.ProtocolError(
|
||||
"cannot join multiple groups",
|
||||
)
|
||||
}
|
||||
c.data = m.Data
|
||||
g, err := group.AddClient(m.Group, c,
|
||||
group.ClientCredentials{
|
||||
g, err := hall.AddClient(m.Group, c,
|
||||
hall.ClientCredentials{
|
||||
Username: m.Username,
|
||||
Password: m.Password,
|
||||
Token: m.Token,
|
||||
@@ -1428,11 +1428,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
)
|
||||
if err != nil {
|
||||
var e, s string
|
||||
var autherr *group.NotAuthorisedError
|
||||
var autherr *hall.NotAuthorisedError
|
||||
if errors.Is(err, token.ErrUsernameRequired) {
|
||||
s = err.Error()
|
||||
e = "need-username"
|
||||
} else if errors.Is(err, group.ErrDuplicateUsername) {
|
||||
} else if errors.Is(err, hall.ErrDuplicateUsername) {
|
||||
s = err.Error()
|
||||
e = "duplicate-username"
|
||||
} else if errors.As(err, &autherr) {
|
||||
@@ -1441,7 +1441,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
log.Printf("Join group: %v", err)
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
s = "group does not exist"
|
||||
} else if _, ok := err.(group.UserError); ok {
|
||||
} else if _, ok := err.(hall.UserError); ok {
|
||||
s = err.Error()
|
||||
} else {
|
||||
s = "internal server error"
|
||||
@@ -1469,7 +1469,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
Value: redirect,
|
||||
})
|
||||
}
|
||||
c.group = g
|
||||
c.hall = g
|
||||
case "request":
|
||||
requested, err := parseRequested(m.Request)
|
||||
if err != nil {
|
||||
@@ -1498,7 +1498,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
Type: "abort",
|
||||
Id: m.Id,
|
||||
})
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
err := gotOffer(c, m.Id, m.Label, m.SDP, m.Replace)
|
||||
if err != nil {
|
||||
@@ -1565,16 +1565,16 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
return errEmptyId
|
||||
}
|
||||
if m.Candidate == nil {
|
||||
return group.ProtocolError("null candidate")
|
||||
return hall.ProtocolError("null candidate")
|
||||
}
|
||||
err := gotICE(c, m.Candidate, m.Id)
|
||||
if err != nil {
|
||||
log.Printf("ICE: %v", err)
|
||||
}
|
||||
case "chat", "usermessage":
|
||||
g := c.group
|
||||
g := c.hall
|
||||
if g == nil {
|
||||
return c.error(group.UserError("join a group first"))
|
||||
return c.error(hall.UserError("join a group first"))
|
||||
}
|
||||
|
||||
required := "message"
|
||||
@@ -1582,7 +1582,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
required = "caption"
|
||||
}
|
||||
if !member(required, c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
|
||||
id := m.Id
|
||||
@@ -1614,7 +1614,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
Value: m.Value,
|
||||
}
|
||||
if m.Dest == "" {
|
||||
var except group.Client
|
||||
var except hall.Client
|
||||
if m.NoEcho {
|
||||
except = c
|
||||
}
|
||||
@@ -1625,38 +1625,38 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
} else {
|
||||
cc := g.GetClient(m.Dest)
|
||||
if cc == nil {
|
||||
return c.error(group.UserError("user unknown"))
|
||||
return c.error(hall.UserError("user unknown"))
|
||||
}
|
||||
ccc, ok := cc.(*webClient)
|
||||
if !ok {
|
||||
return c.error(group.UserError(
|
||||
return c.error(hall.UserError(
|
||||
"this user doesn't chat",
|
||||
))
|
||||
}
|
||||
ccc.write(mm)
|
||||
}
|
||||
case "groupaction":
|
||||
g := c.group
|
||||
g := c.hall
|
||||
if g == nil {
|
||||
return c.error(group.UserError("join a group first"))
|
||||
return c.error(hall.UserError("join a group first"))
|
||||
}
|
||||
switch m.Kind {
|
||||
case "clearchat":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
var id, userId string
|
||||
if m.Value != nil {
|
||||
value, ok := m.Value.(map[string]any)
|
||||
if !ok {
|
||||
return c.error(group.UserError(
|
||||
return c.error(hall.UserError(
|
||||
"bad value in clearchat",
|
||||
))
|
||||
}
|
||||
id, _ = value["id"].(string)
|
||||
userId, _ = value["userId"].(string)
|
||||
if userId == "" && id != "" {
|
||||
return c.error(group.UserError(
|
||||
return c.error(hall.UserError(
|
||||
"bad value in clearchat",
|
||||
))
|
||||
}
|
||||
@@ -1674,7 +1674,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
}
|
||||
case "lock", "unlock":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
message := ""
|
||||
v, ok := m.Value.(string)
|
||||
@@ -1684,17 +1684,17 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
g.SetLocked(m.Kind == "lock", message)
|
||||
case "record":
|
||||
if !member("record", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
for _, cc := range g.GetClients(c) {
|
||||
_, ok := cc.(*diskwriter.Client)
|
||||
if ok {
|
||||
return c.error(group.UserError("already recording"))
|
||||
return c.error(hall.UserError("already recording"))
|
||||
}
|
||||
}
|
||||
disk := diskwriter.New(g)
|
||||
_, err := group.AddClient(g.Name(), disk,
|
||||
group.ClientCredentials{
|
||||
_, err := hall.AddClient(g.Name(), disk,
|
||||
hall.ClientCredentials{
|
||||
System: true,
|
||||
},
|
||||
)
|
||||
@@ -1702,24 +1702,24 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
disk.Close()
|
||||
return c.error(err)
|
||||
}
|
||||
requestConns(disk, c.group, "")
|
||||
requestConns(disk, c.hall, "")
|
||||
case "unrecord":
|
||||
if !member("record", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
for _, cc := range g.GetClients(c) {
|
||||
disk, ok := cc.(*diskwriter.Client)
|
||||
if ok {
|
||||
disk.Close()
|
||||
group.DelClient(disk)
|
||||
hall.DelClient(disk)
|
||||
}
|
||||
}
|
||||
case "subgroups":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
s := ""
|
||||
for _, sg := range group.GetSubGroups(g.Name()) {
|
||||
for _, sg := range hall.GetSubGroups(g.Name()) {
|
||||
plural := ""
|
||||
if sg.Clients > 1 {
|
||||
plural = "s"
|
||||
@@ -1737,11 +1737,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
})
|
||||
case "setdata":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
data, ok := m.Value.(map[string]interface{})
|
||||
if !ok {
|
||||
return c.error(group.UserError(
|
||||
return c.error(hall.UserError(
|
||||
"Bad value in setdata",
|
||||
))
|
||||
}
|
||||
@@ -1773,7 +1773,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
return terror("error", "client specified token")
|
||||
}
|
||||
|
||||
if tok.Group != c.group.Name() {
|
||||
if tok.Group != c.hall.Name() {
|
||||
return terror("error", "wrong group in token")
|
||||
}
|
||||
if tok.IncludeSubgroups {
|
||||
@@ -1786,7 +1786,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
}
|
||||
|
||||
if tok.Username != nil &&
|
||||
c.group.UserExists(*tok.Username) {
|
||||
c.hall.UserExists(*tok.Username) {
|
||||
return terror("error", "that username is taken")
|
||||
}
|
||||
|
||||
@@ -1881,7 +1881,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
!member("token", c.permissions) {
|
||||
return terror("not-authorised", "not authorised")
|
||||
}
|
||||
tokens, _, err := token.List(c.group.Name())
|
||||
tokens, _, err := token.List(c.hall.Name())
|
||||
if err != nil {
|
||||
return terror("error", err.Error())
|
||||
}
|
||||
@@ -1892,37 +1892,37 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
Value: tokens,
|
||||
})
|
||||
default:
|
||||
return group.UserError("unknown group action")
|
||||
return hall.UserError("unknown group action")
|
||||
}
|
||||
case "useraction":
|
||||
g := c.group
|
||||
g := c.hall
|
||||
if g == nil {
|
||||
return c.error(group.UserError("join a group first"))
|
||||
return c.error(hall.UserError("join a group first"))
|
||||
}
|
||||
switch m.Kind {
|
||||
case "op", "unop", "present", "unpresent", "shutup", "unshutup":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
t := g.GetClient(m.Dest)
|
||||
if t == nil {
|
||||
return c.error(group.UserError("no such user"))
|
||||
return c.error(hall.UserError("no such user"))
|
||||
}
|
||||
target, ok := t.(*webClient)
|
||||
if !ok {
|
||||
return c.error(group.UserError(
|
||||
return c.error(hall.UserError(
|
||||
"this is not a real user",
|
||||
))
|
||||
}
|
||||
target.action(changePermissionsAction{m.Kind})
|
||||
case "identify":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
d := g.GetClient(m.Dest)
|
||||
if d == nil {
|
||||
return c.error(
|
||||
group.UserError("client not found"),
|
||||
hall.UserError("client not found"),
|
||||
)
|
||||
}
|
||||
value := make(map[string]any)
|
||||
@@ -1950,7 +1950,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
})
|
||||
case "kick":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
message := ""
|
||||
v, ok := m.Value.(string)
|
||||
@@ -1963,11 +1963,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
}
|
||||
case "setdata":
|
||||
if m.Dest != c.Id() {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
return c.error(hall.UserError("not authorised"))
|
||||
}
|
||||
data, ok := m.Value.(map[string]interface{})
|
||||
if !ok {
|
||||
return c.error(group.UserError(
|
||||
return c.error(hall.UserError(
|
||||
"Bad value in setdata",
|
||||
))
|
||||
}
|
||||
@@ -1985,7 +1985,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
user := c.Username()
|
||||
perms := c.Permissions()
|
||||
data = c.Data()
|
||||
go func(clients []group.Client) {
|
||||
go func(clients []hall.Client) {
|
||||
for _, cc := range clients {
|
||||
cc.PushClient(
|
||||
g.Name(), "change",
|
||||
@@ -1994,7 +1994,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
}
|
||||
}(g.GetClients(nil))
|
||||
default:
|
||||
return group.UserError("unknown user action")
|
||||
return hall.UserError("unknown user action")
|
||||
}
|
||||
case "pong":
|
||||
// nothing
|
||||
@@ -2004,7 +2004,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
})
|
||||
default:
|
||||
log.Printf("unexpected message: %v", m.Type)
|
||||
return group.ProtocolError("unexpected message")
|
||||
return hall.ProtocolError("unexpected message")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2199,7 +2199,7 @@ func (c *webClient) write(m clientMessage) error {
|
||||
}
|
||||
}
|
||||
|
||||
func broadcast(cs []group.Client, m clientMessage) error {
|
||||
func broadcast(cs []hall.Client, m clientMessage) error {
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2228,7 +2228,7 @@ func (c *webClient) close(data []byte) error {
|
||||
|
||||
func errorMessage(id string, err error) *clientMessage {
|
||||
switch e := err.(type) {
|
||||
case group.UserError:
|
||||
case hall.UserError:
|
||||
return &clientMessage{
|
||||
Type: "usermessage",
|
||||
Kind: "error",
|
||||
@@ -2236,7 +2236,7 @@ func errorMessage(id string, err error) *clientMessage {
|
||||
Privileged: true,
|
||||
Value: e.Error(),
|
||||
}
|
||||
case group.KickError:
|
||||
case hall.KickError:
|
||||
message := e.Message
|
||||
if message == "" {
|
||||
message = "you have been kicked out"
|
||||
|
||||
+12
-12
@@ -7,7 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"git.stormux.org/storm/skald/conn"
|
||||
"git.stormux.org/storm/skald/group"
|
||||
"git.stormux.org/storm/skald/hall"
|
||||
"git.stormux.org/storm/skald/sdpfrag"
|
||||
|
||||
"github.com/pion/sdp/v3"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type WhipClient struct {
|
||||
group *group.Group
|
||||
hall *hall.Hall
|
||||
addr net.Addr
|
||||
id string
|
||||
token string
|
||||
@@ -27,12 +27,12 @@ type WhipClient struct {
|
||||
etag string
|
||||
}
|
||||
|
||||
func NewWhipClient(g *group.Group, id string, token string, addr net.Addr) *WhipClient {
|
||||
return &WhipClient{group: g, id: id, token: token, addr: addr}
|
||||
func NewWhipClient(g *hall.Hall, id string, token string, addr net.Addr) *WhipClient {
|
||||
return &WhipClient{hall: g, id: id, token: token, addr: addr}
|
||||
}
|
||||
|
||||
func (c *WhipClient) Group() *group.Group {
|
||||
return c.group
|
||||
func (c *WhipClient) Hall() *hall.Hall {
|
||||
return c.hall
|
||||
}
|
||||
|
||||
func (c *WhipClient) Addr() net.Addr {
|
||||
@@ -83,12 +83,12 @@ func (c *WhipClient) SetETag(etag string) {
|
||||
c.etag = etag
|
||||
}
|
||||
|
||||
func (c *WhipClient) PushConn(g *group.Group, id string, conn conn.Up, tracks []conn.UpTrack, replace string) error {
|
||||
func (c *WhipClient) PushConn(g *hall.Hall, id string, conn conn.Up, tracks []conn.UpTrack, replace string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WhipClient) RequestConns(target group.Client, g *group.Group, id string) error {
|
||||
if g != c.group {
|
||||
func (c *WhipClient) RequestConns(target hall.Client, g *hall.Hall, id string) error {
|
||||
if g != c.hall {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func (c *WhipClient) Kick(id string, user *string, message string) error {
|
||||
func (c *WhipClient) Close() error {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
g := c.group
|
||||
g := c.hall
|
||||
if g == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -136,8 +136,8 @@ func (c *WhipClient) Close() error {
|
||||
}
|
||||
c.connection = nil
|
||||
}
|
||||
group.DelClient(c)
|
||||
c.group = nil
|
||||
hall.DelClient(c)
|
||||
c.hall = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user