Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
89695c37
Commit
89695c37
authored
May 09, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement reception of audio only.
parent
0c7b77d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
29 deletions
+86
-29
client.go
client.go
+61
-21
group.go
group.go
+10
-8
static/sfu.html
static/sfu.html
+2
-0
static/sfu.js
static/sfu.js
+13
-0
No files found.
client.go
View file @
89695c37
...
...
@@ -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
{
...
...
group.go
View file @
89695c37
...
...
@@ -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
...
...
static/sfu.html
View file @
89695c37
...
...
@@ -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>
...
...
static/sfu.js
View file @
89695c37
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment