JSLib Reference Manual / Exports / ChannelEndpoint

Class: ChannelEndpoint#

ChannelEndpoint

Gives access to a Channel API (without needing to connect to socket). It’s fully functional except it won’t send or receive messages (obviously, that’s what a socket is for, but we might add send/receive in the future for non-socket use cases)

Hierarchy#

Table of contents#

Constructors#

Properties#

Accessors#

Methods#

Constructors#

constructor#

new ChannelEndpoint(sbServer, key?, channelId?)

Parameters#

Name

Type

sbServer

SBServer

key?

JsonWebKey

channelId?

string

Overrides#

Channel.constructor

Properties#

admin#

admin: boolean = false

Inherited from#

Channel.admin


adminData#

Optional adminData: Dictionary<any>

Inherited from#

Channel.adminData


channelReady#

channelReady: Promise<Channel>

Channel Class

This is the main work horse for channels. However, it is ABSTRACT, meaning you need a ‘concrete’ class to use it.

Currently you have two options:

You can create a ChannelEndpoint object. That can do everything against a channel except send/receive messages synchronously.

The other option is ChannelSocket, which does everything ChannelEndpoint does, but ALSO connects with a web socket.

So unless you’re actually connecting with intent on interactive, fast messaging, an endpoint is sufficient. In fact, UNLESS you are going to do send/receive, you should use ChannelEndpoint, not ChannelSocket.

In our current thinking, ‘Channel’ captures pretty much everything, except how you want (instant) messaging to be hooked up. So for example, our next class might be ‘ChannelP2P’, which would be setting up webrtc data channel connections in a mesh.

Note that you don’t need to worry about what API calls involve race conditions and which don’t, jslib will do that for you.

Param

server to join

Param

key to use to join (optional)

Param

the Channel Name to find on that server (optional)

Inherited from#

Channel.channelReady


locked#

Optional locked: boolean = false

Inherited from#

Channel.locked


motd#

Optional motd: string = ''

Inherited from#

Channel.motd


owner#

owner: boolean = false

Inherited from#

Channel.owner


ready#

ready: Promise<SB384>

Inherited from#

Channel.ready


sb384Ready#

sb384Ready: Promise<SB384>

Inherited from#

Channel.sb384Ready


userName#

userName: string = ''

Inherited from#

Channel.userName


verifiedGuest#

verifiedGuest: boolean = false

Inherited from#

Channel.verifiedGuest

Accessors#

_id#

get _id(): string

Returns#

string

Inherited from#

Channel._id


api#

get api(): this

Returns#

this

Inherited from#

Channel.api


channelId#

get channelId(): undefined | string

Returns#

undefined | string

Inherited from#

Channel.channelId


channelSignKey#

get channelSignKey(): CryptoKey

Returns#

CryptoKey

Inherited from#

Channel.channelSignKey


exportable_privateKey#

get exportable_privateKey(): JsonWebKey

Returns#

JsonWebKey

Inherited from#

Channel.exportable_privateKey


exportable_pubKey#

get exportable_pubKey(): JsonWebKey

Returns#

JsonWebKey

Inherited from#

Channel.exportable_pubKey


hash#

get hash(): string

Returns a unique identifier for external use, that will be unique for any class or object that uses SB384 as it’s root.

This is deterministic, used to identify users, channels, etc.

The hash is base64 encoding of the SHA-384 hash of the public key, taking the ‘x’ and ‘y’ fields. Note that it is slightly restricted, it only allows [A-Za-z0-9], eg does not allow the ‘_’ or ‘-’ characters. This makes the encoding more practical for end-user interactions like copy-paste. This is accomplished by simply re-hashing until the result is valid. This reduces the entropy of the channel ID by a neglible amount.

Note this is not b62 encoding, which we use for 256-bit entities. This is still ~384 bits (e.g. x and y fields are each 384 bits, but of course the underlying total entropy isn’t that, see ).

NOTE: if you ever need to COMPARE hashes, well short version is that you cannot do so in the general case. You can use sbCrypto.compareHashWithKey() to compare a hash with a key, but you cannot compare two hashes. See the comparison function for more details.

Returns#

string

Inherited from#

Channel.hash


keys#

get keys(): ChannelKeys

Returns#

ChannelKeys

Inherited from#

Channel.keys


onMessage#

set onMessage(_f): void

Parameters#

Name

Type

_f

CallableFunction

Returns#

void


ownerChannelId#

get ownerChannelId(): string

Returns#

string

Inherited from#

Channel.ownerChannelId


privateKey#

get privateKey(): CryptoKey

Returns#

CryptoKey

Inherited from#

Channel.privateKey


readyFlag#

get readyFlag(): boolean

Returns#

boolean

Inherited from#

Channel.readyFlag


sbServer#

get sbServer(): SBServer

Returns#

SBServer

Inherited from#

Channel.sbServer

Methods#

acceptVisitor#

acceptVisitor(pubKey): Promise<unknown>

Parameters#

Name

Type

pubKey

string

Returns#

Promise<unknown>

Inherited from#

Channel.acceptVisitor


authorize#

authorize(ownerPublicKey, serverSecret): Promise<any>

Parameters#

Name

Type

ownerPublicKey

Dictionary<any>

serverSecret

string

Returns#

Promise<any>

Inherited from#

Channel.authorize


budd#

budd(): Promise<SBChannelHandle>

“budd” will spin a channel off an existing one. You need to provide one of the following combinations of info:

  • nothing: create new channel and transfer all storage budget

  • just storage amount: creates new channel with that amount, returns new channel

  • just a target channel: moves all storage budget to that channel

  • just keys: creates new channel with those keys and transfers all storage budget

  • keys and storage amount: creates new channel with those keys and that storage amount

In the first (special) case you can just call budd(), in the other cases you need to fill out the ‘options’ object.

Another way to remember the above: all combinations are valid except both a target channel and assigning keys.

Note: if you’re specifying the target channel, then the return values will not include the private key (that return value will be empty).

Same channels as mother and target will be a no-op, regardless of other parameters.

Note: if you provide a value for ‘storage’, it cannot be undefined. If you wish it to be Infinity, then you need to omit the property from options.

Future: negative amount of storage leaves that amount behind, the rest is transferred

Returns#

Promise<SBChannelHandle>

Inherited from#

Channel.budd

budd(options): Promise<SBChannelHandle>

Parameters#

Name

Type

options

Object

options.keys?

JsonWebKey

options.storage?

number

options.targetChannel?

string

Returns#

Promise<SBChannelHandle>

Inherited from#

Channel.budd


downloadData#

downloadData(): Promise<unknown>

Channel.downloadData

Returns#

Promise<unknown>

Inherited from#

Channel.downloadData


getAdminData#

getAdminData(): Promise<ChannelAdminData>

Channel.getAdminData

Returns#

Promise<ChannelAdminData>

Inherited from#

Channel.getAdminData


getCapacity#

getCapacity(): Promise<any>

getCapacity

Returns#

Promise<any>

Inherited from#

Channel.getCapacity


getJoinRequests#

getJoinRequests(): Promise<any>

getJoinRequests

Returns#

Promise<any>

Inherited from#

Channel.getJoinRequests


getLastMessageTimes#

getLastMessageTimes(): Promise<unknown>

Channel.getLastMessageTimes

Returns#

Promise<unknown>

Inherited from#

Channel.getLastMessageTimes


getMother#

getMother(): Promise<any>

getMother

Get the channelID from which this channel was budded. Note that this is only accessible by Owner (as well as hosting server)

Returns#

Promise<any>

Inherited from#

Channel.getMother


getOldMessages#

getOldMessages(currentMessagesLength?, paginate?): Promise<ChannelMessage[]>

Channel.getOldMessages

Will return most recent messages from the channel.

Parameters#

Name

Type

Default value

Description

currentMessagesLength

number

100

number to fetch (default 100)

paginate

boolean

false

if true, will paginate from last request (default false)

Returns#

Promise<ChannelMessage[]>

Inherited from#

Channel.getOldMessages


getStorageLimit#

getStorageLimit(): Promise<any>

getStorageLimit (current storage budget)

Returns#

Promise<any>

Inherited from#

Channel.getStorageLimit


isLocked#

isLocked(): Promise<boolean>

isLocked

Returns#

Promise<boolean>

Inherited from#

Channel.isLocked


lock#

lock(): Promise<unknown>

Channel.lock()

Locks the channel, so that new visitors need an “ack” to join..

Returns#

Promise<unknown>

Inherited from#

Channel.lock


ownerKeyRotation#

ownerKeyRotation(): void

Returns#

void

Inherited from#

Channel.ownerKeyRotation


postPubKey#

postPubKey(_exportable_pubKey): Promise<{ success: boolean }>

Parameters#

Name

Type

_exportable_pubKey

JsonWebKey

Returns#

Promise<{ success: boolean }>

Inherited from#

Channel.postPubKey


send#

send(_m, _messageType?): Promise<string>

Parameters#

Name

Type

_m

string | SBMessage

_messageType?

"string" | "SBMessage"

Returns#

Promise<string>

Overrides#

Channel.send


setMOTD#

setMOTD(motd): Promise<any>

Set message of the day

Parameters#

Name

Type

motd

string

Returns#

Promise<any>

Inherited from#

Channel.setMOTD


storageRequest#

storageRequest(byteLength): Promise<Dictionary<any>>

Parameters#

Name

Type

byteLength

number

Returns#

Promise<Dictionary<any>>

Inherited from#

Channel.storageRequest


updateCapacity#

updateCapacity(capacity): Promise<any>

Update (set) the capacity of the channel; Owner only

Parameters#

Name

Type

capacity

number

Returns#

Promise<any>

Inherited from#

Channel.updateCapacity


uploadChannel#

uploadChannel(channelData): Promise<any>

Parameters#

Name

Type

channelData

ChannelData

Returns#

Promise<any>

Inherited from#

Channel.uploadChannel