Options
All
  • Public
  • Public/Protected
  • All
Menu

The backchannel class is a client that manages it's own database and relay connections between other backchannel clients.

Hierarchy

  • EventEmitter
    • Backchannel

Index

Constructors

constructor

  • Create a new backchannel client. Each instance represents a user opening the backchannel app on their device. There is one Mailbox per contact which is identified by the contact's discoveryKey.

    Parameters

    • dbName: string

      The name of the db for indexeddb

    • settings: BackchannelSettings

      User-defined settings

    Returns Backchannel

Properties

db

open

open: boolean

Accessors

contacts

  • Returns a list of contacts.

    Returns IContact[]

    An array of contacts

devices

  • Returns IDevice[]

settings

  • get settings(): any
  • Returns any

Methods

_addContact

  • _addContact(key: string, device?: boolean): Promise<string>
  • Parameters

    • key: string
    • Optional device: boolean

    Returns Promise<string>

_addContactDocument

  • _addContactDocument(contact: IContact): Promise<FreezeObject<unknown>>
  • Parameters

    Returns Promise<FreezeObject<unknown>>

_decrypt

  • _decrypt(msg: ArrayBuffer, contact: IContact): Promise<any>
  • Parameters

    Returns Promise<any>

_encrypt

  • _encrypt(msgType: string, msg: Uint8Array, contact: IContact): Promise<ArrayBuffer>
  • Parameters

    • msgType: string
    • msg: Uint8Array
    • contact: IContact

    Returns Promise<ArrayBuffer>

accept

  • accept(mailbox: string, password: string, timeout?: number): Promise<string>
  • Open a websocket connection to the local-first relay service. This performs the SPAKE2 protocol using spake2-wasm

    Parameters

    • mailbox: string
    • password: string

      The password

    • timeout: number = 60000

      The timeout before giving up, defaults to 1 minute

    Returns Promise<string>

    A hex represnetation of the resulting key, which is a 32 byte strong shared secret.

addContact

  • addContact(key: string): Promise<string>
  • Create a new contact in the database

    Parameters

    • key: string

      The key add to the database

    Returns Promise<string>

    id - The local id number for this contact

addDevice

  • addDevice(key: string): Promise<string>
  • Parameters

    • key: string

    Returns Promise<string>

connectToAllContacts

  • connectToAllContacts(): void
  • Start connecting to all known contacts. Danger: opens a websocket connection for each contact which could be an expensive operation.

    Returns void

connectToContact

  • connectToContact(contact: IContact): void
  • Start connecting to the contact.

    Parameters

    • contact: IContact

      The contact to connect to

    Returns void

connectToContactId

  • connectToContactId(cid: string): void
  • Start connecting to the contact.

    Parameters

    • cid: string

      The contact id

    Returns void

deleteContact

  • deleteContact(id: string): Promise<void>
  • Delete a contact in the database

    Parameters

    • id: string

      The local id number for this contact

    Returns Promise<void>

deleteDevice

  • deleteDevice(id: string): Promise<void>
  • Parameters

    • id: string

    Returns Promise<void>

destroy

  • destroy(): Promise<void>
  • Destroy this instance and delete the data. Disconnects from all websocket clients. Danger! Unrecoverable!

    Returns Promise<void>

editAvatar

  • editAvatar(contactId: string, avatar: string): Promise<IContact>
  • This updates the avatar for a given contact.

    Parameters

    • contactId: string

      The contact id to edit

    • avatar: string

      The new name for this contact

    Returns Promise<IContact>

    The new contact information

editName

  • editName(contactId: string, name: string): Promise<IContact>
  • This updates the name for a given contact and saves the contact in the database.

    Parameters

    • contactId: string

      The contact id to edit

    • name: string

      The new name for this contact

    Returns Promise<IContact>

    The new contact information

getMessagesByContactId

  • getMessagesByContactId(contactId: string): Promise<IMessage[]>
  • Get messages with another contact.

    Parameters

    • contactId: string

      The ID of the contact

    Returns Promise<IMessage[]>

hasPendingFiles

  • Did the file message fail to send?

    Parameters

    Returns boolean

    true if there are pending files, false if no pending files

listContacts

  • Returns IContact[]

sendFile

  • sendFile(contactId: string, file: File): Promise<FileMessage>
  • Send a file to a contact

    Parameters

    • contactId: string
    • file: File

    Returns Promise<FileMessage>

sendMessage

  • sendMessage(contactId: string, text: string): Promise<TextMessage>
  • Send a message to a contact. Assumes that you've already connected with the contact from listening to the contact.connected event

    Parameters

    • contactId: string
    • text: string

    Returns Promise<TextMessage>

unlinkDevice

  • unlinkDevice(id: string): Promise<void>
  • Sends a tombstone message, which instructs other devices to unlink itself and self-destruct.

    Parameters

    • id: string

      The device id

    Returns Promise<void>

updateSettings

  • Update the settings.

    Parameters

    Returns Promise<void>

Generated using TypeDoc