mardi 21 août 2018

connecting on private-channel.1 but not on private-channel.2 - Laravel-echo-server

I am facing very strange issue that i can not just understand.

I am using vue and laravel for my application and they both are running independently on different port. And i am using laravel as apis.

const tokenData = JSON.parse(window.localStorage.getItem('authUser'))
if (tokenData !== null) {
  console.log(tokenData.token)
  window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://localhost:6001',
    auth: {
      headers: {
        'Authorization': 'Bearer ' + tokenData.token
      }
    }
  })

  store.watch(
    // When the returned result changes...
    function (state) {
      return state.userStore.authUser.user_id
    },
    // Run this callback
    (userId) => {
      window.Echo.private(`cchannel.${userId}`)
        .listen('ChatMessage', (e) => {
          console.log(e)
        })
    }
  )
}

I am using api service so i have to use auth header to authenticate using on private channel.

And getting user_id using vuex and then finally creating dynamic channel for individual user as shown in code.

What i am getting in my terminal is

[22:38:55] - kAUI5s8ytJ6t39dSAAAB authenticated for: private-cchannel.1
[22:38:55] - kAUI5s8ytJ6t39dSAAAB joined channel: private-cchannel.1
[22:39:03] - kAUI5s8ytJ6t39dSAAAB left channel: private-cchannel.1 (transport close)
⚠ [22:39:04] - WsvwWe7spHCuKXyjAAAC could not be authenticated to private-cchannel.3

user id having 1 is able to authenticate on private-cchannel.1, but user id 3 is not with the same.

How is that happening?

I tried giving static channel name like cchannel.1 this is connecting but when i am changing to cchannel.2 it's not.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire