laravel-echo

  • Version 2.1.6
  • Published
  • 304 kB
  • No dependencies
  • MIT license

Install

npm i laravel-echo
yarn add laravel-echo
pnpm add laravel-echo

Overview

Laravel Echo library for beautiful Pusher and Socket.IO integration

Index

Classes

class Channel

abstract class Channel {}
  • This class represents a basic channel.

property options

options: EchoOptionsWithDefaults<BroadcastDriver>;
  • The Echo options.

method error

abstract error: (callback: CallableFunction) => this;
  • Register a callback to be called anytime an error occurs.

method listen

abstract listen: (event: string, callback: CallableFunction) => this;
  • Listen for an event on the channel instance.

method listenForWhisper

listenForWhisper: (event: string, callback: CallableFunction) => this;
  • Listen for a whisper event on the channel instance.

method notification

notification: (callback: CallableFunction) => this;
  • Listen for an event on the channel instance.

method stopListening

abstract stopListening: (event: string, callback?: CallableFunction) => this;
  • Stop listening to an event on the channel instance.

method stopListeningForWhisper

stopListeningForWhisper: (event: string, callback?: CallableFunction) => this;
  • Stop listening for a whisper event on the channel instance.

method subscribed

abstract subscribed: (callback: CallableFunction) => this;
  • Register a callback to be called anytime a subscription succeeds.

class Connector

abstract class Connector<
TBroadcastDriver extends BroadcastDriver,
TPublic extends Channel,
TPrivate extends Channel,
TPresence extends PresenceChannel
> {}

    constructor

    constructor(
    options:
    | (GenericOptions<'reverb'> & Partial<CustomOmit<any, 'cluster'>>)
    | (GenericOptions<'pusher'> & Partial<any>)
    | (GenericOptions<'ably'> & Partial<any>)
    | GenericOptions<'socket.io'>
    | GenericOptions<'null'>
    );
    • Create a new class instance.

    property options

    options: EchoOptionsWithDefaults<TBroadcastDriver>;
    • Connector options.

    method channel

    abstract channel: (channel: string) => TPublic;
    • Get a channel instance by name.

    method connect

    abstract connect: () => void;
    • Create a fresh connection.

    method csrfToken

    protected csrfToken: () => null | string;
    • Extract the CSRF token from the page.

    method disconnect

    abstract disconnect: () => void;
    • Disconnect from the Echo server.

    method leave

    abstract leave: (channel: string) => void;
    • Leave the given channel, as well as its private and presence variants.

    method leaveChannel

    abstract leaveChannel: (channel: string) => void;
    • Leave the given channel.

    method presenceChannel

    abstract presenceChannel: (channel: string) => TPresence;
    • Get a presence channel instance by name.

    method privateChannel

    abstract privateChannel: (channel: string) => TPrivate;
    • Get a private channel instance by name.

    method setOptions

    protected setOptions: (options: EchoOptions<TBroadcastDriver>) => void;
    • Merge the custom options with the defaults.

    method socketId

    abstract socketId: () => string | undefined;
    • Get the socket_id of the connection.

    class Echo

    class Echo<T extends keyof Broadcaster> {}
    • This class is the primary API for interacting with broadcasting.

    constructor

    constructor(
    options:
    | (GenericOptions<'reverb'> & Partial<CustomOmit<any, 'cluster'>>)
    | (GenericOptions<'pusher'> & Partial<any>)
    | (GenericOptions<'ably'> & Partial<any>)
    | GenericOptions<'socket.io'>
    | GenericOptions<'null'>
    | GenericOptions<'function'>
    );
    • Create a new class instance.

    property connector

    connector:
    | PusherConnector<'reverb'>
    | PusherConnector<'pusher'>
    | SocketIoConnector
    | NullConnector;
    • The broadcasting connector.

    property options

    options:
    | (GenericOptions<'reverb'> & Partial<CustomOmit<any, 'cluster'>>)
    | (GenericOptions<'pusher'> & Partial<any>)
    | (GenericOptions<'ably'> & Partial<any>)
    | GenericOptions<'socket.io'>
    | GenericOptions<'null'>
    | GenericOptions<'function'>;
    • The Echo options.

    method channel

    channel: (channel: string) => Broadcaster[T]['public'];
    • Get a channel instance by name.

    method connect

    connect: () => void;
    • Create a new connection.

    method disconnect

    disconnect: () => void;
    • Disconnect from the Echo server.

    method encryptedPrivate

    encryptedPrivate: (channel: string) => Broadcaster[T]['encrypted'];
    • Get a private encrypted channel instance by name.

    method join

    join: (channel: string) => Broadcaster[T]['presence'];
    • Get a presence channel instance by name.

    method leave

    leave: (channel: string) => void;
    • Leave the given channel, as well as its private and presence variants.

    method leaveAllChannels

    leaveAllChannels: () => void;
    • Leave all channels.

    method leaveChannel

    leaveChannel: (channel: string) => void;
    • Leave the given channel.

    method listen

    listen: (
    channel: string,
    event: string,
    callback: CallableFunction
    ) => Broadcaster[T]['public'];
    • Listen for an event on a channel instance.

    method private

    private: (channel: string) => Broadcaster[T]['private'];
    • Get a private channel instance by name.

    method registerAxiosRequestInterceptor

    registerAxiosRequestInterceptor: () => void;
    • Register an Axios HTTP interceptor to add the X-Socket-ID header.

    method registerInterceptors

    registerInterceptors: () => void;
    • Register 3rd party request interceptiors. These are used to automatically send a connections socket id to a Laravel app with a X-Socket-Id header.

    method registerjQueryAjaxSetup

    registerjQueryAjaxSetup: () => void;
    • Register jQuery AjaxPrefilter to add the X-Socket-ID header.

    method registerTurboRequestInterceptor

    registerTurboRequestInterceptor: () => void;
    • Register the Turbo Request interceptor to add the X-Socket-ID header.

    method registerVueRequestInterceptor

    registerVueRequestInterceptor: () => void;
    • Register a Vue HTTP interceptor to add the X-Socket-ID header.

    method socketId

    socketId: () => string | undefined;
    • Get the Socket ID for the connection.

    class EventFormatter

    class EventFormatter {}
    • Event name formatter

    constructor

    constructor(namespace: string | boolean);
    • Create a new class instance.

    method format

    format: (event: string) => string;
    • Format the given event name.

    method setNamespace

    setNamespace: (value: string | boolean) => void;
    • Set the event namespace.

    Interfaces

    interface PresenceChannel

    interface PresenceChannel extends Channel {}
    • This interface represents a presence channel.

    method here

    here: (callback: CallableFunction) => this;
    • Register a callback to be called anytime the member list changes.

    method joining

    joining: (callback: CallableFunction) => this;
    • Listen for someone joining the channel.

    method leaving

    leaving: (callback: CallableFunction) => this;
    • Listen for someone leaving the channel.

    method whisper

    whisper: (eventName: string, data: Record<any, any>) => this;
    • Send a whisper event to other clients in the channel.

    Type Aliases

    type BroadcastDriver

    type BroadcastDriver = Exclude<keyof Broadcaster, 'function'>;

      type Broadcaster

      type Broadcaster = {
      reverb: {
      connector: PusherConnector<'reverb'>;
      public: PusherChannel<'reverb'>;
      private: PusherPrivateChannel<'reverb'>;
      encrypted: PusherEncryptedPrivateChannel<'reverb'>;
      presence: PusherPresenceChannel<'reverb'>;
      options: GenericOptions<'reverb'> &
      Partial<CustomOmit<PusherOptions<'reverb'>, 'cluster'>>;
      };
      pusher: {
      connector: PusherConnector<'pusher'>;
      public: PusherChannel<'pusher'>;
      private: PusherPrivateChannel<'pusher'>;
      encrypted: PusherEncryptedPrivateChannel<'pusher'>;
      presence: PusherPresenceChannel<'pusher'>;
      options: GenericOptions<'pusher'> & Partial<PusherOptions<'pusher'>>;
      };
      ably: {
      connector: PusherConnector<'pusher'>;
      public: PusherChannel<'pusher'>;
      private: PusherPrivateChannel<'pusher'>;
      encrypted: PusherEncryptedPrivateChannel<'pusher'>;
      presence: PusherPresenceChannel<'pusher'>;
      options: GenericOptions<'ably'> & Partial<PusherOptions<'ably'>>;
      };
      'socket.io': {
      connector: SocketIoConnector;
      public: SocketIoChannel;
      private: SocketIoPrivateChannel;
      encrypted: never;
      presence: SocketIoPresenceChannel;
      options: GenericOptions<'socket.io'>;
      };
      null: {
      connector: NullConnector;
      public: NullChannel;
      private: NullPrivateChannel;
      encrypted: NullEncryptedPrivateChannel;
      presence: NullPresenceChannel;
      options: GenericOptions<'null'>;
      };
      function: {
      connector: any;
      public: any;
      private: any;
      encrypted: any;
      presence: any;
      options: GenericOptions<'function'>;
      };
      };
      • Specifies the broadcaster

      type EchoOptions

      type EchoOptions<TBroadcaster extends keyof Broadcaster> =
      Broadcaster[TBroadcaster]['options'];

        Package Files (1)

        Dependencies (0)

        No dependencies.

        Dev Dependencies (22)

        Peer Dependencies (2)

        Badge

        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/laravel-echo.

        • Markdown
          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/laravel-echo)
        • HTML
          <a href="https://www.jsdocs.io/package/laravel-echo"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>