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
eed3d2af
Commit
eed3d2af
authored
Apr 26, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display upstream throughput.
parent
e19d704a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
2 deletions
+86
-2
static/sfu.js
static/sfu.js
+86
-2
No files found.
static/sfu.js
View file @
eed3d2af
...
...
@@ -41,9 +41,19 @@ function Connection(id, pc) {
this
.
pc
=
pc
;
this
.
stream
=
null
;
this
.
iceCandidates
=
[];
this
.
timers
=
[];
this
.
audioStats
=
{};
this
.
videoStats
=
{};
}
Connection
.
prototype
.
setInterval
=
function
(
f
,
t
)
{
this
.
timers
.
push
(
setInterval
(
f
,
t
));
}
Connection
.
prototype
.
close
=
function
()
{
while
(
this
.
timers
.
length
>
0
)
clearInterval
(
this
.
timers
.
pop
());
this
.
pc
.
close
();
send
({
type
:
'
close
'
,
...
...
@@ -111,6 +121,68 @@ document.getElementById('sharebox').onchange = function(e) {
setShareMedia
();
}
async
function
updateStats
(
conn
,
sender
)
{
let
stats
;
if
(
!
sender
.
track
)
return
;
if
(
sender
.
track
.
kind
===
'
audio
'
)
stats
=
conn
.
audioStats
;
else
if
(
sender
.
track
.
kind
===
'
video
'
)
stats
=
conn
.
videoStats
;
else
return
;
let
report
;
try
{
report
=
await
sender
.
getStats
();
}
catch
(
e
)
{
delete
(
stats
.
rate
);
delete
(
stats
.
timestamp
);
delete
(
stats
.
bytesSent
);
return
}
for
(
let
r
of
report
.
values
())
{
if
(
r
.
type
!==
'
outbound-rtp
'
)
continue
;
if
(
stats
.
timestamp
)
{
stats
.
rate
=
((
r
.
bytesSent
-
stats
.
bytesSent
)
-
(
r
.
timestamp
-
stats
.
timestamp
))
*
8
;
}
else
{
delete
(
stats
.
rate
);
}
stats
.
timestamp
=
r
.
timestamp
;
stats
.
bytesSent
=
r
.
bytesSent
;
return
;
}
}
function
displayStats
(
id
)
{
let
conn
=
up
[
id
];
if
(
!
conn
.
audioStats
.
rate
&&
!
conn
.
videoStats
.
rate
)
{
setLabel
(
id
);
return
;
}
let
a
=
conn
.
audioStats
.
rate
;
let
v
=
conn
.
videoStats
.
rate
;
let
text
=
''
;
if
(
a
)
text
=
text
+
Math
.
round
(
a
/
1000
)
+
'
kbps
'
;
if
(
a
&&
v
)
text
=
text
+
'
+
'
;
if
(
v
)
text
=
text
+
Math
.
round
(
v
/
1000
)
+
'
kbps
'
;
if
(
text
)
setLabel
(
id
,
text
);
else
setLabel
(
id
);
}
let
localMediaId
=
null
;
async
function
setLocalMedia
()
{
...
...
@@ -142,8 +214,14 @@ async function setLocalMedia() {
let
c
=
up
[
localMediaId
];
c
.
stream
=
stream
;
stream
.
getTracks
().
forEach
(
t
=>
{
c
.
pc
.
addTrack
(
t
,
stream
);
let
sender
=
c
.
pc
.
addTrack
(
t
,
stream
);
c
.
setInterval
(()
=>
{
updateStats
(
c
,
sender
);
},
2000
);
});
c
.
setInterval
(()
=>
{
displayStats
(
localMediaId
);
},
2500
);
await
setMedia
(
localMediaId
);
}
}
...
...
@@ -178,12 +256,18 @@ async function setShareMedia() {
let
c
=
up
[
shareMediaId
];
c
.
stream
=
stream
;
stream
.
getTracks
().
forEach
(
t
=>
{
c
.
pc
.
addTrack
(
t
,
stream
);
let
sender
=
c
.
pc
.
addTrack
(
t
,
stream
);
t
.
onended
=
e
=>
{
document
.
getElementById
(
'
sharebox
'
).
checked
=
false
;
setShareMedia
();
}
c
.
setInterval
(()
=>
{
updateStats
(
c
,
sender
);
},
2000
);
});
c
.
setInterval
(()
=>
{
displayStats
(
shareMediaId
);
},
2500
);
await
setMedia
(
shareMediaId
);
}
}
...
...
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