JSLib Reference Manual / Exports / Snackabra
Class: Snackabra#
Snackabra The main class for interacting with SB servers
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#
Accessors#
Methods#
Constructors#
constructor#
• new Snackabra(args?, DEBUG?)
Parameters#
Name |
Type |
Default value |
Description |
|---|---|---|---|
|
|
optional 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. |
|
|
|
|
optional boolean to enable debug logging |
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
version#
• get version(): string
Returns#
string
Methods#
connect#
▸ connect(onMessage, key?, channelId?): Promise<ChannelSocket>
Connects to :term:Channel Name on this SB config.
Returns a channel socket promise right away, but it
will not be ready until the ready promise is resolved.
Note that if you have a preferred server then the channel
object will be returned right away, but the ready promise
will still be pending. If you do not have a preferred server,
then the ready promise will be resolved when at least
one of the known servers is responding and ready.
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>