This module exports only one function and error objects.
Construct an object of type Recorder.
Name | Type | Required | Default | Description |
---|---|---|---|---|
apiKey | string | ✅ | API key associated with you account. | |
options | options object | See options object. |
Name | Type | Required | Default | Description |
---|---|---|---|---|
auth | auth object | Information to authenticate recording. If API key authentication is enabled, this parameter is required. | ||
iceServers | RTCIceServer[] | TURN servers that can be used by the ICE Agent. SkyWay ice servers are used by default. | ||
iceTransportPolicy | RTCIceTransportPolicy[] | all |
all and relay are supported. relay indicates ICE engine only use relay candidates. |
It is calculated using the HMAC-SHA256 algorithm on the string timestamp
, with the secret key for the app.
The final value should be in base64 string format.
Name | Type | Required | Default | Description |
---|---|---|---|---|
credential | string | ✅ | The HMAC credential for API key authentication. | |
timestamp | string | ✅ | The UNIX timestamp which used to calculate credential. timestamp must be a 10 digits. |
Sample code to generate credential using Node.js looks like this.
const credential = require("crypto")
.createHmac("sha256", YOUR_SECRET_KEY)
.update(timestamp)
.digest("base64");
An instance of type Recorder.
TypeError
is thrown, if invalid parameters are given.
This object contains below members.
- class TypeError
- class InvalidStateError
- class AbortError
- class RequestError
- class NetworkError
- class ServerError
The Recorder
class is used for recording a audio track via SkyWay recording server.
An instance of type Recorder
should be constructed via createRecorder(apiKey, [options])
An instance of type RecorderState
RecorderState
represents the current state of an instance of Recorder.
Transitions are:
- createRecorder(apiKey, [options]):
new
[initial state] - start(track):
recording
- stop():
closed
RecorderState
transitions diagram is shown below.
-- new Recorder(apiKey, [options]) --> "new" -- start(track) --> "recording" -- stop() --> "closed"
recorder.start(track)
starts recording a given audio track.
If the recording is successfully started, recorder.state
changes to recording
.
Name | Type | Required | Default | Description |
---|---|---|---|---|
track | MediaStreamTrack | ✅ | A MediaStreamTrack to record |
The recording ID which is used as the uploading file path of the audio recording file.
TypeError
is thrown if invalid type for parameters are given as follows:track
is not passed or falsytrack.kind
is not equal toaudio
. Note thatvideo
is not supported.
InvalidStateError
is thrown ifrecorder.state
isn'tnew
.RequestError
is thrown if invalid request parameter was given as follows:- The application associated with the given
apiKey
does not found. - The given credential does not match to computed credentials by SkyWay server.
- etc.
- The application associated with the given
NetworkError
is thrown, if request for SkyWay backend server failed due to network issues.ServerError
is thrown, if the SkyWay server encountered an internal error.
recorder.stop()
stops recording. If the recording is successfully stoped, recorder.state
changes to closed
.
After the recording is stopped, SkyWay recording server is going to upload the recording audio file into the bucket of Google Cloud Storage specified in SkyWay Dashboard. The uploaded filename is equal to the recording ID.
undefined
InvalidStateError
is thrown, ifrecorder.state
is notrecording
.RequestError
is thrown if invalid request parameter was given as follows:- The application associated with the given
apiKey
does not found. - The given credential does not match to computed credentials by SkyWay server.
- The application associated with the given
NetworkError
is thrown, if request for SkyWay backend server failed due to network issues.ServerError
is thrown, if the SkyWay server encountered an internal error.
recorder.stop()
callstrack.stop()
internally- you may want to call
track.clone()
beforerecorder.start(track)
- you may want to call
- if you call
recorder.stop()
too early after started, it may fail to record
The abort
event is emitted when the following errors occured during a recording.
- Disconnected from server for any reason. The possible causes include:
- Network issue,
- Recording exceeding the maximum recordable time of audio track.
- Transport closed by server error.
- Recording track ended.
The TypeError
class is used for reports errors that arise because a parameter has incorrect type.
The InvalidStateError
class is used for reports errors that arise because a method is called with an invalid state.
The AbortError
class is used for reports errors that arise because a request is aborted. For example, the AbortError
is thrown if an externally stopping the audio track being transmitted caused by the disconnection of microphones associated with the recording.
The RequestError
class is used for reports errors that arise because invalid request parameters are given.
The NetworkError
class is used for reports errors that arise because a request failed due to network issues.
The ServerError
class is used for reports errors that arise because a requested SkyWay server encountered an internal error.