Skip to content

Instantly share code, notes, and snippets.

@johngrantuk
Created March 29, 2016 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngrantuk/fbd250a777c24e139e10f9c6d00a5b62 to your computer and use it in GitHub Desktop.
Save johngrantuk/fbd250a777c24e139e10f9c6d00a5b62 to your computer and use it in GitHub Desktop.
Django Channels javascript example
$(function() {
// When we're using HTTPS, use WSS too.
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
var chatsock = new ReconnectingWebSocket(ws_scheme + '://' + window.location.host + "/sensor/");
chatsock.onopen = function() {
console.log("Connected!");
$('#sensor').text("Connected!");
chatsock.send("Connected!");
};
chatsock.onmessage = function(message) {
console.log("Received Sock message!");
console.log(message);
$('#sensor').text(message.data);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment