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
90ba4814
Commit
90ba4814
authored
Oct 08, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Discard old history entries.
parent
865848c7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
22 deletions
+47
-22
README
README
+2
-0
group/group.go
group/group.go
+39
-2
group/group_test.go
group/group_test.go
+4
-4
rtpconn/webclient.go
rtpconn/webclient.go
+2
-16
No files found.
README
View file @
90ba4814
...
...
@@ -103,6 +103,8 @@ fields, all of which are optional.
displayed on the landing page for public groups;
- `max-clients`: the maximum number of clients that may join the group at
a time;
- `max-history-age`: the time, in seconds, during which chat history is
kept (default 14400, i.e. 4 hours);
- `allow-recording`: if true, then recording is allowed in this group;
- `allow-anonymous`: if true, then users may connect with an empty
username; this is not recommended, since anonymous users are not
...
...
group/group.go
View file @
90ba4814
...
...
@@ -65,7 +65,7 @@ func IceConfiguration() webrtc.Configuration {
type
ChatHistoryEntry
struct
{
Id
string
User
string
Time
u
int64
Time
int64
Kind
string
Value
string
}
...
...
@@ -396,6 +396,18 @@ func (g *Group) Shutdown(message string) {
})
}
func
FromJSTime
(
tm
int64
)
time
.
Time
{
if
tm
==
0
{
return
time
.
Time
{}
}
return
time
.
Unix
(
int64
(
tm
)
/
1000
,
(
int64
(
tm
)
%
1000
)
*
1000000
)
}
func
ToJSTime
(
tm
time
.
Time
)
int64
{
return
int64
((
tm
.
Sub
(
time
.
Unix
(
0
,
0
))
+
time
.
Millisecond
/
2
)
/
time
.
Millisecond
)
}
const
maxChatHistory
=
50
func
(
g
*
Group
)
ClearChatHistory
()
{
...
...
@@ -404,7 +416,7 @@ func (g *Group) ClearChatHistory() {
g
.
history
=
nil
}
func
(
g
*
Group
)
AddToChatHistory
(
id
,
user
string
,
time
u
int64
,
kind
,
value
string
)
{
func
(
g
*
Group
)
AddToChatHistory
(
id
,
user
string
,
time
int64
,
kind
,
value
string
)
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
...
...
@@ -417,10 +429,34 @@ func (g *Group) AddToChatHistory(id, user string, time uint64, kind, value strin
)
}
func
discardObsoleteHistory
(
h
[]
ChatHistoryEntry
,
seconds
int
)
[]
ChatHistoryEntry
{
now
:=
time
.
Now
()
d
:=
4
*
time
.
Hour
if
seconds
>
0
{
d
=
time
.
Duration
(
seconds
)
*
time
.
Second
}
i
:=
0
for
i
<
len
(
h
)
{
log
.
Println
(
h
[
i
]
.
Time
,
FromJSTime
(
h
[
i
]
.
Time
),
now
.
Sub
(
FromJSTime
(
h
[
i
]
.
Time
)))
if
now
.
Sub
(
FromJSTime
(
h
[
i
]
.
Time
))
<=
d
{
break
}
i
++
}
if
i
>
0
{
copy
(
h
,
h
[
i
:
])
h
=
h
[
:
len
(
h
)
-
i
]
}
return
h
}
func
(
g
*
Group
)
GetChatHistory
()
[]
ChatHistoryEntry
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
g
.
history
=
discardObsoleteHistory
(
g
.
history
,
g
.
description
.
MaxHistoryAge
)
h
:=
make
([]
ChatHistoryEntry
,
len
(
g
.
history
))
copy
(
h
,
g
.
history
)
return
h
...
...
@@ -448,6 +484,7 @@ type description struct {
Redirect
string
`json:"redirect,omitempty"`
Public
bool
`json:"public,omitempty"`
MaxClients
int
`json:"max-clients,omitempty"`
MaxHistoryAge
int
`json:"max-history-age",omitempty`
AllowAnonymous
bool
`json:"allow-anonymous,omitempty"`
AllowRecording
bool
`json:"allow-recording,omitempty"`
Op
[]
ClientCredentials
`json:"op,omitempty"`
...
...
rtpconn/webclient
_test.go
→
group/group
_test.go
View file @
90ba4814
package
rtpconn
package
group
import
(
"testing"
...
...
@@ -7,9 +7,9 @@ import (
func
TestJSTime
(
t
*
testing
.
T
)
{
tm
:=
time
.
Now
()
js
:=
t
oJSTime
(
tm
)
tm2
:=
f
romJSTime
(
js
)
js2
:=
t
oJSTime
(
tm2
)
js
:=
T
oJSTime
(
tm
)
tm2
:=
F
romJSTime
(
js
)
js2
:=
T
oJSTime
(
tm2
)
if
js
!=
js2
{
t
.
Errorf
(
"%v != %v"
,
js
,
js2
)
...
...
rtpconn/webclient.go
View file @
90ba4814
...
...
@@ -147,7 +147,7 @@ type clientMessage struct {
Permissions
group
.
ClientPermissions
`json:"permissions,omitempty"`
Group
string
`json:"group,omitempty"`
Value
string
`json:"value,omitempty"`
Time
uint64
`json:"time,omitempty"`
Time
int64
`json:"time,omitempty"`
Offer
*
webrtc
.
SessionDescription
`json:"offer,omitempty"`
Answer
*
webrtc
.
SessionDescription
`json:"answer,omitempty"`
Candidate
*
webrtc
.
ICECandidateInit
`json:"candidate,omitempty"`
...
...
@@ -155,20 +155,6 @@ type clientMessage struct {
Request
rateMap
`json:"request,omitempty"`
}
func
fromJSTime
(
tm
uint64
)
time
.
Time
{
if
tm
==
0
{
return
time
.
Time
{}
}
return
time
.
Unix
(
int64
(
tm
)
/
1000
,
(
int64
(
tm
)
%
1000
)
*
1000000
)
}
func
toJSTime
(
tm
time
.
Time
)
uint64
{
if
tm
.
Before
(
time
.
Unix
(
0
,
0
))
{
return
0
}
return
uint64
((
tm
.
Sub
(
time
.
Unix
(
0
,
0
))
+
time
.
Millisecond
/
2
)
/
time
.
Millisecond
)
}
type
closeMessage
struct
{
data
[]
byte
}
...
...
@@ -1060,7 +1046,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
log
.
Printf
(
"ICE: %v"
,
err
)
}
case
"chat"
:
tm
:=
t
oJSTime
(
time
.
Now
())
tm
:=
group
.
T
oJSTime
(
time
.
Now
())
if
m
.
Dest
==
""
{
c
.
group
.
AddToChatHistory
(
m
.
Id
,
m
.
Username
,
tm
,
m
.
Kind
,
m
.
Value
,
...
...
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