Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EchoService

The service class, use this as something like (or use the AngularLaravelEchoModule.forRoot method):

export const echoConfig: SocketIoEchoConfig = {
  userModel: 'App.User',
  notificationNamespace: 'App\\Notifications',
  options: {
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001'
  }
}

@NgModule({
  ...
  providers: [
    ...
    EchoService,
    { provide: ECHO_CONFIG, useValue: echoConfig }
    ...
  ]
  ...
})

and import it in your component as

@Component({
...
})
export class ExampleComponent {
  constructor(echoService: EchoService) {
  }
}

Hierarchy

  • EchoService

Index

Constructors

constructor

Accessors

connected

  • get connected(): boolean

connectionState

  • get connectionState(): Observable<boolean>
  • Observable of connection state changes, emits true when connected and false when disconnected

    Returns Observable<boolean>

echo

rawConnectionState

socketId

  • get socketId(): string

Methods

join

joining

  • joining(name: string): Observable<any>
  • Listen for users joining the specified presence channel.

    Parameters

    • name: string

      The name of the channel

    Returns Observable<any>

    An observable that emits the user when he joins the specified channel

leave

leaving

  • leaving(name: string): Observable<any>
  • Listen for users leaving the specified presence channel.

    Parameters

    • name: string

      The name of the channel

    Returns Observable<any>

    An observable that emits the user when he leaves the specified channel

listen

  • listen(name: string, event: string): Observable<any>
  • Listen for events on the specified channel.

    Parameters

    • name: string

      The name of the channel

    • event: string

      The name of the event

    Returns Observable<any>

    An observable that emits the event data of the specified event when it arrives

listenForWhisper

  • listenForWhisper(name: string, event: string): Observable<any>
  • Listen for client sent events (whispers) on the specified private or presence channel channel.

    Parameters

    • name: string

      The name of the channel

    • event: string

      The name of the event

    Returns Observable<any>

    An observable that emits the whisper data of the specified event when it arrives

login

  • login(headers: object, userId: string | number): EchoService
  • Set authentication data and connect to and start listening for notifications on the users private channel

    Parameters

    • headers: object

      Authentication headers to send when talking to the service

      • [key: string]: string
    • userId: string | number

      The current user's id

    Returns EchoService

    The instance for chaining

logout

notification

  • notification(type: string, name?: undefined | string): Observable<any>
  • Listen for notifications on the users private channel.

    Parameters

    • type: string

      The type of notification to listen for or * for any

    • Optional name: undefined | string

      Optional a different channel to receive notifications on

    Returns Observable<any>

    An observable that emits the notification of the specified type when it arrives

users

  • users(name: string): Observable<any[]>
  • Listen for user list updates on the specified presence channel.

    Parameters

    • name: string

      The name of the channel

    Returns Observable<any[]>

    An observable that emits the initial user list as soon as it's available

whisper

  • whisper(name: string, event: string, data: any): EchoService
  • Send a client event to the specified presence or private channel (whisper).

    Parameters

    • name: string

      The name of the channel

    • event: string

      The name of the event

    • data: any

      The payload for the event

    Returns EchoService

    The instance for chaining