mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Implement reception of audio only.
This commit is contained in:
parent
0c7b77d919
commit
89695c3713
4 changed files with 86 additions and 29 deletions
82
client.go
82
client.go
|
@ -105,6 +105,7 @@ type clientMessage struct {
|
||||||
Answer *webrtc.SessionDescription `json:"answer,omitempty"`
|
Answer *webrtc.SessionDescription `json:"answer,omitempty"`
|
||||||
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
||||||
Del bool `json:"del,omitempty"`
|
Del bool `json:"del,omitempty"`
|
||||||
|
Request []string `json:"request,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type closeMessage struct {
|
type closeMessage struct {
|
||||||
|
@ -934,21 +935,48 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
|
||||||
return pc.AddICECandidate(*candidate)
|
return pc.AddICECandidate(*candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *client) setRequested(audio, video bool) error {
|
||||||
|
if audio == c.requestedAudio && video == c.requestedVideo {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.down != nil {
|
||||||
|
for id := range c.down {
|
||||||
|
c.write(clientMessage{
|
||||||
|
Type: "close",
|
||||||
|
Id: id,
|
||||||
|
})
|
||||||
|
delDownConn(c, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.requestedAudio = audio
|
||||||
|
c.requestedVideo = video
|
||||||
|
|
||||||
|
for _, cc := range c.group.getClients(c) {
|
||||||
|
cc.action(pushTracksAction{c})
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *client) requested(kind webrtc.RTPCodecType) bool {
|
||||||
|
switch kind {
|
||||||
|
case webrtc.RTPCodecTypeAudio:
|
||||||
|
return c.requestedAudio
|
||||||
|
case webrtc.RTPCodecTypeVideo:
|
||||||
|
return c.requestedVideo
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func clientLoop(c *client, conn *websocket.Conn) error {
|
func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
read := make(chan interface{}, 1)
|
read := make(chan interface{}, 1)
|
||||||
go clientReader(conn, read, c.done)
|
go clientReader(conn, read, c.done)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if c.down != nil {
|
c.setRequested(false, false)
|
||||||
for id := range c.down {
|
|
||||||
c.write(clientMessage{
|
|
||||||
Type: "close",
|
|
||||||
Id: id,
|
|
||||||
})
|
|
||||||
delDownConn(c, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.up != nil {
|
if c.up != nil {
|
||||||
for id := range c.up {
|
for id := range c.up {
|
||||||
delUpConn(c, id)
|
delUpConn(c, id)
|
||||||
|
@ -956,17 +984,11 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
g := c.group
|
|
||||||
|
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
Type: "permissions",
|
Type: "permissions",
|
||||||
Permissions: c.permissions,
|
Permissions: c.permissions,
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, cc := range g.getClients(c) {
|
|
||||||
cc.action(pushTracksAction{c})
|
|
||||||
}
|
|
||||||
|
|
||||||
h := c.group.getChatHistory()
|
h := c.group.getChatHistory()
|
||||||
for _, m := range h {
|
for _, m := range h {
|
||||||
err := c.write(clientMessage{
|
err := c.write(clientMessage{
|
||||||
|
@ -1007,14 +1029,19 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
case a := <-c.actionCh:
|
case a := <-c.actionCh:
|
||||||
switch a := a.(type) {
|
switch a := a.(type) {
|
||||||
case addTrackAction:
|
case addTrackAction:
|
||||||
down, _, err :=
|
var down *downConnection
|
||||||
addDownTrack(
|
var err error
|
||||||
|
if c.requested(a.track.track.Kind()) {
|
||||||
|
down, _, err = addDownTrack(
|
||||||
c, a.remote.id, a.track,
|
c, a.remote.id, a.track,
|
||||||
a.remote)
|
a.remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
down = getDownConn(c, a.remote.id)
|
||||||
}
|
}
|
||||||
if a.done {
|
if a.done && down != nil {
|
||||||
err = negotiate(c, a.remote.id, down.pc)
|
err = negotiate(c, a.remote.id, down.pc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1106,6 +1133,19 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
|
|
||||||
func handleClientMessage(c *client, m clientMessage) error {
|
func handleClientMessage(c *client, m clientMessage) error {
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
|
case "request":
|
||||||
|
var audio, video bool
|
||||||
|
for _, s := range m.Request {
|
||||||
|
switch(s) {
|
||||||
|
case "audio": audio = true
|
||||||
|
case "video": video = true
|
||||||
|
default: log.Printf("Unknown request %v", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := c.setRequested(audio, video)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case "offer":
|
case "offer":
|
||||||
if !c.permissions.Present {
|
if !c.permissions.Present {
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
|
|
18
group.go
18
group.go
|
@ -150,14 +150,16 @@ type downConnection struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
group *group
|
group *group
|
||||||
id string
|
id string
|
||||||
username string
|
username string
|
||||||
permissions userPermission
|
permissions userPermission
|
||||||
done chan struct{}
|
requestedAudio bool
|
||||||
writeCh chan interface{}
|
requestedVideo bool
|
||||||
writerDone chan struct{}
|
done chan struct{}
|
||||||
actionCh chan interface{}
|
writeCh chan interface{}
|
||||||
|
writerDone chan struct{}
|
||||||
|
actionCh chan interface{}
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
down map[string]*downConnection
|
down map[string]*downConnection
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
<label for="sharebox">Share screen:</label>
|
<label for="sharebox">Share screen:</label>
|
||||||
<input id="sharebox" type="checkbox"/ disabled>
|
<input id="sharebox" type="checkbox"/ disabled>
|
||||||
|
|
||||||
|
<label for="requestbox">Receive video:</label>
|
||||||
|
<input id="requestbox" type="checkbox" checked>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,11 @@ document.getElementById('sharebox').onchange = function(e) {
|
||||||
setShareMedia(this.checked);
|
setShareMedia(this.checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById('requestbox').onchange = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
sendRequest(this.checked);
|
||||||
|
}
|
||||||
|
|
||||||
async function updateStats(conn, sender) {
|
async function updateStats(conn, sender) {
|
||||||
let stats;
|
let stats;
|
||||||
if(!sender.track)
|
if(!sender.track)
|
||||||
|
@ -481,6 +486,7 @@ function serverConnect() {
|
||||||
username: up.username,
|
username: up.username,
|
||||||
password: up.password,
|
password: up.password,
|
||||||
});
|
});
|
||||||
|
sendRequest(document.getElementById('requestbox').checked);
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
socket.onclose = function(e) {
|
socket.onclose = function(e) {
|
||||||
|
@ -551,6 +557,13 @@ function serverConnect() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendRequest(video) {
|
||||||
|
send({
|
||||||
|
type: 'request',
|
||||||
|
request: video ? ['audio', 'video'] : ['audio'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function gotOffer(id, offer) {
|
async function gotOffer(id, offer) {
|
||||||
let c = down[id];
|
let c = down[id];
|
||||||
if(!c) {
|
if(!c) {
|
||||||
|
|
Loading…
Reference in a new issue