1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Implement reception of audio only.

This commit is contained in:
Juliusz Chroboczek 2020-05-09 19:39:34 +02:00
parent 0c7b77d919
commit 89695c3713
4 changed files with 86 additions and 29 deletions

View file

@ -105,6 +105,7 @@ type clientMessage struct {
Answer *webrtc.SessionDescription `json:"answer,omitempty"`
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
Del bool `json:"del,omitempty"`
Request []string `json:"request,omitempty"`
}
type closeMessage struct {
@ -934,21 +935,48 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
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 {
read := make(chan interface{}, 1)
go clientReader(conn, read, c.done)
defer func() {
if c.down != nil {
for id := range c.down {
c.write(clientMessage{
Type: "close",
Id: id,
})
delDownConn(c, id)
}
}
c.setRequested(false, false)
if c.up != nil {
for id := range c.up {
delUpConn(c, id)
@ -956,17 +984,11 @@ func clientLoop(c *client, conn *websocket.Conn) error {
}
}()
g := c.group
c.write(clientMessage{
Type: "permissions",
Permissions: c.permissions,
})
for _, cc := range g.getClients(c) {
cc.action(pushTracksAction{c})
}
h := c.group.getChatHistory()
for _, m := range h {
err := c.write(clientMessage{
@ -1007,14 +1029,19 @@ func clientLoop(c *client, conn *websocket.Conn) error {
case a := <-c.actionCh:
switch a := a.(type) {
case addTrackAction:
down, _, err :=
addDownTrack(
var down *downConnection
var err error
if c.requested(a.track.track.Kind()) {
down, _, err = addDownTrack(
c, a.remote.id, a.track,
a.remote)
if err != nil {
return err
if err != nil {
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)
if err != nil {
return err
@ -1106,6 +1133,19 @@ func clientLoop(c *client, conn *websocket.Conn) error {
func handleClientMessage(c *client, m clientMessage) error {
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":
if !c.permissions.Present {
c.write(clientMessage{

View file

@ -150,14 +150,16 @@ type downConnection struct {
}
type client struct {
group *group
id string
username string
permissions userPermission
done chan struct{}
writeCh chan interface{}
writerDone chan struct{}
actionCh chan interface{}
group *group
id string
username string
permissions userPermission
requestedAudio bool
requestedVideo bool
done chan struct{}
writeCh chan interface{}
writerDone chan struct{}
actionCh chan interface{}
mu sync.Mutex
down map[string]*downConnection

View file

@ -47,6 +47,8 @@
<label for="sharebox">Share screen:</label>
<input id="sharebox" type="checkbox"/ disabled>
<label for="requestbox">Receive video:</label>
<input id="requestbox" type="checkbox" checked>
</div>
</div>

View file

@ -141,6 +141,11 @@ document.getElementById('sharebox').onchange = function(e) {
setShareMedia(this.checked);
}
document.getElementById('requestbox').onchange = function(e) {
e.preventDefault();
sendRequest(this.checked);
}
async function updateStats(conn, sender) {
let stats;
if(!sender.track)
@ -481,6 +486,7 @@ function serverConnect() {
username: up.username,
password: up.password,
});
sendRequest(document.getElementById('requestbox').checked);
resolve();
};
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) {
let c = down[id];
if(!c) {