JSLib Reference Manual / Exports / Snackabra
Class: Snackabra#
Snackabra is the main class for interacting with the Snackable backend.
It is a singleton, so you can only have one instance of it. It is guaranteed to be synchronous, so you can use it right away. It is also guaranteed to be thread-safe, so you can use it from multiple threads.
Constructor expects an object with the names of the matching servers, for example below shows the miniflare local dev config. Note that ‘new Snackabra()’ is guaranteed synchronous, so can be ‘used’ right away. You can optionally call without a parameter in which case SB will ping known servers.
Example
const sb = new Snackabra({
channel_server: 'http://127.0.0.1:4001',
channel_ws: 'ws://127.0.0.1:4001',
storage_server: 'http://127.0.0.1:4000'
})
Table of contents#
Constructors#
Properties#
Accessors#
Methods#
Constructors#
constructor#
• new Snackabra()
Properties#
#channel#
• Private #channel: Channel
#preferredServer#
• Private Optional #preferredServer: SBServer
#storage#
• Private #storage: StorageApi
Accessors#
channel#
• get channel(): Channel
Connects to a channel.
Returns#
crypto#
• get crypto(): SBCrypto
Returns the crypto API.
Returns#
storage#
• get storage(): StorageApi
Returns the storage API.
Returns#
StorageApi
Methods#
connect#
▸ connect(onMessage, key?, channelId?): Promise<ChannelSocket>
Parameters#
Name |
Type |
Description |
|---|---|---|
|
( |
- |
|
|
optional key to use for encryption/decryption * |
|
|
optional channel id to use for encryption/decryption * |
Returns#
Promise<ChannelSocket>
a channel object
create#
▸ create(sbServer, serverSecret, keys?): Promise<SBChannelHandle>
Creates a new channel. Currently uses trivial authentication.
Returns a promise to a ‘’SBChannelHandle’’ object
(which includes the :term:Channel Name).
Note that this method does not connect to the channel,
it just creates (authorizes) it.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
the server to use |
|
|
|
the server secret |
|
|
optional keys to use for encryption/decryption |
Returns#
Promise<SBChannelHandle>
sendFile#
▸ sendFile(file): void
Sends a file to the channel.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
the file to send |
Returns#
void