Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
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
nexedi
galene
Commits
307c834b
Commit
307c834b
authored
Dec 28, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check ICE configuration periodically.
parent
89a9e6c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
21 deletions
+41
-21
group/ice.go
group/ice.go
+41
-21
No files found.
group/ice.go
View file @
307c834b
...
...
@@ -4,7 +4,8 @@ import (
"encoding/json"
"log"
"os"
"sync"
"sync/atomic"
"time"
"github.com/pion/webrtc/v3"
)
...
...
@@ -24,35 +25,54 @@ type RTCConfiguration struct {
var
ICEFilename
string
var
ICERelayOnly
bool
var
iceConf
RTCConfiguration
var
iceOnce
sync
.
Once
type
iceConf
struct
{
conf
RTCConfiguration
timestamp
time
.
Time
}
func
ICEConfiguration
()
*
RTCConfiguration
{
iceOnce
.
Do
(
func
()
{
var
iceServers
[]
ICEServer
var
iceConfiguration
atomic
.
Value
func
updateICEConfiguration
()
*
iceConf
{
now
:=
time
.
Now
()
var
conf
RTCConfiguration
if
ICEFilename
!=
""
{
file
,
err
:=
os
.
Open
(
ICEFilename
)
if
err
!=
nil
{
log
.
Printf
(
"Open %v: %v"
,
ICEFilename
,
err
)
return
}
else
{
defer
file
.
Close
()
d
:=
json
.
NewDecoder
(
file
)
err
=
d
.
Decode
(
&
conf
.
ICEServers
)
if
err
!=
nil
{
log
.
Printf
(
"Get ICE configuration: %v"
,
err
)
}
}
defer
file
.
Close
()
d
:=
json
.
NewDecoder
(
file
)
err
=
d
.
Decode
(
&
iceServers
)
if
err
!=
nil
{
log
.
Printf
(
"Get ICE configuration: %v"
,
err
)
return
}
iceConf
=
RTCConfiguration
{
ICEServers
:
iceServers
,
}
if
ICERelayOnly
{
iceConf
.
ICETransportPolicy
=
"relay"
}
})
}
if
ICERelayOnly
{
conf
.
ICETransportPolicy
=
"relay"
}
iceConf
:=
iceConf
{
conf
:
conf
,
timestamp
:
now
,
}
iceConfiguration
.
Store
(
&
iceConf
)
return
&
iceConf
}
func
ICEConfiguration
()
*
RTCConfiguration
{
conf
,
ok
:=
iceConfiguration
.
Load
()
.
(
*
iceConf
)
if
!
ok
||
time
.
Since
(
conf
.
timestamp
)
>
5
*
time
.
Minute
{
conf
=
updateICEConfiguration
()
}
else
if
time
.
Since
(
conf
.
timestamp
)
>
2
*
time
.
Minute
{
go
updateICEConfiguration
()
}
return
&
conf
.
conf
}
func
ToConfiguration
(
conf
*
RTCConfiguration
)
webrtc
.
Configuration
{
var
iceServers
[]
webrtc
.
ICEServer
for
_
,
s
:=
range
conf
.
ICEServers
{
...
...
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