api/utils/audio-over-socket

This file contains some re-usable parts for websocket audio communication.

Source:

Methods

(static) encodeAndSendAudioOnDataAvailable(id, recorder, rpc) → {Promise.<*>}

Source:

Encode the audio as base64 and send it to the websocket server.

Parameters:
Name Type Description
id string

The reserved ID for the audio.

recorder MediaRecorder

The recorder to use to get the recording.

rpc string

The RPC to use to store the data.

Returns:
  • The response of the given RPC.
Type
Promise.<*>

(static) prepareServerForAudio(id, recorder, rpc) → {Promise}

Source:

Send the recorder settings to the websocket server to initialize it.

The reserved ID (passed in the parameters) is returned once the promise is resolved.

Parameters:
Name Type Description
id string

The reserved ID for the audio.

recorder MediaRecorder

The recorder which has been set up to record.

rpc string

The RPC to use to initialize the websocket server.

Fires:
  • {websocketserverreadyforaudio} - When the websocket server has been prepared for and is ready to receive the audio.event:
Returns:
  • The promise which resolves when the websocket server is ready for the audio.
Type
Promise

(static) registerStreamForRecorder(recorder, rpcName, dataEvenopt) → {Promise}

Source:

Register a RPC call to the current websocket connection. The backend will call this registered function once, an then we can send progressive results (the details.progress call) to send audio chunks to the backend. We will send those chunks as soon as we got audio from the recorder.

When the recording ends we un-register the rpc.

Parameters:
Name Type Attributes Description
recorder MediaRecorder

Audio recorder instance.

rpcName string

Name of the RPC to register. This name will be prepended with nl.itslanguage for better consistency.

dataEven string <optional>

Optional, the name of the event to receive audio data on. Can be overridden, for example when you want to use the BufferPlugin.

Fires:
Returns:
  • It returns a promise with the service registration as result.
Type
Promise