drab v0.4.1 Drab.Client

Enable Drab on the browser side. Must be included in HTML template, for example in web/templates/layout/app.html.eex:

<%= Drab.Client.js(@conn) %>

after the line which loads app.js:

<script src="<%= static_path(@conn, "/js/app.js") %>"></script>

Summary

Functions

Generates JS code which runs Drab. Passes controller and action name, tokenized for safety. Runs only when the controller which renders current action has been compiled with use Drab.Controller

Functions

js(conn, assigns \\ [])

Generates JS code which runs Drab. Passes controller and action name, tokenized for safety. Runs only when the controller which renders current action has been compiled with use Drab.Controller.

Optional argument may be a list of parameters which will be added to assigns to the socket. Example of layout/app.html.eex:

<%= Drab.Client.js(@conn) %>
<%= Drab.Client.js(@conn, user_id: 4, any_other: "test") %>

Please remember that your parameters are passed to the browser as Phoenix Token. Token is signed, but not ciphered. Do not put any secret data in it.

On the browser side, there is a global object Drab, which you may use to create your own channels inside Drab Socket:

ch = Drab.socket.channel("mychannel:whatever")
ch.join()