socketbus-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

SocketBus JavaScript Client

Getting Started

  1. Install the client
npm install socketbus-js --save

Create a SocketBus instance

import SocketBus from 'socketbus-js';

const socketBus = new SocketBus({
    // SocketBus' public key
    app_id: 'my-public-key',
    
    // Endpoint to authenticate channels
    authEndpoint: '/channels/auth',

    // Application namespace
    namespace: '',

    // User id to be able to send event to all but the sender
    user_id: null,

    // Event fired on Connect
    onConnect: () => {

    },

    // Function to parse all registred events
    formatEventName: (event, options) => {

    }
})

Laravel Echo

import { SocketBusLaravel } from "socketbus-js";
import LaravelEcho from "laravel-echo";

window.Echo = SocketBusLaravel(LaravelEcho, {
    app_id: 'my-app-id'
});

Echo.private('foods')
    .listen('NewFoodEvent', (payload) => {
        // code
    })

Joining Channels

const foodsChannel = socketBus.private('foods')
    .listen('new-food', (payload) => { /** callback */ })
    .listen('food-status', (payload) => { /** callback */ })

Leaving Channels

foodsChannel.leave()

End-to-end encryption

Socket-to-socket communication

foodsChannel.emit('new-food', {
    food: 'cupcake'
});

Whispering

Whispers are messages up to 128 bytes, that doesn't require Socket-to-socket communication to be enabled.

foodsChannel.whisper('food-status', 'hot');

Custom Authentication

Readme

Keywords

none

Package Sidebar

Install

npm i socketbus-js

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

573 kB

Total Files

55

Last publish

Collaborators

  • valterlorran