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
759a39fb
Commit
759a39fb
authored
4 years ago
by
Nils G.
Browse files
Options
Downloads
Patches
Plain Diff
Add websockets to game to retrieve changes in the room without refresh or ajax
parent
f0cd6486
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
controllers/game.py
+9
-2
9 additions, 2 deletions
controllers/game.py
modules/http_util.py
+7
-0
7 additions, 0 deletions
modules/http_util.py
static/renderer/debug.js
+1
-1
1 addition, 1 deletion
static/renderer/debug.js
views/game/index.html
+24
-1
24 additions, 1 deletion
views/game/index.html
with
41 additions
and
4 deletions
controllers/game.py
+
9
−
2
View file @
759a39fb
from
parameter_util
import
JSON_BODY
,
JSON_CONTAINS
from
http_util
import
FAIL
,
CODE_JSON
,
CODE_MISSING
,
CODE_SEMANTIC
,
CODE_GONE
,
CODE_CONFLICT
from
http_util
import
FAIL
,
CODE_JSON
,
CODE_MISSING
,
CODE_SEMANTIC
,
CODE_GONE
,
CODE_CONFLICT
,
GET_HOST
from
room_util
import
ROOM_GET
from
gluon.contrib.websocket_messaging
import
websocket_send
import
json
def
start
():
...
...
@@ -28,7 +30,12 @@ def start():
if
room_record
.
closed
:
return
(
FAIL
(
CODE_GONE
))
db
(
db
.
Room
.
id
==
room_record
.
id
).
update
(
started
=
True
,
roles
=
json
.
dumps
(
roles
))
roles
=
json
.
dumps
(
roles
)
db
(
db
.
Room
.
id
==
room_record
.
id
).
update
(
started
=
True
,
roles
=
roles
)
websocket_send
(
'
http://
'
+
GET_HOST
()
+
'
:8888
'
,
roles
,
'
mykey
'
,
room_record
.
code
)
json_response
=
{
"
status
"
:
"
success
"
}
return
(
response
.
json
(
json_response
))
This diff is collapsed.
Click to expand it.
modules/http_util.py
+
7
−
0
View file @
759a39fb
...
...
@@ -14,3 +14,10 @@ def FAIL(_code):
def
SUCCESS
():
current
.
response
.
status
=
200
return
(
200
)
def
GET_HOST
():
http_host
=
current
.
request
.
env
.
http_host
if
"
:
"
in
http_host
:
http_host
=
http_host
[:
http_host
.
find
(
"
:
"
)]
return
(
http_host
)
This diff is collapsed.
Click to expand it.
static/renderer/debug.js
+
1
−
1
View file @
759a39fb
...
...
@@ -2,7 +2,7 @@ function render(_name, _role, _roles){
if
(
_role
in
_roles
)
{
//TODO: Render role according to definition
$
(
"
#game_content
"
).
html
(
_role
);
$
(
"
#game_content
"
).
html
(
JSON
.
stringify
(
_role
s
)
);
return
;
}
...
...
This diff is collapsed.
Click to expand it.
views/game/index.html
+
24
−
1
View file @
759a39fb
{{include 'include/popup.html'}}
{{ from http_util import GET_HOST }}
<!-- ############################### -->
<!-- #.............................# -->
...
...
@@ -21,6 +22,28 @@
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
(){
render
(
name
,
role
,
{}
);
render
(
name
,
role
,
JSON
.
parse
(
'
{{=XML(room_record.roles)}}
'
)
);
});
//Websocket connection
$
(
document
).
ready
(
function
(){
if
(
'
WebSocket
'
in
window
)
{
var
ws
=
new
WebSocket
(
"
ws://{{=GET_HOST()}}:8888/realtime/{{=room_record.code}}
"
);
ws
.
onopen
=
function
()
{};
ws
.
onmessage
=
function
(
e
){
set_info
(
e
.
data
);
render
(
name
,
role
,
JSON
.
parse
(
e
.
data
));
};
ws
.
onclose
=
function
()
{
set_error
(
"
{{=T('WebSocket has closed')}}. {{=T('Please refresh this website')}}.
"
);
};
}
else
{
/* not supported */
set_error
(
"
{{=T('WebSocket is not supported by your browser')}}.
"
);
}
});
</script>
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