我想在反应本机应用程序中使用 laravel 回显服务器,但我认为出了点问题,我不知道是什么我在日志中收到此错误
undefined 不是对象(评估 'this.connector.channel')通道 D:\react-native\taav\node_modules\laravel-echo\dist\echo.js:750:34 componentDidMount
这是我的 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()
})
}