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