Skip to content

use laravel echo server in react native client #15474

@mohsen158

Description

@mohsen158

I want to use laravel echo server in react native app
but I think something is wrong that I don't know what is it
I get this error in my log

undefined is not an object (evaluating 'this.connector.channel')
channel
D:\react-native\taav\node_modules\laravel-echo\dist\echo.js:750:34
componentDidMount

it is my 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'];
}

}

that I know my laravel server is correct because I can use correctly my socket in browser

and my react native code:

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()

        })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: For Stack OverflowA question for Stack Overflow. Applying this label will cause issue to be closed.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions