Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast To Others Is not working as it Listens to my on Events #57

Closed
mwangaben opened this issue Nov 10, 2024 · 1 comment
Closed

Comments

@mwangaben
Copy link

mwangaben commented Nov 10, 2024

With laravel Echo on Website platform (Vuejs) a header is added on axios to tell the pusher server who is the owner of the newly created event and when it comes to broadcast you can opt not to listen to your own events.

On the website this is how it is done

  axios.headers['X-Socket-Id'] = window.Echo.socketId()

I need to put something like soket-id on the headers under Diointerceptor to send the soket_id long side the HTTP request to the server to know my socket_id and stop broadcasting to me since i am the creator of the event as i do not need to be notified.

class DioInterceptor extends Interceptor {
@override
void onRequest(
    RequestOptions options, RequestInterceptorHandler handler) async {
  final accessToken = AppStore.getAccessToken();
  if (accessToken != null) {
    options.headers['Authorization'] = 'Bearer $accessToken';
  }

  options.headers['X-Socket-Id'] = SoketID()
  options.headers['Content-Type'] = 'application/json';
  super.onRequest(options, handler);
}
}

@mwangaben mwangaben changed the title Broadcast To Others Is not working as it broadcast to the My own Events Broadcast To Others Is not working as it Listens to my on Evenets Nov 11, 2024
@mwangaben mwangaben changed the title Broadcast To Others Is not working as it Listens to my on Evenets Broadcast To Others Is not working as it Listens to my on Events Nov 13, 2024
@mwangaben
Copy link
Author

Finally after source diving on the source of this package i have come resolve my issue by using the master repository instead of the current on the flutter packages website as below which does not reflects the new merged #51 which exposes socket_id

     dart_pusher_channels:
     git: [email protected]:kerimamansaryyev/dart_pusher_channels.git

On the DioInterceptor

 class DioInterceptor extends Interceptor {
     @override
     void onRequest(
            RequestOptions options, RequestInterceptorHandler handler) async {
            final accessToken = AppStore.getAccessToken();
            if (accessToken != null) {
                 options.headers['Authorization'] = 'Bearer $accessToken';
            }

          options.headers['X-Socket-Id'] =  liveWire.client.socketId;
          options.headers['Content-Type'] = 'application/json';
          super.onRequest(options, handler);
    }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant