FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rtcstats/example/example.js at main · rtcstats/rtcstats · GitHub
rtcstats
/
rtcstats
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
41
Code
Issues
3
Pull requests
6
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
rtcstats
/
example
/
example.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (63 loc) · 2.48 KB
Breadcrumbs
rtcstats
/
example
/
example.js
Copy path
File metadata and controls
70 lines (63 loc) · 2.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import
fs
from
'node:fs'
;
import
path
from
'node:path'
;
import
config
from
'config'
;
import
opener
from
'opener'
;
import
{
RTCStatsServer
}
from
'@rtcstats/rtcstats-server/rtcstats-server.js'
;
import
{
generateAuthToken
,
setupDirectory
}
from
'@rtcstats/rtcstats-server/utils.js'
;
class
RTCStatsAndHttpServer
extends
RTCStatsServer
{
// Override HTTP behavior.
handleHttpRequest
(
request
,
response
)
{
if
(
request
.
url
.
startsWith
(
'/packages/rtcstats-'
)
&&
request
.
url
.
endsWith
(
'.js'
)
)
{
fs
.
readFile
(
'..'
+
request
.
url
,
(
error
,
content
)
=>
{
response
.
writeHead
(
200
,
{
'Content-Type'
:
'text/javascript'
}
)
;
response
.
end
(
content
,
'utf-8'
)
;
}
)
;
}
else
if
(
request
.
url
.
startsWith
(
'/?'
)
)
{
fs
.
readFile
(
'./index.html'
,
(
error
,
content
)
=>
{
response
.
writeHead
(
200
,
{
'Content-Type'
:
'text/html'
}
)
;
response
.
end
(
content
,
'utf-8'
)
;
}
)
;
}
else
{
return
super
.
handleHttpRequest
(
request
,
response
)
;
}
}
// Override storage behavior.
createStorage
(
storageConfig
)
{
return
{
put
:
async
(
key
,
filename
)
=>
{
console
.
log
(
'RTCStats dump generated in '
+
path
.
join
(
process
.
cwd
(
)
,
filename
)
)
;
}
,
}
;
}
// Override database behavior.
createDatabase
(
databaseConfig
)
{
return
{
insert
:
(
startTime
,
authData
)
=>
{
return
'example-id'
;
}
,
update
:
(
)
=>
{
}
}
;
}
}
// Setup up work and upload directories.
setupDirectory
(
config
,
config
.
server
.
workDirectory
)
;
setupDirectory
(
config
,
config
.
server
.
uploadDirectory
)
;
// Since we do not upload, do not delete the files after not uploading them.
config
.
server
.
deleteAfterUpload
=
false
;
config
.
authorization
.
jwtSecret
=
'secret'
;
const
server
=
new
RTCStatsAndHttpServer
(
config
)
;
server
.
listen
(
)
;
// This section shows JWT-based authorization with a shared secret.
// It generates a token with an `rtcStats` object than can be used for
// authenticated user and conference (or session) metadata.
// This is passed to the sample page which passes the token during
// the websocket connection.
generateAuthToken
(
{
user
:
'example'
,
session
:
'unique-id'
,
conference
:
'krankygeek'
,
}
,
config
.
authorization
.
jwtSecret
)
.
then
(
(
token
)
=>
{
// Open the browser at the indicated url.
opener
(
'http://localhost:'
+
config
.
server
.
httpPort
+
'/?rtcstats-token='
+
token
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL