Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Created a websocket api so you can build site/module specific ws handlers #454

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
2 participants
Owner

mmzeeman commented Nov 12, 2012

See documentation for more information.

Owner

arjan commented Nov 12, 2012

That looks nice!

Maybe some more docs, e.g. including the -module() header and exports in the example handler.
And, how do you send information to the socket proces? Would be nice to have the interval in the example stream the "hello" to the browser.

Owner

mmzeeman commented Nov 12, 2012

Basically you just send a message {send_data, <<"data">} to the websocket process. But you are right, that needs to be documented.

Owner

arjan commented Nov 13, 2012

From an OTP view you would expect that {send_data, _} to be handled by the websocket_info callback function? Or is it intercepted earlier in the process..

Owner

mmzeeman commented Nov 13, 2012

It is handled in the send_loop of the websocket process. This is also where the info messages are picked up. I didn't change this part as it is currently in use by z_session_page to send scripts to the client. z_session_page sends {send_message, Data} message's to the websocket pid to make that happen.

You can of course send data over the websocket in the websocket_info callback by doing self() ! {send_message. Data}

It is probably nice to define the function below in controller_websocket.

% @doc Send data over websocket.
send_data(Data) ->
    send_data(self(), Data).

% @doc Send data to the user over the specified websocket.
send_data(Pid, Data) ->
    Pid ! {send_data, Data). 
Owner

arjan commented Dec 4, 2012

I think this is good to merge, if you document the sending of messages to the WS proces somewhere, as that is quite a handy feature :)

👍

Owner

mmzeeman commented Dec 14, 2012

The sending of data is documented here: mmzeeman/zotonic@ceb7155

@mmzeeman mmzeeman closed this in eca4fb8 Dec 14, 2012

Owner

arjan commented Dec 14, 2012

I took the liberty to rebase this to master, fix the documentation errors, squash everything in one commit, and commit it under your name ;-)

rpip pushed a commit to rpip/zotonic that referenced this pull request Aug 12, 2013

mod_base: Created a pluggable controller_websocket API
This way you can override the default behaviour.

Fixes #454

Squashed commit of the following:

commit cba46d210dc9628b42c39766ace03b48bbf6d337
Author: Arjan Scherpenisse <arjan@scherpenisse.net>
Date:   Fri Dec 14 20:56:48 2012 +0100

    controller WS tweaks

commit a88c2959fb7cb186ca13edd770e6014478d014ba
Author: Maas-Maarten Zeeman <mmzeeman@xs4all.nl>
Date:   Mon Dec 3 09:46:32 2012 +0100

    Fix websocket handshakes

commit a463f58a505f8f8748ad4ea324b6578c12d12d39
Author: Maas-Maarten Zeeman <mmzeeman@xs4all.nl>
Date:   Wed Nov 14 23:31:56 2012 +0100

    Added api to send messages over a websocket

commit 5b12a931c90a1619165e55aa575ed8e6237c23a2
Author: Maas-Maarten Zeeman <mmzeeman@xs4all.nl>
Date:   Fri Nov 9 12:06:07 2012 +0100

    Created a pluggable websocket api so you can override the default behaviour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment