enso-ui / ui

Laravel Enso UI
MIT License
9 stars 10 forks source link

Expose App.User's echo #13

Closed jlsjonas closed 5 years ago

jlsjonas commented 5 years ago

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

aocneanu commented 5 years ago

Please share more context about what you're suggesting

jlsjonas commented 5 years ago

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:

aocneanu commented 5 years ago

Sounds good. I'll look into it.

aocneanu commented 5 years ago

I couldn't make echo a store prop because apparently the object is mutated internally by Pusher and that triggers vuex errors.

jlsjonas commented 5 years ago

Ah, so we'll have to stick to multiple connections (or patching)? That sucks 😅