rails generate channel MatestackUiCoreChannel.
MatestackUiCoreChannel < ApplicationCable::Channelclass.
matestack_ui_core_channel.jsis responsible to create a subscription to the "MatestackUiCoreChannel".
MatestackUiCore.eventHubwith the received data.
async/isolated components or show/hide content with the
togglecomponent. 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::Connectionto identify connections by a current user.
current_user. We check if a user is signed in by accessing
env['warden'].userwhich gets set when a user is successfully authenticated. If
env['warden'].useris not set we reject the connection.
reject_unauthorized_connectioncall from our connection.
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
:eventkey 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.