-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
94 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
from channels.staticfiles import StaticFilesConsumer | ||
from chat.consumers import ws_connect, ws_receive | ||
|
||
channel_routing = { | ||
# This makes Django serve static files from settings.STATIC_URL, similar | ||
# to django.views.static.serve. This isn't ideal (not exactly production | ||
# quality) but it works for a minimal example. | ||
'http.request': StaticFilesConsumer() | ||
'http.request': StaticFilesConsumer(), | ||
|
||
'websocket.connect': ws_connect, | ||
'websocket.receive': ws_receive, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
def ws_connect(message): | ||
log.debug('ws_connect path={path}'.format(**message.content)) | ||
|
||
def ws_receive(message): | ||
log.debug('ws_receive text={text}'.format(**message.content)) | ||
message.reply_channel.send({'text': message['text']}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
$(function() { | ||
// When we're using HTTPS, use WSS too. | ||
var ws_scheme = window.location.protocol == "https:" ? "wss://" : "ws://"; | ||
|
||
var chatsock = new ReconnectingWebSocket(ws_scheme + location.host + "/chat"); | ||
chatsock.onmessage = function(message) { | ||
alert(message.data); | ||
}; | ||
|
||
$("#go").on("click", function(event) { | ||
chatsock.send($("#message")[0].value); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
hi | ||
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{% block content %}{% endblock content %} | ||
{% block content %}{% endblock content %} | ||
|
||
{% block afterbody %}{% endblock afterbody %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>{{ room.label }}</h1> | ||
<table> | ||
{% for message in messages %} | ||
<tr> | ||
<td>{{ message.timestamp }}</td> | ||
<td>{{ message.username }}</td> | ||
<td>{{ message.message }}</td> | ||
</tr> | ||
{% endfor %} | ||
{% load staticfiles %} | ||
<h1>{{ room.label }}</h1> | ||
<table> | ||
{% for message in messages %} | ||
<tr> | ||
<td>Say something:</td> | ||
<td><input id="username" type="text" placeholder="your name"></td> | ||
<td> | ||
<input id="message" type="text" placeholder="message"> | ||
<button id="go">Say it</button> | ||
</td> | ||
</table> | ||
{% endblock content %} | ||
<td>{{ message.timestamp }}</td> | ||
<td>{{ message.username }}</td> | ||
<td>{{ message.message }}</td> | ||
</tr> | ||
{% endfor %} | ||
<tr> | ||
<td>Say something:</td> | ||
<td><input id="username" type="text" placeholder="your name"></td> | ||
<td> | ||
<input id="message" type="text" placeholder="message"> | ||
<button id="go">Say it</button> | ||
</td> | ||
</table> | ||
{% endblock content %} | ||
|
||
{% block afterbody %} | ||
<script type="text/javascript" src='{% static "jquery-1.12.1.min.js" %}'></script> | ||
<script type="text/javascript" src='{% static "reconnecting-websocket.min.js" %}'></script> | ||
<script type="text/javascript" src='{% static "chat.js" %}'></script> | ||
{% endblock afterbody %} |