Namespace: Quiet

Quiet

Source:

Methods

<static> ab2str(ab) → {string}

Convert an array buffer in UTF8 to string
Parameters:
Name Type Description
ab ArrayBuffer array buffer to be converted
Source:
Returns:
s - converted string
Type
string

<static> addReadyCallback(c, onError)

Add a callback to be called when Quiet is ready for use, e.g. when transmitters and receivers can be created.
Parameters:
Name Type Argument Description
c function The user function which will be called
onError onError <optional>
User errback function
Source:
Example
addReadyCallback(function() { console.log("ready!"); });

<static> mergeab(ab1, ab2) → {ArrayBuffer}

Merge 2 ArrayBuffers This is a convenience function to assist user receiver functions that want to aggregate multiple payloads.
Parameters:
Name Type Description
ab1 ArrayBuffer beginning ArrayBuffer
ab2 ArrayBuffer ending ArrayBuffer
Source:
Returns:
buf - ab1 merged with ab2
Type
ArrayBuffer

<static> receiver(profile, onReceive, onCreateFail, onReceiveFail)

Create a new receiver with the profile specified by profile (should match profile of transmitter).
Parameters:
Name Type Argument Description
profile string name of profile to use, must be a key in quiet-profiles.json
onReceive onReceive callback which receiver will call to send user received data
onCreateFail onReceiverCreateFail <optional>
callback to notify user that receiver could not be created
onReceiveFail onReceiveFail <optional>
callback to notify user that receiver received corrupted data
Source:
Example
receiver("robust", function(payload) { console.log("received chunk of data: " + Quiet.ab2str(payload)); });

<static> setLibfecPrefix(prefix)

Set the path prefix of libfec.js. Although not strictly required, it is highly recommended to include this library.

This function, if used, must be called before quiet-emscripten.js has started loading. If it is not called first, then emscripten will not load libfec.js.
Parameters:
Name Type Description
prefix string The path prefix where emscripten will fetch libfec.js
Source:
Example
setLibfecPrefix("/");  // fetches /libfec.js

<static> setMemoryInitializerPrefix(prefix)

Set the path prefix of quiet-emscripten.js.mem. This file is used to initialize the memory state of emscripten.

This function must be called before quiet-emscripten.js has started loading. If it is not called first, then emscripten will default to a prefix of "".
Parameters:
Name Type Description
prefix string The path prefix where emscripten will fetch quiet-emscripten.js.mem
Source:
Example
setMemoryInitializerPrefix("/");  // fetches /quiet-emscripten.js.mem

<static> setProfilesPrefix(prefix)

Set the path prefix of quiet-profiles.json and do an async fetch of that path. This file is used to configure transmitter and receiver parameters.

This function must be called before creating a transmitter or receiver.
Parameters:
Name Type Description
prefix string The path prefix where Quiet will fetch quiet-profiles.json
Source:
Example
setProfilesPrefix("/js/");  // fetches /js/quiet-profiles.json

<static> str2ab(s) → {ArrayBuffer}

Convert a string to array buffer in UTF8
Parameters:
Name Type Description
s string string to be converted
Source:
Returns:
buf - converted arraybuffer
Type
ArrayBuffer

<static> transmitter(profile) → {transmit}

Create a new transmitter configured by the given profile name.
Parameters:
Name Type Description
profile string name of profile to use, must be a key in quiet-profiles.json
Source:
Returns:
transmit - transmit callback which user calls to start transmission
Type
transmit
Example
var transmit = transmitter("robust");
transmit(Quiet.str2ab("Hello, World!"), function() { console.log("transmission complete"); });

Type Definitions

onError(reason)

Callback to notify user that quiet.js failed to initialize
Parameters:
Name Type Description
reason string error message related to failure
Source:

onReceive(payload)

Callback used by receiver to notify user of data received via microphone/line-in.
Parameters:
Name Type Description
payload ArrayBuffer chunk of data received
Source:

onReceiveFail(total)

Callback used by receiver to notify user that a frame was received but failed checksum. Frames that fail checksum are not sent to onReceive.
Parameters:
Name Type Description
total number total number of frames failed across lifetime of receiver
Source:

onReceiverCreateFail(reason)

Callback used by receiver to notify user of errors in creating receiver. This is a callback because frequently this will result when the user denies permission to use the mic, which happens long after the call to create the receiver.
Parameters:
Name Type Description
reason string error message related to create fail
Source:

onTransmitFinish()

Callback used by transmit to notify user that transmission has finished
Source:

transmit(payload, done)

Callback for user to provide data to a Quiet transmitter

This callback may be used multiple times, but the user must wait for the finished callback between subsequent calls.
Parameters:
Name Type Argument Description
payload ArrayBuffer bytes which will be encoded and sent to speaker
done onTransmitFinish <optional>
callback to notify user that transmission has completed
Source:
Example
transmit(Quiet.str2ab("Hello, World!"), function() { console.log("transmission complete"); });