I have this in routing.py for django-channels
channel_routing = [
# Wire up websocket channels to our consumers:
route("websocket.connect", ws_connect),
route("websocket.receive", ws_message),
]
and the ws_connect looks like this
@channel_session
def ws_connect(message, key):
# Accept connection
message.reply_channel.send({"accept": True})
and when the page loads this socket connection is made correctly
<script type="text/javascript">
// Note that the path doesn't matter for routing; any WebSocket
// connection gets bumped over to WebSocket consumers
socket = new WebSocket("ws://" + window.location.host + "/chat/");
socket.onmessage = function(response) {
console.log(response.data);
}
socket.onopen = function() {
socket.send({"test":"data"});
}
// Call onopen directly if socket is already open
if (socket.readyState == WebSocket.OPEN) socket.onopen();
</script>
I want to start testing if I can have a background process running from this, so I set a test json input to socket.send however I haven't found anything on the documentation, apologies if I missed it. How to access this info in ws_connect it should be in message same way there's request I believe.