drsdvwsvo78320812 2019-08-14 06:52
浏览 251

Quasar Vue Socket.io Laravel-Echo实施

Im using quasar framework and trying to add laravel-echo with socket.io. Socket server is up and running and broadcasting event with no issues.

But for some reason my client side does not want to connect it keeps giving me error that cannot read property 'channel' of undefined.

My Setup

package.json

"laravel-echo": "^1.5.4",
"quasar": "^1.0.5",
"socket.io-client": "^2.2.0",

boot/laravel-echo.js

import Echo from 'laravel-echo'

window.io = require('socket.io-client')

const echo = new Echo({
    broadcaster: 'socket-io',
    host: window.location.hostname + ':6001'
})

export default ({ Vue }) => {
    Vue.prototype.$echo = echo
}

quasar.conf.js

boot: [
    'axios',
    'laravel-echo'
],

index.vue

created () {
    this.listen()
},
methods: {
    listen() {
       this.$echo.channel('test').listen('event', payload => {
          console.log('THIS IS THE PAYLOAD: ' + payload)
       })
    }
}

Browser

[Vue warn]: Error in created hook: "TypeError: Cannot read property 'channel' of undefined"

found in

---> <AllEvents>
   <QPage>
      <DashboardIndex> at src/pages/dashboard/Index.vue
         <QPageContainer>

Socket.io

L A R A V E L  E C H O  S E R V E R

version 1.5.6

⚠ Starting server in DEV mode...

✔  Running at localhost on port 6001
✔  Channels are ready.
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

Channel: test
Event: event

I have even change the code to the same as in the laravel documentation (https://laravel.com/docs/5.8/broadcasting#receiving-broadcasts) with window.Echo

import Echo from 'laravel-echo'

window.io = require('socket.io-client')

window.Echo = new Echo({
  broadcaster: 'socket-io',
  host: window.location.hostname + ':6001'
})

export default async ({ Vue }) => {
}

and trying to connect to channel

window.Echo.channel('test').listen('event', payload => {
    console.log('Here')
    console.log(payload)
})

but still getting the same error on the browser, not sure what im missing here, any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongzhong8834 2019-08-14 07:38
    关注

    :( uh man, what a noob,

    Should be

    broadcaster: 'socket.io',
    

    and not

    broadcaster: 'socket-io',
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题