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
7979720e
Commit
7979720e
authored
Apr 25, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Read public groups at startup.
parent
1fb527e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
group.go
group.go
+40
-5
sfu.go
sfu.go
+2
-0
No files found.
group.go
View file @
7979720e
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"sync"
"sync"
"strings"
"time"
"time"
"github.com/pion/webrtc/v2"
"github.com/pion/webrtc/v2"
...
@@ -89,7 +90,7 @@ var groups struct {
...
@@ -89,7 +90,7 @@ var groups struct {
api
*
webrtc
.
API
api
*
webrtc
.
API
}
}
func
addGroup
(
name
string
)
(
*
group
,
error
)
{
func
addGroup
(
name
string
,
desc
*
groupDescription
)
(
*
group
,
error
)
{
groups
.
mu
.
Lock
()
groups
.
mu
.
Lock
()
defer
groups
.
mu
.
Unlock
()
defer
groups
.
mu
.
Unlock
()
...
@@ -105,17 +106,23 @@ func addGroup(name string) (*group, error) {
...
@@ -105,17 +106,23 @@ func addGroup(name string) (*group, error) {
)
)
}
}
var
err
error
g
:=
groups
.
groups
[
name
]
g
:=
groups
.
groups
[
name
]
if
g
==
nil
{
if
g
==
nil
{
desc
,
err
:=
getDescription
(
name
)
if
(
desc
==
nil
)
{
if
err
!=
nil
{
desc
,
err
=
getDescription
(
name
)
return
nil
,
err
if
err
!=
nil
{
return
nil
,
err
}
}
}
g
=
&
group
{
g
=
&
group
{
name
:
name
,
name
:
name
,
description
:
desc
,
description
:
desc
,
}
}
groups
.
groups
[
name
]
=
g
groups
.
groups
[
name
]
=
g
}
else
if
desc
!=
nil
{
g
.
description
=
desc
}
else
if
g
.
dead
||
time
.
Since
(
g
.
description
.
loadTime
)
>
5
*
time
.
Second
{
}
else
if
g
.
dead
||
time
.
Since
(
g
.
description
.
loadTime
)
>
5
*
time
.
Second
{
changed
,
err
:=
descriptionChanged
(
name
,
g
.
description
)
changed
,
err
:=
descriptionChanged
(
name
,
g
.
description
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -164,7 +171,7 @@ type userid struct {
...
@@ -164,7 +171,7 @@ type userid struct {
}
}
func
addClient
(
name
string
,
client
*
client
,
user
,
pass
string
)
(
*
group
,
[]
userid
,
error
)
{
func
addClient
(
name
string
,
client
*
client
,
user
,
pass
string
)
(
*
group
,
[]
userid
,
error
)
{
g
,
err
:=
addGroup
(
name
)
g
,
err
:=
addGroup
(
name
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
@@ -376,3 +383,31 @@ func getPublicGroups() []publicGroup {
...
@@ -376,3 +383,31 @@ func getPublicGroups() []publicGroup {
}
}
return
gs
return
gs
}
}
func
readPublicGroups
()
{
dir
,
err
:=
os
.
Open
(
groupsDir
)
if
err
!=
nil
{
return
}
defer
dir
.
Close
()
fis
,
err
:=
dir
.
Readdir
(
-
1
)
if
err
!=
nil
{
log
.
Printf
(
"readPublicGroups: %v"
,
err
)
return
}
for
_
,
fi
:=
range
fis
{
if
!
strings
.
HasSuffix
(
fi
.
Name
(),
".json"
)
{
continue
}
name
:=
fi
.
Name
()[
:
len
(
fi
.
Name
())
-
5
]
desc
,
err
:=
getDescription
(
name
)
if
err
!=
nil
{
continue
}
if
desc
.
Public
{
addGroup
(
name
,
desc
)
}
}
}
sfu.go
View file @
7979720e
...
@@ -45,6 +45,8 @@ func main() {
...
@@ -45,6 +45,8 @@ func main() {
http
.
HandleFunc
(
"/ws"
,
wsHandler
)
http
.
HandleFunc
(
"/ws"
,
wsHandler
)
http
.
HandleFunc
(
"/public-groups.json"
,
publicHandler
)
http
.
HandleFunc
(
"/public-groups.json"
,
publicHandler
)
go
readPublicGroups
()
go
func
()
{
go
func
()
{
server
:=
&
http
.
Server
{
server
:=
&
http
.
Server
{
Addr
:
httpAddr
,
Addr
:
httpAddr
,
...
...
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