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
88d2a968
Commit
88d2a968
authored
Aug 12, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure error and chat messages.
parent
7b512962
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
15 deletions
+25
-15
group.go
group.go
+3
-3
static/sfu.js
static/sfu.js
+13
-6
webclient.go
webclient.go
+9
-6
No files found.
group.go
View file @
88d2a968
...
...
@@ -24,8 +24,8 @@ import (
type
chatHistoryEntry
struct
{
id
string
user
string
kind
string
value
string
me
bool
}
const
(
...
...
@@ -294,7 +294,7 @@ func (g *group) clearChatHistory() {
g
.
history
=
nil
}
func
(
g
*
group
)
addToChatHistory
(
id
,
user
,
value
string
,
me
bool
)
{
func
(
g
*
group
)
addToChatHistory
(
id
,
user
,
kind
,
value
string
)
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
...
...
@@ -303,7 +303,7 @@ func (g *group) addToChatHistory(id, user, value string, me bool) {
g
.
history
=
g
.
history
[
:
len
(
g
.
history
)
-
1
]
}
g
.
history
=
append
(
g
.
history
,
chatHistoryEntry
{
id
:
id
,
user
:
user
,
value
:
value
,
me
:
m
e
},
chatHistoryEntry
{
id
:
id
,
user
:
user
,
kind
:
kind
,
value
:
valu
e
},
)
}
...
...
static/sfu.js
View file @
88d2a968
...
...
@@ -681,7 +681,7 @@ function serverConnect() {
gotUser
(
m
.
id
,
m
.
username
,
m
.
del
);
break
;
case
'
chat
'
:
addToChatbox
(
m
.
id
,
m
.
username
,
m
.
value
,
m
.
m
e
);
addToChatbox
(
m
.
id
,
m
.
username
,
m
.
kind
,
m
.
valu
e
);
break
;
case
'
clearchat
'
:
resetChat
();
...
...
@@ -694,8 +694,15 @@ function serverConnect() {
case
'
pong
'
:
/* nothing */
break
;
case
'
error
'
:
displayError
(
'
The server said:
'
+
m
.
value
);
case
'
usermessage
'
:
switch
(
m
.
kind
)
{
case
'
error
'
:
displayError
(
'
The server said:
'
+
m
.
value
);
break
;
default
:
displayWarning
(
'
The server said:
'
+
m
.
value
)
break
;
}
break
;
default
:
console
.
warn
(
'
Unexpected server message
'
,
m
.
type
);
...
...
@@ -962,10 +969,10 @@ function formatLines(lines) {
let
lastMessage
=
{};
function
addToChatbox
(
peerId
,
nick
,
message
,
m
e
){
function
addToChatbox
(
peerId
,
nick
,
kind
,
messag
e
){
let
container
=
document
.
createElement
(
'
div
'
);
container
.
classList
.
add
(
'
message
'
);
if
(
!
me
)
{
if
(
kind
!==
'
me
'
)
{
let
p
=
formatLines
(
message
.
split
(
'
\n
'
));
if
(
lastMessage
.
nick
!==
nick
||
lastMessage
.
peerId
!==
peerId
)
{
let
user
=
document
.
createElement
(
'
p
'
);
...
...
@@ -1124,8 +1131,8 @@ function handleInput() {
type
:
'
chat
'
,
id
:
myid
,
username
:
username
,
kind
:
me
?
'
me
'
:
''
,
value
:
message
,
me
:
me
,
});
}
catch
(
e
)
{
console
.
error
(
e
);
...
...
webclient.go
View file @
88d2a968
...
...
@@ -175,7 +175,7 @@ type clientMessage struct {
Permissions
clientPermission
`json:"permissions,omitempty"`
Group
string
`json:"group,omitempty"`
Value
string
`json:"value,omitempty"`
Me
bool
`json:"me
,omitempty"`
Kind
string
`json:"kind
,omitempty"`
Offer
*
webrtc
.
SessionDescription
`json:"offer,omitempty"`
Answer
*
webrtc
.
SessionDescription
`json:"answer,omitempty"`
Candidate
*
webrtc
.
ICECandidateInit
`json:"candidate,omitempty"`
...
...
@@ -634,7 +634,8 @@ func startClient(conn *websocket.Conn) (err error) {
// at this point, the writer is not running yet, so format
// the message ourselves
conn
.
WriteJSON
(
clientMessage
{
Type
:
"error"
,
Type
:
"usermessage"
,
Kind
:
"error"
,
Value
:
"don't put spaces in your username"
,
})
conn
.
WriteMessage
(
websocket
.
CloseMessage
,
...
...
@@ -667,7 +668,8 @@ func startClient(conn *websocket.Conn) (err error) {
m
,
e
:=
errorToWSCloseMessage
(
err
)
if
m
!=
""
{
c
.
write
(
clientMessage
{
Type
:
"error"
,
Type
:
"usermessage"
,
Kind
:
"error"
,
Value
:
m
,
})
}
...
...
@@ -727,7 +729,7 @@ func clientLoop(c *webClient, conn *websocket.Conn) error {
Id
:
m
.
id
,
Username
:
m
.
user
,
Value
:
m
.
value
,
Me
:
m
.
me
,
Kind
:
m
.
kind
,
})
if
err
!=
nil
{
return
err
...
...
@@ -996,7 +998,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
log
.
Printf
(
"ICE: %v"
,
err
)
}
case
"chat"
:
c
.
group
.
addToChatHistory
(
m
.
Id
,
m
.
Username
,
m
.
Value
,
m
.
M
e
)
c
.
group
.
addToChatHistory
(
m
.
Id
,
m
.
Username
,
m
.
Kind
,
m
.
Valu
e
)
clients
:=
c
.
group
.
getClients
(
nil
)
for
_
,
cc
:=
range
clients
{
cc
,
ok
:=
cc
.
(
*
webClient
)
...
...
@@ -1163,7 +1165,8 @@ func (c *webClient) error(err error) error {
switch
e
:=
err
.
(
type
)
{
case
userError
:
return
c
.
write
(
clientMessage
{
Type
:
"error"
,
Type
:
"usermessage"
,
Kind
:
"error"
,
Value
:
string
(
e
),
})
default
:
...
...
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