@fappurbate/channel-ext v1.0.0
@fappurbate/channel-ext
Extension side of the library that allows easy communication among Chaturbate apps & bots and Fappurbate extensions.
Documentation
Class: Channel
Represents a channel between a Chaturbate bot (app) and a Fappurbate extension. Allows communication with events and requests.
new Channel(options)
options.namestringName of the channel. Must not clash with channel names of others instances (including other apps & bots in the same chat).
onEvent.addListener(subject, callback): this
subjectstringName of the event to listen to.callbackany => voidCallback will be called on a given event with attached data as the first argument.
Add a listener for a given event subject.
onEvent.removeListener(subject, callback): this
subjectstringName of the event.callbackany => voidThe same callback that was passed toonEvent.addListener.
Remove an event listener.
onRequest.addHandler(subject, handler): this
subjectstringName of the request.handlerany => void|any|PromiseHandler will be called on a given request.
Add a handler for a given request subject. It will be called with the data attached as the first argument. All handlers are called, but only the first received response is used. If throws an error, it is sent back to the bot (app) as an error response. May also return a Promise.
onRequest.removeHandler(subject, handler): this
subjectstringName of the request.handlerany => void|any|PromiseThe same handler that was passed toonRequest.addHandler.
Remove a request handler.
close(): void
Unregister all event listeners. After this the channel is usable no more. Do it before you try to open a new channel with the same name.
name
string
The name of the channel. Read-only.
emit(subject, data): void
subjectstringName of the event.dataany?Data to send with the event. Must be serializable.
Send an event to the bot (app).
request(subject, data): Promise
subjectstringName of the request.dataany?Data to send with the request. Must be serializable.
Send a request to the bot (app). If an error response is received, returns a promise that rejects with a Failure that contains attached data. It is to distinguish an error response from other errors like network errors, timeout, etc.
Class: Failure
A subclass of fb.Error that represents an error response from request(subject, data).
new Failure(data)
dataany?default: {}Data to attach.
name
string=== 'Failure'
type
string=== 'ERR_FAILURE'