【发布时间】:2018-01-20 23:18:27
【问题描述】:
我想在 react native 应用中使用 laravel echo server 但我觉得有什么不对劲,我不知道是什么 我的日志中出现此错误
undefined 不是一个对象(评估 'this.connector.channel') 渠道 D:\react-native\taav\node_modules\laravel-echo\dist\echo.js:750:34 组件DidMount
这是我的 laravel
class updateStatus implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $activity;
public function __construct( Activity $a)
{
//
$this->activity=$a;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return ['channel'];
}
}
我知道我的 laravel 服务器是正确的,因为我可以在浏览器中正确使用我的套接字
和我的反应原生代码:
import React, {Component} from 'react';
import Echo from "laravel-echo"
import io from 'socket.io-client/dist/socket.io';
export default class Activities extends Component {
constructor(props) {
super(props)
this.btnadd = this.btnadd.bind(this)
this.SearchMethod = this.SearchMethod.bind(this)
this.socket = io('http://'.concat(server).concat(':6001'), {json: false})
}
componentDidMount() {
var echo = window.Echo = new Echo({
broadcaster: 'io',
host: 'http://'.concat(server).concat(':6001')
});
window.Echo.channel('channel')
.listen('updateStatus', (e) => {
// this.additem()
})
}
【问题讨论】:
标签: javascript laravel react-native laravel-echo