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
cb1782b6
Commit
cb1782b6
authored
Apr 25, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow server to push error message to client.
parent
2cb323ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
19 deletions
+36
-19
client.go
client.go
+33
-18
static/sfu.js
static/sfu.js
+3
-1
No files found.
client.go
View file @
cb1782b6
...
...
@@ -54,7 +54,13 @@ func (err protocolError) Error() string {
return
string
(
err
)
}
func
errorToWSCloseMessage
(
err
error
)
[]
byte
{
type
userError
string
func
(
err
userError
)
Error
()
string
{
return
string
(
err
)
}
func
errorToWSCloseMessage
(
err
error
)
(
string
,
[]
byte
)
{
var
code
int
var
text
string
switch
e
:=
err
.
(
type
)
{
...
...
@@ -63,10 +69,13 @@ func errorToWSCloseMessage(err error) []byte {
case
protocolError
:
code
=
websocket
.
CloseProtocolError
text
=
string
(
e
)
case
userError
:
code
=
websocket
.
CloseNormalClosure
text
=
string
(
e
)
default
:
code
=
websocket
.
CloseInternalServerErr
}
return
websocket
.
FormatCloseMessage
(
code
,
text
)
return
"The server said: "
+
text
,
websocket
.
FormatCloseMessage
(
code
,
text
)
}
func
isWSNormalError
(
err
error
)
bool
{
...
...
@@ -76,19 +85,20 @@ func isWSNormalError(err error) bool {
}
type
clientMessage
struct
{
Type
string
`json:"type"`
Id
string
`json:"id,omitempty"`
Username
string
`json:"username,omitempty"`
Password
string
`json:"password,omitempty"`
Group
string
`json:"group,omitempty"`
Value
string
`json:"value,omitempty"`
Me
*
bool
`json:"me,omitempty"`
Offer
*
webrtc
.
SessionDescription
`json:"offer,omitempty"`
Answer
*
webrtc
.
SessionDescription
`json:"answer,omitempty"`
Candidate
*
webrtc
.
ICECandidateInit
`json:"candidate,omitempty"`
Del
bool
`json:"del,omitempty"`
AudioRate
int
`json:"audiorate,omitempty"`
VideoRate
int
`json:"audiorate,omitempty"`
Type
string
`json:"type"`
Id
string
`json:"id,omitempty"`
Username
string
`json:"username,omitempty"`
Password
string
`json:"password,omitempty"`
Group
string
`json:"group,omitempty"`
Value
string
`json:"value,omitempty"`
Message
string
`json:"message,omitempty"`
Me
*
bool
`json:"me,omitempty"`
Offer
*
webrtc
.
SessionDescription
`json:"offer,omitempty"`
Answer
*
webrtc
.
SessionDescription
`json:"answer,omitempty"`
Candidate
*
webrtc
.
ICECandidateInit
`json:"candidate,omitempty"`
Del
bool
`json:"del,omitempty"`
AudioRate
int
`json:"audiorate,omitempty"`
VideoRate
int
`json:"audiorate,omitempty"`
}
type
closeMessage
struct
{
...
...
@@ -120,10 +130,15 @@ func startClient(conn *websocket.Conn) (err error) {
if
isWSNormalError
(
err
)
{
err
=
nil
}
else
{
m
,
e
:=
errorToWSCloseMessage
(
err
)
if
m
!=
""
{
c
.
write
(
clientMessage
{
Type
:
"error"
,
Message
:
m
,
})
}
select
{
case
c
.
writeCh
<-
closeMessage
{
errorToWSCloseMessage
(
err
),
}
:
case
c
.
writeCh
<-
closeMessage
{
e
}
:
case
<-
c
.
writerDone
:
}
}
...
...
static/sfu.js
View file @
cb1782b6
...
...
@@ -311,6 +311,9 @@ function serverConnect() {
case
'
chat
'
:
addToChatbox
(
m
.
id
,
m
.
username
,
m
.
value
,
m
.
me
);
break
;
case
'
error
'
:
displayError
(
m
.
message
);
break
;
default
:
console
.
warn
(
'
Unexpected server message
'
,
m
.
type
);
return
;
...
...
@@ -773,7 +776,6 @@ document.getElementById('disconnectbutton').onclick = function(e) {
socket
.
close
();
}
function
start
()
{
group
=
decodeURIComponent
(
location
.
pathname
.
replace
(
/^
\/[
a-z
]
*
\/
/
,
''
));
let
title
=
document
.
getElementById
(
'
title
'
);
...
...
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