happones / nativescript-laravel-echo

A nativescript plugin for laravel-echo
Apache License 2.0
10 stars 2 forks source link

Broadcast toOthers() issue #7

Closed lord-zeus closed 5 years ago

lord-zeus commented 5 years ago

When broadcasting to others you end up still receiving the the broadcast any help on this ?

happones commented 5 years ago

Try the new version

lord-zeus commented 5 years ago

it works when I use it this way axios.defaults.headers.common['X-Socket-Id'] = Echo.socketId();

lord-zeus commented 5 years ago

when the X-Socket-Id is being place and I navigate out of that component and back into the component the it start receiving the broadcast to others.

each time I get into that page I leave that channel before re-entering it back any ideas ?

lord-zeus commented 5 years ago

Echo.leave('channel-name'); almost like the channel is not being left

happones commented 5 years ago

Hello, you can share more information about your case, such as the NS version and the plugin, at which moment you launch the events of join andleave, greetings.

lord-zeus commented 5 years ago

lets say I have two component Home & Chat

I leave from the home to the chat where the join and the leave are

mounted(){ const Echo = new TnsEcho({ host: url, authEndpoint: '/broadcasting/auth', broadcaster: 'socket.io', debug: false, auth: { headers: { Authorization: 'Bearer ' + token } }, }); setTimeout(() => { Echo.socketId(); axios.defaults.headers.common['X-Socket-Id'] = Echo.socketId(); }, 1000);//half second for get socket id, only socket.io Echo.leave('chat_id'); Echo.private('chat_id') .listen('ChatEvent', (chat) => { .... console.log(chat);

                 `});`

},

but it does not leave the channel each time it enter the chat component it just creates a new channel with a new socket id there by causing the application to listen to its own broadcast()->toOthers

happones commented 5 years ago

You're using the versión 1.0.3?

lord-zeus commented 5 years ago

You're using the versión 1.0.3?

yes I thought it was the problem so I updated to it but still has same problem

happones commented 5 years ago

try this

export default {
   data() {
      return {
         echo: null,
         channel: ''
      }
   },
   mounted() {
      this.channel = 'MiChannel';
      this.echo = new Echo(options);
       this.echo.join(this.channel)
                .here((users) => {
                    console.log(users);
                })
                .joining((user) => {

                })
                .leaving((user) => {

                })
                .listen('Event', (e) => {

                });
   },
   destroyed() {
      this.echo.leave(this.channel);
   }
}
dungfv commented 5 years ago

I have same problem, i can't get socketId. Seem, this.echo.socketId() not working. I catch error JS: [TypeError: Cannot read property 'id' of undefined]

dungfv commented 5 years ago

In the connector socketio-connector.js, this.socket.socket.id() is undefined. It should be this.socket.android.id() or this.socket.ios.id() depending on the platform

happones commented 5 years ago

I work on the solution these days

dungfv commented 5 years ago

Any new information about this issue?

happones commented 5 years ago

Ready uploading