Hi,

I don't keep track of stack overflow so I don't know if anybody else would
answer stuff there.

Secondly, I replied to a very similar question you asked on this list last
week - is this the same problem as that?

Andrew

On Mon, Sep 4, 2017 at 1:45 AM, Samuel Muiruri <[email protected]>
wrote:

> According to django-channels' github any "help" related issue should be
> posted here, I've asked this question before here and on stack with no
> response, don't feel the need to but if I don't get an adequate response I
> might need to hire a dev to implement this for me.
>
> I have this code for a socket connection
>
> 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();
>
> works nicely and connects to this route (even though it's supposed to look
> for /chat/ but I can work on setting this later)
>
> from gallery.consumers import ws_connect, ws_message
>
> channel_routing = [
>    # Wire up websocket channels to our consumers:
>    route("websocket.connect", ws_connect),
>    route("websocket.receive", ws_message),
> ]
>
> and in the consumers file
>
> import json
> from channels import Group
> from channels.sessions import channel_session
>
> # Connected to websocket.connect
> @channel_session
> def ws_connect(message, key):
>     # Accept connection
>     message.reply_channel.send({"accept": True})
>
> # Connected to websocket.receive
> @channel_session
> def ws_message(message, key):
>     reply = json.dumps({'status':'ok'})
>     message.reply_channel.send({"text": reply})
>
> # Connected to websocket.disconnect
> @channel_session
> def ws_disconnect(message, key):
>     message.reply_channel.send({'accept': False})
>
> first hurdle I need to get over is getting the data sent via sockets i.e.
>
> socket.onopen = function() {
>     socket.send({"test":"data"});
> }
>
> then I can move to having this trigger a background process so I can send
> the status and finally the final result via sockets.
>
> --
>
> Best Regards,
>
> Samuel Muiruri.
>
> Web Designer | +254 738 940064
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAJZFZXoiq3WQ5zaXGMSxYpAfCREqQ
> tC-73yTL8-9OED9vA0m4Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJZFZXoiq3WQ5zaXGMSxYpAfCREqQtC-73yTL8-9OED9vA0m4Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1urLEz5B6Zqzj-RuL%2BpS3LD00J-eD_XBhPM7U34xjz_VCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to