Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Lynchburg Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lynchburg
Lynchburg Server
Commits
abc3ec16
Commit
abc3ec16
authored
4 years ago
by
Nils G.
Browse files
Options
Downloads
Patches
Plain Diff
Move websocket API into seperate python module
parent
759a39fb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
controllers/game.py
+5
-7
5 additions, 7 deletions
controllers/game.py
modules/websocket_util.py
+10
-0
10 additions, 0 deletions
modules/websocket_util.py
views/game/index.html
+5
-2
5 additions, 2 deletions
views/game/index.html
with
20 additions
and
9 deletions
controllers/game.py
+
5
−
7
View file @
abc3ec16
from
parameter_util
import
JSON_BODY
,
JSON_CONTAINS
from
parameter_util
import
JSON_BODY
,
JSON_CONTAINS
from
http_util
import
FAIL
,
CODE_JSON
,
CODE_MISSING
,
CODE_SEMANTIC
,
CODE_GONE
,
CODE_CONFLICT
,
GET_HOST
from
http_util
import
FAIL
,
CODE_JSON
,
CODE_MISSING
,
CODE_SEMANTIC
,
CODE_GONE
,
CODE_CONFLICT
from
room_util
import
ROOM_GET
from
room_util
import
ROOM_GET
from
websocket_util
import
WEBSOCKET_SEND
from
gluon.contrib.websocket_messaging
import
websocket_send
import
json
import
json
...
@@ -24,8 +23,8 @@ def start():
...
@@ -24,8 +23,8 @@ def start():
if
not
room_record
:
if
not
room_record
:
return
(
FAIL
(
CODE_SEMANTIC
))
return
(
FAIL
(
CODE_SEMANTIC
))
if
room_record
.
started
:
#
if room_record.started:
return
(
FAIL
(
CODE_CONFLICT
))
#
return(FAIL(CODE_CONFLICT))
if
room_record
.
closed
:
if
room_record
.
closed
:
return
(
FAIL
(
CODE_GONE
))
return
(
FAIL
(
CODE_GONE
))
...
@@ -34,8 +33,7 @@ def start():
...
@@ -34,8 +33,7 @@ def start():
db
(
db
.
Room
.
id
==
room_record
.
id
).
update
(
started
=
True
,
roles
=
roles
)
db
(
db
.
Room
.
id
==
room_record
.
id
).
update
(
started
=
True
,
roles
=
roles
)
WEBSOCKET_SEND
(
room_record
,
"
roles
"
,
roles
)
websocket_send
(
'
http://
'
+
GET_HOST
()
+
'
:8888
'
,
roles
,
'
mykey
'
,
room_record
.
code
)
json_response
=
{
"
status
"
:
"
success
"
}
json_response
=
{
"
status
"
:
"
success
"
}
return
(
response
.
json
(
json_response
))
return
(
response
.
json
(
json_response
))
This diff is collapsed.
Click to expand it.
modules/websocket_util.py
0 → 100644
+
10
−
0
View file @
abc3ec16
from
gluon
import
*
from
gluon.contrib.websocket_messaging
import
websocket_send
from
http_util
import
GET_HOST
def
WEBSOCKET_SEND
(
_room
,
_type
,
_data
):
websocket_send
(
'
http://
'
+
GET_HOST
()
+
'
:8888
'
,
_data
,
'
67c371fd204fbcbf9742310d1a9d951bcca1aa86
'
,
_room
.
code
)
def
GET_URL
(
_room
):
return
(
"
ws://
"
+
GET_HOST
()
+
"
:8888/realtime/
"
+
_room
.
code
)
This diff is collapsed.
Click to expand it.
views/game/index.html
+
5
−
2
View file @
abc3ec16
{{include 'include/popup.html'}}
{{include 'include/popup.html'}}
{{ from
http
_util import GET_
HOST
}}
{{ from
websocket
_util import GET_
URL
}}
<!-- ############################### -->
<!-- ############################### -->
<!-- #.............................# -->
<!-- #.............................# -->
...
@@ -30,12 +30,15 @@
...
@@ -30,12 +30,15 @@
$
(
document
).
ready
(
function
(){
$
(
document
).
ready
(
function
(){
if
(
'
WebSocket
'
in
window
)
{
if
(
'
WebSocket
'
in
window
)
{
var
ws
=
new
WebSocket
(
"
ws://
{{=GET_
HOST()}}:8888/realtime/{{=
room_record
.code
}}
"
);
var
ws
=
new
WebSocket
(
"
{{=GET_
URL(
room_record
)
}}
"
);
ws
.
onopen
=
function
()
{};
ws
.
onopen
=
function
()
{};
ws
.
onmessage
=
function
(
e
){
ws
.
onmessage
=
function
(
e
){
set_info
(
e
.
data
);
set_info
(
e
.
data
);
render
(
name
,
role
,
JSON
.
parse
(
e
.
data
));
render
(
name
,
role
,
JSON
.
parse
(
e
.
data
));
};
};
ws
.
onerror
=
function
(
e
)
{
set_error
(
"
{{=T('Error')}}:
"
+
e
);
};
ws
.
onclose
=
function
()
{
ws
.
onclose
=
function
()
{
set_error
(
"
{{=T('WebSocket has closed')}}. {{=T('Please refresh this website')}}.
"
);
set_error
(
"
{{=T('WebSocket has closed')}}. {{=T('Please refresh this website')}}.
"
);
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment