rails generate channel MatestackUiVueJsChannel
.app/javascript/channels/matestack_ui_vue_js_channel.js
file where you can setup your subscriptions.MatestackUiVueJsChannel < ApplicationCable::Channel
class.matestack_ui_vue_js_channel.js
is responsible to create a subscription to the "MatestackUiVueJsChannel".MatestackUiVueJs.eventHub
with the received data.app/javascript/channels/matestack_ui_vue_js_channel.js
matestack_ui_vue_js_channel.js
yourself in app/javascript/channels/
and paste the above code in it.async
/isolated components or show/hide content with the toggle
component. We will introduce two different types of creating server side events. First broadcasting events to all subscribed clients and secondly sending events to a user by authenticating a connection through a devise user.app/channels/matestack_ui_core_channel.rb
. If not create it now. Inside it we define that every subscriber of this channel should stream from the "matestack-ui-core" channel, which means that anything transmitted by a publisher to this channel is direcetly routed to the channel subscribers.ApplicationCable::Connection
to identify connections by a current user.current_user
. We check if a user is signed in by accessing env['warden'].user
which gets set when a user is successfully authenticated. If env['warden'].user
is not set we reject the connection.reject_unauthorized_connection
call from our connection.reject
unless a current_user
is present.received(data)
callback and have a clear structure to determine what the name of the event is which should be emitted. Like shown above we recommend using an :event
key in your websocket broadcast, which represents the event name that gets emitted through the event hub. You optionally can pass all the received data as payload to that event or also use a specific key. As this is optional you don't need to pass any data to the event emit.