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
77179c3d
Commit
77179c3d
authored
Sep 16, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow usernames with spaces.
This requires a proper parser for commands.
parent
1672f132
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
35 deletions
+42
-35
static/sfu.js
static/sfu.js
+42
-16
webclient.go
webclient.go
+0
-19
No files found.
static/sfu.js
View file @
77179c3d
...
@@ -992,6 +992,40 @@ function clearChat() {
...
@@ -992,6 +992,40 @@ function clearChat() {
document
.
getElementById
(
'
box
'
).
textContent
=
''
;
document
.
getElementById
(
'
box
'
).
textContent
=
''
;
}
}
/**
* parseCommand splits a string into two space-separated parts. The first
* part may be quoted and may include backslash escapes.
*
* @param {string} line
* @returns {Array.<string>}
*/
function
parseCommand
(
line
)
{
let
i
=
0
;
while
(
i
<
line
.
length
&&
line
[
i
]
===
'
'
)
i
++
;
let
start
=
'
'
;
if
(
i
<
line
.
length
&&
line
[
i
]
===
'
"
'
||
line
[
i
]
===
"
'
"
)
{
start
=
line
[
i
];
i
++
;
}
let
first
=
""
;
while
(
i
<
line
.
length
)
{
if
(
line
[
i
]
===
start
)
{
if
(
start
!==
'
'
)
i
++
;
break
;
}
if
(
line
[
i
]
===
'
\\
'
&&
i
<
line
.
length
-
1
)
i
++
;
first
=
first
+
line
[
i
];
i
++
;
}
while
(
i
<
line
.
length
&&
line
[
i
]
===
'
'
)
i
++
;
return
[
first
,
line
.
slice
(
i
)];
}
function
handleInput
()
{
function
handleInput
()
{
let
input
=
document
.
getElementById
(
'
input
'
);
let
input
=
document
.
getElementById
(
'
input
'
);
let
data
=
input
.
value
;
let
data
=
input
.
value
;
...
@@ -1002,8 +1036,8 @@ function handleInput() {
...
@@ -1002,8 +1036,8 @@ function handleInput() {
if
(
data
===
''
)
if
(
data
===
''
)
return
;
return
;
if
(
data
.
charAt
(
0
)
===
'
/
'
)
{
if
(
data
[
0
]
===
'
/
'
)
{
if
(
data
.
charAt
(
1
)
===
'
/
'
)
{
if
(
data
.
length
>
1
&&
data
[
1
]
===
'
/
'
)
{
message
=
data
.
substring
(
1
);
message
=
data
.
substring
(
1
);
me
=
false
;
me
=
false
;
}
else
{
}
else
{
...
@@ -1057,31 +1091,23 @@ function handleInput() {
...
@@ -1057,31 +1091,23 @@ function handleInput() {
displayError
(
"
You're not an operator
"
);
displayError
(
"
You're not an operator
"
);
return
;
return
;
}
}
let
username
,
message
;
let
parsed
=
parseCommand
(
rest
);
let
space
=
rest
.
indexOf
(
'
'
);
if
(
space
<
0
)
{
username
=
rest
;
message
=
null
;
}
else
{
username
=
rest
.
slice
(
0
,
space
);
message
=
rest
.
slice
(
space
+
1
).
trim
();
}
let
id
;
let
id
;
if
(
username
in
users
)
{
if
(
parsed
[
0
]
in
users
)
{
id
=
rest
;
id
=
parsed
[
0
]
;
}
else
{
}
else
{
for
(
let
i
in
users
)
{
for
(
let
i
in
users
)
{
if
(
users
[
i
]
===
username
)
{
if
(
users
[
i
]
===
parsed
[
0
]
)
{
id
=
i
;
id
=
i
;
break
;
break
;
}
}
}
}
}
}
if
(
!
id
)
{
if
(
!
id
)
{
displayError
(
'
Unknown user
'
+
username
);
displayError
(
'
Unknown user
'
+
parsed
[
0
]
);
return
;
return
;
}
}
serverConnection
.
userAction
(
cmd
.
slice
(
1
),
id
,
message
);
serverConnection
.
userAction
(
cmd
.
slice
(
1
),
id
,
parsed
[
1
]
);
return
;
return
;
}
}
default
:
default
:
...
...
webclient.go
View file @
77179c3d
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"errors"
"errors"
"log"
"log"
"os"
"os"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -645,24 +644,6 @@ func startClient(conn *websocket.Conn) (err error) {
...
@@ -645,24 +644,6 @@ func startClient(conn *websocket.Conn) (err error) {
return
return
}
}
if
strings
.
ContainsRune
(
m
.
Username
,
' '
)
{
// at this point, the writer is not running yet, so format
// the message ourselves
conn
.
WriteJSON
(
clientMessage
{
Type
:
"usermessage"
,
Kind
:
"error"
,
Value
:
"don't put spaces in your username"
,
})
conn
.
WriteMessage
(
websocket
.
CloseMessage
,
websocket
.
FormatCloseMessage
(
websocket
.
CloseProtocolError
,
"don't put spaces in your username"
,
),
)
conn
.
Close
()
return
}
c
:=
&
webClient
{
c
:=
&
webClient
{
id
:
m
.
Id
,
id
:
m
.
Id
,
credentials
:
clientCredentials
{
credentials
:
clientCredentials
{
...
...
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