1.2.0 • Published 5 years ago

nativescript-laravel-echo v1.2.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
5 years ago

NativeScript Laravel-Echo

npm npm

NPM

This is a laravel-echo plugin for native applications made with nativescript

For more information read Laravel Broadcast.

Prerequisites / Requirements

Necesary api authentication in your laravel backend application.

Modify the file where the following line Broadcast::routes()

Example in app/Providers/BroadcastServiceProvider.php

class BroadcastServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Broadcast::routes(['middleware' => 'auth:api']);
        require base_path('routes/channels.php');
    }
}

Installation

Describe your plugin installation steps. Ideally it would be something like:

$ tns plugin add nativescript-laravel-echo

Usage

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class Event implements ShouldBroadcast
{
    /**
     * Information about the shipping status update.
     *
     * @var string
     */
    public $data; //data show in console.dir as data
}

Javascript

const TnsEcho = require('nativescript-laravel-echo').TnsEcho;

const token = 'Asdsd3dsdsTytf';//Your token

const options = {
    //....
    broadcaster: 'socket.io',// pusher,
    headers: {
        auth: {
            bearer: `Bearer ${token}`
        }
    }
}

const Echo = new TnsEcho(options)

Echo.channel('YourChannel').listen('Event', e => {
    console.dir(e)
})

//presence channel for others
const http = require('tns-core-modules/http');

http.request({
    //....
    headers: {
        //...
        'X-Socket-Id': Echo.socketId() // get socket id
    }
});

TypeScript

import { TnsEcho } from 'nativescript-laravel-echo';

const token = 'Asdsd3dsdsTytf';//Your token

const options = {
    //....
    broadcaster: 'socket.io',// pusher,
    headers: {
        auth: {
            bearer: `Bearer ${token}`
        }
    }
}

this.Echo = new TnsEcho(options)

this.Echo.channel('YourChannel').listen('Event', e => {
    console.dir(e)
})

//presence channel for others
import * as http from 'tns-core-modules/http';

http.request({
    //....
    headers: {
        //...
        'X-Socket-Id': this.Echo.socketId() // get socket id
    }
})

Options

These are each of the parameters that can go in the object options.

PropertyDefaultDescription
broadcasterpusherDriver for broadcast pusher or socket.io
hostnullYour host only socket.io
authEndpoint/broadcasting/authYour auth endpoint only for Pusher
keynullYour api key of Pusher App
clusternullYour cluster of Pusher App
authauth:{headers:{}}Necesary in private an presence channel's with Authorization header
namespaceApp.EventsThe namespace backend events
debugfalseEnable debug only socket.io broadcaster
forceWebsocketsfalseForce WebSockets

License

Apache License Version 2.0, January 2004

1.2.0

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago