mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Make the requested field of client requests into a dictionary.
This commit is contained in:
parent
b265aacd32
commit
037f002a29
3 changed files with 55 additions and 13 deletions
60
client.go
60
client.go
|
@ -91,6 +91,53 @@ func isWSNormalError(err error) bool {
|
||||||
websocket.CloseGoingAway)
|
websocket.CloseGoingAway)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type rateMap map[string]uint32
|
||||||
|
|
||||||
|
func (v *rateMap) UnmarshalJSON(b []byte) error {
|
||||||
|
var m map[string]interface{}
|
||||||
|
|
||||||
|
err := json.Unmarshal(b, &m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
n := make(map[string]uint32, len(m))
|
||||||
|
for k, w := range m {
|
||||||
|
switch w := w.(type) {
|
||||||
|
case bool:
|
||||||
|
if w {
|
||||||
|
n[k] = ^uint32(0)
|
||||||
|
} else {
|
||||||
|
n[k] = 0
|
||||||
|
}
|
||||||
|
case float64:
|
||||||
|
if w < 0 || w >= float64(^uint32(0)) {
|
||||||
|
return errors.New("overflow")
|
||||||
|
}
|
||||||
|
n[k] = uint32(w)
|
||||||
|
default:
|
||||||
|
return errors.New("unexpected type in JSON map")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*v = n
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v rateMap) MarshalJSON() ([]byte, error) {
|
||||||
|
m := make(map[string]interface{}, len(v))
|
||||||
|
for k, w := range v {
|
||||||
|
switch w {
|
||||||
|
case 0:
|
||||||
|
m[k] = false
|
||||||
|
case ^uint32(0):
|
||||||
|
m[k] = true
|
||||||
|
default:
|
||||||
|
m[k] = w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return json.Marshal(m)
|
||||||
|
}
|
||||||
|
|
||||||
type clientMessage struct {
|
type clientMessage struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Id string `json:"id,omitempty"`
|
Id string `json:"id,omitempty"`
|
||||||
|
@ -105,7 +152,7 @@ type clientMessage struct {
|
||||||
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
||||||
Labels map[string]string `json:"labels,omitempty"`
|
Labels map[string]string `json:"labels,omitempty"`
|
||||||
Del bool `json:"del,omitempty"`
|
Del bool `json:"del,omitempty"`
|
||||||
Request []string `json:"request,omitempty"`
|
Request rateMap `json:"request,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type closeMessage struct {
|
type closeMessage struct {
|
||||||
|
@ -927,7 +974,7 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
|
||||||
return pc.AddICECandidate(*candidate)
|
return pc.AddICECandidate(*candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) setRequested(requested []string) error {
|
func (c *client) setRequested(requested map[string]uint32) error {
|
||||||
if c.down != nil {
|
if c.down != nil {
|
||||||
for id := range c.down {
|
for id := range c.down {
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
|
@ -951,12 +998,7 @@ func (c *client) setRequested(requested []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) isRequested(label string) bool {
|
func (c *client) isRequested(label string) bool {
|
||||||
for _, r := range c.requested {
|
return c.requested[label] != 0
|
||||||
if label == r {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDownConnTracks(c *client, remote *upConnection, tracks []*upTrack) (*downConnection, error) {
|
func addDownConnTracks(c *client, remote *upConnection, tracks []*upTrack) (*downConnection, error) {
|
||||||
|
@ -1002,7 +1044,7 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
go clientReader(conn, read, c.done)
|
go clientReader(conn, read, c.done)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
c.setRequested([]string{})
|
c.setRequested(map[string]uint32{})
|
||||||
if c.up != nil {
|
if c.up != nil {
|
||||||
for id := range c.up {
|
for id := range c.up {
|
||||||
delUpConn(c, id)
|
delUpConn(c, id)
|
||||||
|
|
2
group.go
2
group.go
|
@ -171,7 +171,7 @@ type client struct {
|
||||||
id string
|
id string
|
||||||
username string
|
username string
|
||||||
permissions userPermission
|
permissions userPermission
|
||||||
requested []string
|
requested map[string]uint32
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
writeCh chan interface{}
|
writeCh chan interface{}
|
||||||
writerDone chan struct{}
|
writerDone chan struct{}
|
||||||
|
|
|
@ -563,13 +563,13 @@ function sendRequest(value) {
|
||||||
let request = [];
|
let request = [];
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
request = ['audio'];
|
request = {audio: true};
|
||||||
break;
|
break;
|
||||||
case 'screenshare':
|
case 'screenshare':
|
||||||
request = ['audio', 'screenshare'];
|
request = {audio: true, screenshare: true};
|
||||||
break;
|
break;
|
||||||
case 'everything':
|
case 'everything':
|
||||||
request = ['audio', 'screenshare', 'video'];
|
request = {audio: true, screenshare: true, video: true};
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error(`Uknown value ${value} in sendRequest`);
|
console.error(`Uknown value ${value} in sendRequest`);
|
||||||
|
|
Loading…
Reference in a new issue