API Docs for: 0.2.1
Show:

Hook.Channel.WEBSOCKETS Class

Module: Hook

Methods

call

(
  • procedure
)
Promise

Parameters:

  • procedure String

Returns:

Promise:

disconnect

() Hook.Channel

Disconnect from channel, publishing a 'disconnected' message.

Returns:

Hook.Channel:

this

isConnected

() Boolean

Is EventSource listenning to messages?

Returns:

Boolean:

publish

(
  • event
  • message
  • options
)
Hook.Channel

Publish event message

Parameters:

  • event String
  • message Object
  • options Object

    'exclude' and 'elegible' are optional options.

Returns:

Hook.Channel:

subscribe

(
  • event
  • callback
)
Hook.Channel

Subscribe to channel. Publishes a 'connected' message on the first time.

Parameters:

  • event String

    (optional)

  • callback Function

Returns:

Hook.Channel:

Example:

Registering for a single custom event

channel.subscribe('some-event', function(data) {
  console.log("Custom event triggered: ", data);
})

Registering for client connected/disconnected events

channel.subscribe('connected', function(data) {
  console.log("New client connected: ", data.client_id);
});
channel.subscribe('disconnected', function(data) {
  console.log("Client disconnected: ", data.client_id);
});

unsubscribe

(
  • event
)
Hook.Channel

Unsubscribe to a event listener

Parameters:

  • event String

Returns:

Hook.Channel: