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
c6087233
Commit
c6087233
authored
Sep 13, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move group and client to their own package.
parent
d9cf32ed
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
258 additions
and
226 deletions
+258
-226
disk.go
disk.go
+11
-10
group/client.go
group/client.go
+29
-0
group/group.go
group/group.go
+124
-89
rtpconn.go
rtpconn.go
+9
-8
sfu.go
sfu.go
+5
-5
stats.go
stats.go
+4
-3
webclient.go
webclient.go
+67
-104
webserver.go
webserver.go
+9
-7
No files found.
disk.go
View file @
c6087233
...
...
@@ -16,10 +16,11 @@ import (
"github.com/pion/webrtc/v3/pkg/media/samplebuilder"
"sfu/conn"
"sfu/group"
)
type
diskClient
struct
{
group
*
group
group
*
group
.
Group
id
string
mu
sync
.
Mutex
...
...
@@ -41,11 +42,11 @@ func newId() string {
return
s
}
func
NewDiskClient
(
g
*
group
)
*
diskClient
{
func
NewDiskClient
(
g
*
group
.
Group
)
*
diskClient
{
return
&
diskClient
{
group
:
g
,
id
:
newId
()}
}
func
(
client
*
diskClient
)
Group
()
*
group
{
func
(
client
*
diskClient
)
Group
()
*
group
.
Group
{
return
client
.
group
}
...
...
@@ -53,15 +54,15 @@ func (client *diskClient) Id() string {
return
client
.
id
}
func
(
client
*
diskClient
)
Credentials
()
c
lientCredentials
{
return
c
lientCredentials
{
"RECORDING"
,
""
}
func
(
client
*
diskClient
)
Credentials
()
group
.
C
lientCredentials
{
return
group
.
C
lientCredentials
{
"RECORDING"
,
""
}
}
func
(
client
*
diskClient
)
SetPermissions
(
perms
c
lientPermissions
)
{
func
(
client
*
diskClient
)
SetPermissions
(
perms
group
.
C
lientPermissions
)
{
return
}
func
(
client
*
diskClient
)
p
ushClient
(
id
,
username
string
,
add
bool
)
error
{
func
(
client
*
diskClient
)
P
ushClient
(
id
,
username
string
,
add
bool
)
error
{
return
nil
}
...
...
@@ -79,11 +80,11 @@ func (client *diskClient) Close() error {
func
(
client
*
diskClient
)
kick
(
message
string
)
error
{
err
:=
client
.
Close
()
d
elClient
(
client
)
group
.
D
elClient
(
client
)
return
err
}
func
(
client
*
diskClient
)
p
ushConn
(
id
string
,
up
conn
.
Up
,
tracks
[]
conn
.
UpTrack
,
label
string
)
error
{
func
(
client
*
diskClient
)
P
ushConn
(
id
string
,
up
conn
.
Up
,
tracks
[]
conn
.
UpTrack
,
label
string
)
error
{
client
.
mu
.
Lock
()
defer
client
.
mu
.
Unlock
()
...
...
@@ -101,7 +102,7 @@ func (client *diskClient) pushConn(id string, up conn.Up, tracks []conn.UpTrack,
return
nil
}
directory
:=
filepath
.
Join
(
recordingsDir
,
client
.
group
.
name
)
directory
:=
filepath
.
Join
(
recordingsDir
,
client
.
group
.
Name
()
)
err
:=
os
.
MkdirAll
(
directory
,
0700
)
if
err
!=
nil
{
return
err
...
...
client.go
→
group/
client.go
View file @
c6087233
package
main
package
group
import
(
"sfu/conn"
)
type
c
lientCredentials
struct
{
type
C
lientCredentials
struct
{
Username
string
`json:"username,omitempty"`
Password
string
`json:"password,omitempty"`
}
type
c
lientPermissions
struct
{
type
C
lientPermissions
struct
{
Op
bool
`json:"op,omitempty"`
Present
bool
`json:"present,omitempty"`
Record
bool
`json:"record,omitempty"`
}
type
c
lient
interface
{
Group
()
*
g
roup
type
C
lient
interface
{
Group
()
*
G
roup
Id
()
string
Credentials
()
c
lientCredentials
SetPermissions
(
c
lientPermissions
)
p
ushConn
(
id
string
,
conn
conn
.
Up
,
tracks
[]
conn
.
UpTrack
,
label
string
)
error
p
ushClient
(
id
,
username
string
,
add
bool
)
error
Credentials
()
C
lientCredentials
SetPermissions
(
C
lientPermissions
)
P
ushConn
(
id
string
,
conn
conn
.
Up
,
tracks
[]
conn
.
UpTrack
,
label
string
)
error
P
ushClient
(
id
,
username
string
,
add
bool
)
error
}
type
k
ickable
interface
{
k
ick
(
message
string
)
error
type
K
ickable
interface
{
K
ick
(
message
string
)
error
}
group.go
→
group
/group
.go
View file @
c6087233
This diff is collapsed.
Click to expand it.
rtpconn.go
View file @
c6087233
...
...
@@ -20,6 +20,7 @@ import (
"sfu/conn"
"sfu/estimator"
"sfu/group"
"sfu/jitter"
"sfu/packetcache"
"sfu/rtptime"
...
...
@@ -110,8 +111,8 @@ type rtpDownConnection struct {
iceCandidates
[]
*
webrtc
.
ICECandidateInit
}
func
newDownConn
(
c
c
lient
,
id
string
,
remote
conn
.
Up
)
(
*
rtpDownConnection
,
error
)
{
pc
,
err
:=
c
.
Group
()
.
API
()
.
NewPeerConnection
(
i
ceConfiguration
())
func
newDownConn
(
c
group
.
C
lient
,
id
string
,
remote
conn
.
Up
)
(
*
rtpDownConnection
,
error
)
{
pc
,
err
:=
c
.
Group
()
.
API
()
.
NewPeerConnection
(
group
.
I
ceConfiguration
())
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -371,8 +372,8 @@ func (up *rtpUpConnection) complete() bool {
return
true
}
func
newUpConn
(
c
c
lient
,
id
string
)
(
*
rtpUpConnection
,
error
)
{
pc
,
err
:=
c
.
Group
()
.
API
()
.
NewPeerConnection
(
i
ceConfiguration
())
func
newUpConn
(
c
group
.
C
lient
,
id
string
)
(
*
rtpUpConnection
,
error
)
{
pc
,
err
:=
c
.
Group
()
.
API
()
.
NewPeerConnection
(
group
.
I
ceConfiguration
())
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -448,9 +449,9 @@ func newUpConn(c client, id string) (*rtpUpConnection, error) {
up
.
mu
.
Unlock
()
if
complete
{
clients
:=
c
.
Group
()
.
g
etClients
(
c
)
clients
:=
c
.
Group
()
.
G
etClients
(
c
)
for
_
,
cc
:=
range
clients
{
cc
.
p
ushConn
(
up
.
id
,
up
,
tracks
,
up
.
label
)
cc
.
P
ushConn
(
up
.
id
,
up
,
tracks
,
up
.
label
)
}
go
rtcpUpSender
(
up
)
}
...
...
@@ -750,8 +751,8 @@ func sendUpRTCP(conn *rtpUpConnection) error {
rate
=
r
}
}
if
rate
<
m
inBitrate
{
rate
=
m
inBitrate
if
rate
<
group
.
M
inBitrate
{
rate
=
group
.
M
inBitrate
}
var
ssrcs
[]
uint32
...
...
sfu.go
View file @
c6087233
...
...
@@ -14,14 +14,14 @@ import (
"runtime"
"runtime/pprof"
"syscall"
"sfu/group"
)
var
httpAddr
string
var
staticRoot
string
var
dataDir
string
var
groupsDir
string
var
recordingsDir
string
var
iceFilename
string
func
main
()
{
var
cpuprofile
,
memprofile
,
mutexprofile
string
...
...
@@ -31,7 +31,7 @@ func main() {
"web server root `directory`"
)
flag
.
StringVar
(
&
dataDir
,
"data"
,
"./data/"
,
"data `directory`"
)
flag
.
StringVar
(
&
group
sDir
,
"groups"
,
"./groups/"
,
flag
.
StringVar
(
&
group
.
Directory
,
"groups"
,
"./groups/"
,
"group description `directory`"
)
flag
.
StringVar
(
&
recordingsDir
,
"recordings"
,
"./recordings/"
,
"recordings `directory`"
)
...
...
@@ -81,9 +81,9 @@ func main() {
}()
}
i
ceFilename
=
filepath
.
Join
(
dataDir
,
"ice-servers.json"
)
group
.
I
ceFilename
=
filepath
.
Join
(
dataDir
,
"ice-servers.json"
)
go
r
eadPublicGroups
()
go
group
.
R
eadPublicGroups
()
webserver
()
terminate
:=
make
(
chan
os
.
Signal
,
1
)
...
...
stats.go
View file @
c6087233
...
...
@@ -5,6 +5,7 @@ import (
"sync/atomic"
"time"
"sfu/group"
"sfu/rtptime"
)
...
...
@@ -33,15 +34,15 @@ type trackStats struct {
}
func
getGroupStats
()
[]
groupStats
{
names
:=
g
etGroup
Names
()
names
:=
g
roup
.
Get
Names
()
gs
:=
make
([]
groupStats
,
0
,
len
(
names
))
for
_
,
name
:=
range
names
{
g
:=
g
etGroup
(
name
)
g
:=
g
roup
.
Get
(
name
)
if
g
==
nil
{
continue
}
clients
:=
g
.
g
etClients
(
nil
)
clients
:=
g
.
G
etClients
(
nil
)
stats
:=
groupStats
{
name
:
name
,
clients
:
make
([]
clientStats
,
0
,
len
(
clients
)),
...
...
webclient.go
View file @
c6087233
This diff is collapsed.
Click to expand it.
webserver.go
View file @
c6087233
...
...
@@ -18,6 +18,8 @@ import (
"time"
"github.com/gorilla/websocket"
"sfu/group"
)
var
server
*
http
.
Server
...
...
@@ -47,8 +49,8 @@ func webserver() {
IdleTimeout
:
120
*
time
.
Second
,
}
server
.
RegisterOnShutdown
(
func
()
{
rangeGroups
(
func
(
g
*
g
roup
)
bool
{
go
g
.
s
hutdown
(
"server is shutting down"
)
group
.
Range
(
func
(
g
*
group
.
G
roup
)
bool
{
go
g
.
S
hutdown
(
"server is shutting down"
)
return
true
})
})
...
...
@@ -139,7 +141,7 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
return
}
g
,
err
:=
addGroup
(
name
,
nil
)
g
,
err
:=
group
.
Add
(
name
,
nil
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
notFound
(
w
)
...
...
@@ -168,7 +170,7 @@ func publicHandler(w http.ResponseWriter, r *http.Request) {
return
}
g
:=
g
etPublicGroups
()
g
:=
g
roup
.
GetPublic
()
e
:=
json
.
NewEncoder
(
w
)
e
.
Encode
(
g
)
return
...
...
@@ -409,8 +411,8 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
}
}
func
checkGroupPermissions
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
group
string
)
bool
{
desc
,
err
:=
g
etDescription
(
group
)
func
checkGroupPermissions
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
group
name
string
)
bool
{
desc
,
err
:=
g
roup
.
GetDescription
(
groupname
)
if
err
!=
nil
{
return
false
}
...
...
@@ -420,7 +422,7 @@ func checkGroupPermissions(w http.ResponseWriter, r *http.Request, group string)
return
false
}
p
,
err
:=
getPermission
(
desc
,
c
lientCredentials
{
user
,
pass
})
p
,
err
:=
desc
.
GetPermission
(
group
.
C
lientCredentials
{
user
,
pass
})
if
err
!=
nil
||
!
p
.
Record
{
return
false
}
...
...
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