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
d8b98497
Commit
d8b98497
authored
May 27, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename client to webClient.
parent
50982fdd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
55 deletions
+55
-55
conn.go
conn.go
+1
-1
group.go
group.go
+13
-29
webclient.go
webclient.go
+41
-25
No files found.
conn.go
View file @
d8b98497
...
...
@@ -281,7 +281,7 @@ type downConnection interface {
type
rtpDownConnection
struct
{
id
string
client
*
c
lient
client
*
webC
lient
pc
*
webrtc
.
PeerConnection
remote
*
upConnection
tracks
[]
*
rtpDownTrack
...
...
group.go
View file @
d8b98497
...
...
@@ -21,22 +21,6 @@ import (
"github.com/pion/webrtc/v2"
)
type
client
struct
{
group
*
group
id
string
username
string
permissions
userPermission
requested
map
[
string
]
uint32
done
chan
struct
{}
writeCh
chan
interface
{}
writerDone
chan
struct
{}
actionCh
chan
interface
{}
mu
sync
.
Mutex
down
map
[
string
]
*
rtpDownConnection
up
map
[
string
]
*
upConnection
}
type
chatHistoryEntry
struct
{
id
string
user
string
...
...
@@ -57,7 +41,7 @@ type group struct {
locked
uint32
mu
sync
.
Mutex
clients
map
[
string
]
*
c
lient
clients
map
[
string
]
*
webC
lient
history
[]
chatHistoryEntry
}
...
...
@@ -80,7 +64,7 @@ type getUpAction struct {
}
type
pushConnsAction
struct
{
c
*
c
lient
c
*
webC
lient
}
type
connectionFailedAction
struct
{
...
...
@@ -138,7 +122,7 @@ func addGroup(name string, desc *groupDescription) (*group, error) {
g
=
&
group
{
name
:
name
,
description
:
desc
,
clients
:
make
(
map
[
string
]
*
c
lient
),
clients
:
make
(
map
[
string
]
*
webC
lient
),
}
groups
.
groups
[
name
]
=
g
}
else
if
desc
!=
nil
{
...
...
@@ -211,7 +195,7 @@ type userid struct {
username
string
}
func
addClient
(
name
string
,
client
*
c
lient
,
user
,
pass
string
)
(
*
group
,
[]
userid
,
error
)
{
func
addClient
(
name
string
,
client
*
webC
lient
,
user
,
pass
string
)
(
*
group
,
[]
userid
,
error
)
{
g
,
err
:=
addGroup
(
name
,
nil
)
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
@@ -247,7 +231,7 @@ func addClient(name string, client *client, user, pass string) (*group, []userid
return
g
,
users
,
nil
}
func
delClient
(
c
*
c
lient
)
{
func
delClient
(
c
*
webC
lient
)
{
c
.
group
.
mu
.
Lock
()
defer
c
.
group
.
mu
.
Unlock
()
g
:=
c
.
group
...
...
@@ -259,10 +243,10 @@ func delClient(c *client) {
delete
(
g
.
clients
,
c
.
id
)
}
func
(
g
*
group
)
getClients
(
except
*
client
)
[]
*
c
lient
{
func
(
g
*
group
)
getClients
(
except
*
webClient
)
[]
*
webC
lient
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
clients
:=
make
([]
*
c
lient
,
0
,
len
(
g
.
clients
))
clients
:=
make
([]
*
webC
lient
,
0
,
len
(
g
.
clients
))
for
_
,
c
:=
range
g
.
clients
{
if
c
!=
except
{
clients
=
append
(
clients
,
c
)
...
...
@@ -271,7 +255,7 @@ func (g *group) getClients(except *client) []*client {
return
clients
}
func
(
g
*
group
)
getClientUnlocked
(
id
string
)
*
c
lient
{
func
(
g
*
group
)
getClientUnlocked
(
id
string
)
*
webC
lient
{
for
_
,
c
:=
range
g
.
clients
{
if
c
.
id
==
id
{
return
c
...
...
@@ -280,7 +264,7 @@ func (g *group) getClientUnlocked(id string) *client {
return
nil
}
func
(
g
*
group
)
Range
(
f
func
(
c
*
c
lient
)
bool
)
{
func
(
g
*
group
)
Range
(
f
func
(
c
*
webC
lient
)
bool
)
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
for
_
,
c
:=
range
g
.
clients
{
...
...
@@ -327,7 +311,7 @@ func (err writerDeadError) Error() string {
return
"client writer died"
}
func
(
c
*
c
lient
)
write
(
m
clientMessage
)
error
{
func
(
c
*
webC
lient
)
write
(
m
clientMessage
)
error
{
select
{
case
c
.
writeCh
<-
m
:
return
nil
...
...
@@ -336,7 +320,7 @@ func (c *client) write(m clientMessage) error {
}
}
func
(
c
*
c
lient
)
error
(
err
error
)
error
{
func
(
c
*
webC
lient
)
error
(
err
error
)
error
{
switch
e
:=
err
.
(
type
)
{
case
userError
:
return
c
.
write
(
clientMessage
{
...
...
@@ -354,7 +338,7 @@ func (err clientDeadError) Error() string {
return
"client dead"
}
func
(
c
*
c
lient
)
action
(
m
interface
{})
error
{
func
(
c
*
webC
lient
)
action
(
m
interface
{})
error
{
select
{
case
c
.
actionCh
<-
m
:
return
nil
...
...
@@ -611,7 +595,7 @@ func getGroupStats() []groupStats {
return
gs
}
func
getClientStats
(
c
*
c
lient
)
clientStats
{
func
getClientStats
(
c
*
webC
lient
)
clientStats
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
...
...
client.go
→
web
client.go
View file @
d8b98497
...
...
@@ -91,6 +91,22 @@ func isWSNormalError(err error) bool {
websocket
.
CloseGoingAway
)
}
type
webClient
struct
{
group
*
group
id
string
username
string
permissions
userPermission
requested
map
[
string
]
uint32
done
chan
struct
{}
writeCh
chan
interface
{}
writerDone
chan
struct
{}
actionCh
chan
interface
{}
mu
sync
.
Mutex
down
map
[
string
]
*
rtpDownConnection
up
map
[
string
]
*
upConnection
}
type
rateMap
map
[
string
]
uint32
func
(
v
*
rateMap
)
UnmarshalJSON
(
b
[]
byte
)
error
{
...
...
@@ -183,7 +199,7 @@ func startClient(conn *websocket.Conn) (err error) {
return
}
c
:=
&
c
lient
{
c
:=
&
webC
lient
{
id
:
m
.
Id
,
username
:
m
.
Username
,
actionCh
:
make
(
chan
interface
{},
10
),
...
...
@@ -262,7 +278,7 @@ func startClient(conn *websocket.Conn) (err error) {
return
clientLoop
(
c
,
conn
)
}
func
getUpConn
(
c
*
c
lient
,
id
string
)
*
upConnection
{
func
getUpConn
(
c
*
webC
lient
,
id
string
)
*
upConnection
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
...
...
@@ -276,7 +292,7 @@ func getUpConn(c *client, id string) *upConnection {
return
conn
}
func
getUpConns
(
c
*
c
lient
)
[]
string
{
func
getUpConns
(
c
*
webC
lient
)
[]
string
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
up
:=
make
([]
string
,
0
,
len
(
c
.
up
))
...
...
@@ -286,7 +302,7 @@ func getUpConns(c *client) []string {
return
up
}
func
addUpConn
(
c
*
c
lient
,
id
string
)
(
*
upConnection
,
error
)
{
func
addUpConn
(
c
*
webC
lient
,
id
string
)
(
*
upConnection
,
error
)
{
pc
,
err
:=
groups
.
api
.
NewPeerConnection
(
iceConfiguration
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -563,7 +579,7 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
}
}
func
sendRR
(
c
*
c
lient
,
conn
*
upConnection
)
error
{
func
sendRR
(
c
*
webC
lient
,
conn
*
upConnection
)
error
{
c
.
mu
.
Lock
()
if
len
(
conn
.
tracks
)
==
0
{
c
.
mu
.
Unlock
()
...
...
@@ -604,7 +620,7 @@ func sendRR(c *client, conn *upConnection) error {
})
}
func
rtcpUpSender
(
c
*
c
lient
,
conn
*
upConnection
)
{
func
rtcpUpSender
(
c
*
webC
lient
,
conn
*
upConnection
)
{
for
{
time
.
Sleep
(
time
.
Second
)
err
:=
sendRR
(
c
,
conn
)
...
...
@@ -617,7 +633,7 @@ func rtcpUpSender(c *client, conn *upConnection) {
}
}
func
delUpConn
(
c
*
c
lient
,
id
string
)
bool
{
func
delUpConn
(
c
*
webC
lient
,
id
string
)
bool
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
...
...
@@ -653,7 +669,7 @@ func delUpConn(c *client, id string) bool {
return
true
}
func
getDownConn
(
c
*
c
lient
,
id
string
)
*
rtpDownConnection
{
func
getDownConn
(
c
*
webC
lient
,
id
string
)
*
rtpDownConnection
{
if
c
.
down
==
nil
{
return
nil
}
...
...
@@ -667,7 +683,7 @@ func getDownConn(c *client, id string) *rtpDownConnection {
return
conn
}
func
getConn
(
c
*
c
lient
,
id
string
)
iceConnection
{
func
getConn
(
c
*
webC
lient
,
id
string
)
iceConnection
{
up
:=
getUpConn
(
c
,
id
)
if
up
!=
nil
{
return
up
...
...
@@ -679,7 +695,7 @@ func getConn(c *client, id string) iceConnection {
return
nil
}
func
addDownConn
(
c
*
c
lient
,
id
string
,
remote
*
upConnection
)
(
*
rtpDownConnection
,
error
)
{
func
addDownConn
(
c
*
webC
lient
,
id
string
,
remote
*
upConnection
)
(
*
rtpDownConnection
,
error
)
{
pc
,
err
:=
groups
.
api
.
NewPeerConnection
(
iceConfiguration
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -716,7 +732,7 @@ func addDownConn(c *client, id string, remote *upConnection) (*rtpDownConnection
return
conn
,
nil
}
func
delDownConn
(
c
*
c
lient
,
id
string
)
bool
{
func
delDownConn
(
c
*
webC
lient
,
id
string
)
bool
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
...
...
@@ -740,7 +756,7 @@ func delDownConn(c *client, id string) bool {
return
true
}
func
addDownTrack
(
c
*
c
lient
,
conn
*
rtpDownConnection
,
remoteTrack
*
upTrack
,
remoteConn
*
upConnection
)
(
*
webrtc
.
RTPSender
,
error
)
{
func
addDownTrack
(
c
*
webC
lient
,
conn
*
rtpDownConnection
,
remoteTrack
*
upTrack
,
remoteConn
*
upConnection
)
(
*
webrtc
.
RTPSender
,
error
)
{
local
,
err
:=
conn
.
pc
.
NewTrack
(
remoteTrack
.
track
.
PayloadType
(),
remoteTrack
.
track
.
SSRC
(),
...
...
@@ -1058,7 +1074,7 @@ func sendRecovery(p *rtcp.TransportLayerNack, track *rtpDownTrack) {
}
}
func
negotiate
(
c
*
c
lient
,
down
*
rtpDownConnection
)
error
{
func
negotiate
(
c
*
webC
lient
,
down
*
rtpDownConnection
)
error
{
offer
,
err
:=
down
.
pc
.
CreateOffer
(
nil
)
if
err
!=
nil
{
return
err
...
...
@@ -1094,7 +1110,7 @@ func negotiate(c *client, down *rtpDownConnection) error {
})
}
func
sendICE
(
c
*
c
lient
,
id
string
,
candidate
*
webrtc
.
ICECandidate
)
error
{
func
sendICE
(
c
*
webC
lient
,
id
string
,
candidate
*
webrtc
.
ICECandidate
)
error
{
if
candidate
==
nil
{
return
nil
}
...
...
@@ -1106,7 +1122,7 @@ func sendICE(c *client, id string, candidate *webrtc.ICECandidate) error {
})
}
func
gotOffer
(
c
*
c
lient
,
id
string
,
offer
webrtc
.
SessionDescription
,
labels
map
[
string
]
string
)
error
{
func
gotOffer
(
c
*
webC
lient
,
id
string
,
offer
webrtc
.
SessionDescription
,
labels
map
[
string
]
string
)
error
{
var
err
error
up
,
ok
:=
c
.
up
[
id
]
if
!
ok
{
...
...
@@ -1147,7 +1163,7 @@ func gotOffer(c *client, id string, offer webrtc.SessionDescription, labels map[
})
}
func
gotAnswer
(
c
*
c
lient
,
id
string
,
answer
webrtc
.
SessionDescription
)
error
{
func
gotAnswer
(
c
*
webC
lient
,
id
string
,
answer
webrtc
.
SessionDescription
)
error
{
down
:=
getDownConn
(
c
,
id
)
if
down
==
nil
{
return
protocolError
(
"unknown id in answer"
)
...
...
@@ -1168,7 +1184,7 @@ func gotAnswer(c *client, id string, answer webrtc.SessionDescription) error {
return
nil
}
func
gotICE
(
c
*
c
lient
,
candidate
*
webrtc
.
ICECandidateInit
,
id
string
)
error
{
func
gotICE
(
c
*
webC
lient
,
candidate
*
webrtc
.
ICECandidateInit
,
id
string
)
error
{
conn
:=
getConn
(
c
,
id
)
if
conn
==
nil
{
return
errors
.
New
(
"unknown id in ICE"
)
...
...
@@ -1176,7 +1192,7 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
return
conn
.
addICECandidate
(
candidate
)
}
func
(
c
*
c
lient
)
setRequested
(
requested
map
[
string
]
uint32
)
error
{
func
(
c
*
webC
lient
)
setRequested
(
requested
map
[
string
]
uint32
)
error
{
if
c
.
down
!=
nil
{
for
id
:=
range
c
.
down
{
c
.
write
(
clientMessage
{
...
...
@@ -1199,11 +1215,11 @@ func (c *client) setRequested(requested map[string]uint32) error {
return
nil
}
func
(
c
*
c
lient
)
isRequested
(
label
string
)
bool
{
func
(
c
*
webC
lient
)
isRequested
(
label
string
)
bool
{
return
c
.
requested
[
label
]
!=
0
}
func
addDownConnTracks
(
c
*
c
lient
,
remote
*
upConnection
,
tracks
[]
*
upTrack
)
(
*
rtpDownConnection
,
error
)
{
func
addDownConnTracks
(
c
*
webC
lient
,
remote
*
upConnection
,
tracks
[]
*
upTrack
)
(
*
rtpDownConnection
,
error
)
{
requested
:=
false
for
_
,
t
:=
range
tracks
{
if
c
.
isRequested
(
t
.
label
)
{
...
...
@@ -1234,14 +1250,14 @@ func addDownConnTracks(c *client, remote *upConnection, tracks []*upTrack) (*rtp
return
down
,
nil
}
func
pushConn
(
c
*
c
lient
,
conn
*
upConnection
,
tracks
[]
*
upTrack
,
label
string
)
{
func
pushConn
(
c
*
webC
lient
,
conn
*
upConnection
,
tracks
[]
*
upTrack
,
label
string
)
{
c
.
action
(
addConnAction
{
conn
,
tracks
})
if
label
!=
""
{
c
.
action
(
addLabelAction
{
conn
.
id
,
conn
.
label
})
}
}
func
clientLoop
(
c
*
c
lient
,
conn
*
websocket
.
Conn
)
error
{
func
clientLoop
(
c
*
webC
lient
,
conn
*
websocket
.
Conn
)
error
{
read
:=
make
(
chan
interface
{},
1
)
go
clientReader
(
conn
,
read
,
c
.
done
)
...
...
@@ -1393,7 +1409,7 @@ func clientLoop(c *client, conn *websocket.Conn) error {
}
}
func
failConnection
(
c
*
c
lient
,
id
string
,
message
string
)
error
{
func
failConnection
(
c
*
webC
lient
,
id
string
,
message
string
)
error
{
if
id
!=
""
{
err
:=
c
.
write
(
clientMessage
{
Type
:
"abort"
,
...
...
@@ -1412,7 +1428,7 @@ func failConnection(c *client, id string, message string) error {
return
nil
}
func
handleClientMessage
(
c
*
c
lient
,
m
clientMessage
)
error
{
func
handleClientMessage
(
c
*
webC
lient
,
m
clientMessage
)
error
{
switch
m
.
Type
{
case
"request"
:
err
:=
c
.
setRequested
(
m
.
Request
)
...
...
@@ -1507,7 +1523,7 @@ func handleClientMessage(c *client, m clientMessage) error {
return
nil
}
func
sendRateUpdate
(
c
*
c
lient
)
{
func
sendRateUpdate
(
c
*
webC
lient
)
{
type
remb
struct
{
pc
*
webrtc
.
PeerConnection
ssrc
uint32
...
...
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