Created
March 29, 2016 18:11
-
-
Save johngrantuk/fbd250a777c24e139e10f9c6d00a5b62 to your computer and use it in GitHub Desktop.
Django Channels javascript example
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
$(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