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
5c97e739
Commit
5c97e739
authored
Sep 11, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement activity detection.
parent
d35f5999
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
23 deletions
+127
-23
static/protocol.js
static/protocol.js
+48
-18
static/sfu.css
static/sfu.css
+10
-0
static/sfu.html
static/sfu.html
+4
-0
static/sfu.js
static/sfu.js
+65
-5
No files found.
static/protocol.js
View file @
5c97e739
...
...
@@ -919,29 +919,59 @@ Stream.prototype.updateStats = async function() {
let
transceivers
=
c
.
pc
.
getTransceivers
();
for
(
let
i
=
0
;
i
<
transceivers
.
length
;
i
++
)
{
let
t
=
transceivers
[
i
];
let
tid
=
t
.
sender
.
track
&&
t
.
sender
.
track
.
id
;
if
(
!
tid
)
continue
;
let
stid
=
t
.
sender
.
track
&&
t
.
sender
.
track
.
id
;
let
rtid
=
t
.
receiver
.
track
&&
t
.
receiver
.
track
.
id
;
let
report
;
try
{
report
=
await
t
.
sender
.
getStats
();
}
catch
(
e
)
{
continue
;
let
report
=
null
;
if
(
stid
)
{
try
{
report
=
await
t
.
sender
.
getStats
();
}
catch
(
e
)
{
}
}
stats
[
tid
]
=
{};
if
(
report
)
{
for
(
let
r
of
report
.
values
())
{
if
(
stid
&&
r
.
type
===
'
outbound-rtp
'
)
{
if
(
!
(
'
bytesSent
'
in
r
))
continue
;
if
(
!
stats
[
stid
])
stats
[
stid
]
=
{};
stats
[
stid
][
r
.
type
]
=
{};
stats
[
stid
][
r
.
type
].
timestamp
=
r
.
timestamp
;
stats
[
stid
][
r
.
type
].
bytesSent
=
r
.
bytesSent
;
if
(
old
[
stid
]
&&
old
[
stid
][
r
.
type
])
stats
[
stid
][
r
.
type
].
rate
=
((
r
.
bytesSent
-
old
[
stid
][
r
.
type
].
bytesSent
)
*
1000
/
(
r
.
timestamp
-
old
[
stid
][
r
.
type
].
timestamp
))
*
8
;
}
}
}
for
(
let
r
of
report
.
values
())
{
if
(
r
.
type
!==
'
outbound-rtp
'
)
continue
;
report
=
null
;
if
(
rtid
)
{
try
{
report
=
await
t
.
receiver
.
getStats
();
}
catch
(
e
)
{
console
.
error
(
e
);
}
}
stats
[
tid
].
timestamp
=
r
.
timestamp
;
stats
[
tid
].
bytesSent
=
r
.
bytesSent
;
if
(
old
[
tid
]
&&
old
[
tid
].
timestamp
)
{
stats
[
tid
].
rate
=
((
r
.
bytesSent
-
old
[
tid
].
bytesSent
)
*
1000
/
(
r
.
timestamp
-
old
[
tid
].
timestamp
))
*
8
;
if
(
report
)
{
for
(
let
r
of
report
.
values
())
{
if
(
rtid
&&
r
.
type
===
'
track
'
)
{
if
(
!
(
'
totalAudioEnergy
'
in
r
))
continue
;
if
(
!
stats
[
rtid
])
stats
[
rtid
]
=
{};
stats
[
rtid
][
r
.
type
]
=
{};
stats
[
rtid
][
r
.
type
].
timestamp
=
r
.
timestamp
;
stats
[
rtid
][
r
.
type
].
totalAudioEnergy
=
r
.
totalAudioEnergy
;
if
(
old
[
rtid
]
&&
old
[
rtid
][
r
.
type
])
stats
[
rtid
][
r
.
type
].
audioEnergy
=
(
r
.
totalAudioEnergy
-
old
[
rtid
][
r
.
type
].
totalAudioEnergy
)
*
1000
/
(
r
.
timestamp
-
old
[
rtid
][
r
.
type
].
timestamp
);
}
}
}
}
...
...
static/sfu.css
View file @
5c97e739
...
...
@@ -610,6 +610,11 @@ h1 {
margin-top
:
auto
;
margin-bottom
:
auto
;
position
:
relative
;
border
:
2px
solid
rgba
(
0
,
0
,
0
,
0
);
}
.peer-active
{
border
:
2px
solid
#610a86
;
}
.media
{
...
...
@@ -670,6 +675,11 @@ h1 {
margin-top
:
15px
;
}
.sidenav
form
{
display
:
block
;
margin-top
:
15px
;
}
.sidenav-header
h2
{
color
:
#fff
;
padding
:
10px
;
...
...
static/sfu.html
View file @
5c97e739
...
...
@@ -172,6 +172,10 @@
<option
value=
"screenshare"
>
screen share
</option>
<option
value=
"everything"
selected
>
everything
</option>
</select>
<form>
<input
id=
"activitybox"
type=
"checkbox"
>
Activity detection
</input>
</form>
</div>
</div>
...
...
static/sfu.js
View file @
5c97e739
...
...
@@ -142,6 +142,9 @@ function gotDownStream(c) {
c
.
onstatus
=
function
(
status
)
{
setMediaStatus
(
c
);
}
c
.
onstats
=
gotDownStats
;
if
(
document
.
getElementById
(
'
activitybox
'
).
value
)
c
.
setStatsInterval
(
activityDetectionInterval
);
}
// Store current browser viewport height in css variable
...
...
@@ -278,7 +281,23 @@ document.getElementById('requestselect').onchange = function(e) {
serverConnection
.
request
(
this
.
value
);
};
function
displayStats
(
stats
)
{
const
activityDetectionInterval
=
100
;
const
activityDetectionPeriod
=
700
;
const
activityDetectionThreshold
=
0.2
;
document
.
getElementById
(
'
activitybox
'
).
onchange
=
function
(
e
)
{
for
(
let
id
in
serverConnection
.
down
)
{
let
c
=
serverConnection
.
down
[
id
];
if
(
this
.
value
)
c
.
setStatsInterval
(
activityDetectionInterval
);
else
{
setActive
(
c
,
false
);
c
.
setStatsInterval
(
0
);
}
}
}
function
gotUpStats
(
stats
)
{
let
c
=
this
;
let
text
=
''
;
...
...
@@ -286,16 +305,57 @@ function displayStats(stats) {
c
.
pc
.
getSenders
().
forEach
(
s
=>
{
let
tid
=
s
.
track
&&
s
.
track
.
id
;
let
stats
=
tid
&&
c
.
stats
[
tid
];
if
(
stats
&&
stats
.
rate
>
0
)
{
let
rate
=
stats
&&
stats
[
'
outbound-rtp
'
]
&&
stats
[
'
outbound-rtp
'
].
rate
;
if
(
typeof
rate
===
'
number
'
)
{
if
(
text
)
text
=
text
+
'
+
'
;
text
=
text
+
Math
.
round
(
stats
.
rate
/
1000
)
+
'
kbps
'
;
text
=
text
+
Math
.
round
(
rate
/
1000
)
+
'
kbps
'
;
}
});
setLabel
(
c
,
text
);
}
/**
* @param {Stream} c
* @param {boolean} value
*/
function
setActive
(
c
,
value
)
{
let
peer
=
document
.
getElementById
(
'
peer-
'
+
c
.
id
);
if
(
value
)
peer
.
classList
.
add
(
'
peer-active
'
);
else
peer
.
classList
.
remove
(
'
peer-active
'
);
}
function
gotDownStats
(
stats
)
{
if
(
!
document
.
getElementById
(
'
activitybox
'
).
value
)
return
;
let
c
=
this
;
let
maxEnergy
=
0
;
c
.
pc
.
getReceivers
().
forEach
(
r
=>
{
let
tid
=
r
.
track
&&
r
.
track
.
id
;
let
s
=
tid
&&
stats
[
tid
];
let
energy
=
s
&&
s
[
'
track
'
]
&&
s
[
'
track
'
].
audioEnergy
;
if
(
typeof
energy
===
'
number
'
)
maxEnergy
=
Math
.
max
(
maxEnergy
,
energy
);
});
// totalAudioEnergy is defined as the integral of the square of the
// volume, so square the threshold.
if
(
maxEnergy
>
activityDetectionThreshold
*
activityDetectionThreshold
)
{
c
.
userdata
.
lastVoiceActivity
=
Date
.
now
();
setActive
(
c
,
true
);
}
else
{
let
last
=
c
.
userdata
.
lastVoiceActivity
;
if
(
!
last
||
Date
.
now
()
-
last
>
activityDetectionPeriod
)
setActive
(
c
,
false
);
}
}
function
mapMediaOption
(
value
)
{
console
.
assert
(
typeof
(
value
)
===
'
string
'
);
switch
(
value
)
{
...
...
@@ -457,7 +517,7 @@ async function addLocalMedia(id) {
let
sender
=
c
.
pc
.
addTrack
(
t
,
stream
);
});
c
.
onstats
=
display
Stats
;
c
.
onstats
=
gotUp
Stats
;
c
.
setStatsInterval
(
2000
);
await
setMedia
(
c
,
true
);
setButtonsVisibility
();
...
...
@@ -486,7 +546,7 @@ async function addShareMedia(setup) {
};
c
.
labels
[
t
.
id
]
=
'
screenshare
'
;
});
c
.
onstats
=
display
Stats
;
c
.
onstats
=
gotUp
Stats
;
c
.
setStatsInterval
(
2000
);
await
setMedia
(
c
,
true
);
setButtonsVisibility
()
...
...
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