Closed jlsjonas closed 5 years ago
Please share more context about what you're suggesting
I want to send custom events to the user (App.user.<userid>
channel) that would trigger custom client-side code (f.e. downloading a generated document without extra interaction with the notification system)
With the current location of the App.user.<userid>
channel's Echo declaration the only workaround I see is to add custom listeners to it in Notifications.vue
or exposing it on the window or something.
The best approach would probably be to add Echo-related code to VueX with a few actions to add listeners. IO.vue could also use this echo instance instead of maintaining it's completely separate connection.
Rough outline:
store/echo.js
that initialises a new Echo (just as in initEcho
) during store setup
private
-like action to add new channelsApp.User.<userid>
channel right away, exposing it (other channel listeners could directly interact with the exposed echo instance; as they're less likely to be used besides the component they're initialised in)listen()
in Notifications.vue
would call an action to set up the [(*a)channel &] listeners insteadIO.vue
or (b) IO.vue
would no longer need to initEcho()
and just listen()
using the exposed echo instanceSounds good. I'll look into it.
I couldn't make echo
a store prop because apparently the object is mutated internally by Pusher and that triggers vuex errors.
Ah, so we'll have to stick to multiple connections (or patching)? That sucks 😅
This is a feature request.
Prerequisites
yes
Description
To avoid multiple simultaneous websocket connections to the server for the same purpose (sending events to a specific user)
this.echo.private(
App.User.${this.user.id})
, currently residing in Notifications.vue should be exposed more globally (state? injected from root?)Use case
Custom event that triggers a client-side action, user-specific.
Current workaround
Patching
Notifications.vue
to include custom listeners, breaking separation or establishing & maintaining multiple connections to the same channel