JavaScript API v2.0
You can use this API in the browser, on the page where the Pipe recording client is embedded to check the status of the recording client & recording process using control functions and events. The 2.0 version of the JavaScript API can be used with recording clients embedded using the 2.0 Embed Code.
The JavaScript API v2.0 has 3 main components:
JavaScript Events API v2.0 (Desktop recorder) which will inform you about the events.
JavaScript Events API v2.0 (Mobile native recorder) which will inform you about mobile events.
JavaScript Control API v2.0 (Desktop recorder)
Getting the Recorder Object
The JavaScript Control API allows you to control Pipe’s desktop recorder using JavaScript.
With it, you can for example create your own UI by hiding the lower menu of the desktop Pipe recorder and control the recording process through the JS Control API using your own buttons.
The JavaScript Control API allows you to control Pipe’s desktop recorder using JavaScript.
With it, you can for example create your own UI by hiding the lower menu of the desktop Pipe recorder and control the recording process through the JS Control API using your own buttons.
Embed Code v2.0 via HTML
Controlling the recorder through JavaScript when using the 2.0 embed code (HTML)
Example code: check out the example code we’ve prepared on how to control the Pipe recorder using the JS APIs when using the 2.0 embed code:
When using the 2.0 HTML version of the embed code, you do not have a reference in JS for each recorder so you need to obtain one first. The way to obtain these references is by using the PipeSDK.getRecorderById()
method inside the PipeSDK.onRecordersInserted()
method. Once the reference is obtained you can execute its record()
method:
<input type="button" class="btn" value="Record" id="recordbtn" />
<script>
PipeSDK.onRecordersInserted = function(){
myRecorder = PipeSDK.getRecorderById('UNIQUE_ID_OF_THE_PIPERECORDER_TAG');
myRecorder.onReadyToRecord = function(id, type){
document.getElementById("recordbtn").onclick = function (){
myRecorder.record();
}
}
}
</script>
In the example above, after the recorder object/objects have been initialized, we get a reference (myRecorder
) to our recorder using the PipeSDK.getRecorderById()
method. After that, we assign a function to the click event of a button on our page. When this button is clicked, the recording is triggered using the myRecorder.record()
method.
PipeSDK
is the root object that is automatically initialized and accessible after pipe.js
has loaded in the browser.
UNIQUE_ID_OF_THE_PIPERECORDER_TAG
is the ID of any ``piperecorder``` tag on your page, that will automatically be replaced with a Pipe recorder. This id becomes the ID of the recorder.
onReadyToRecord()
event has been triggered.Embed Code v2.0 via JavaScript
Controlling the recorder through JavaScript when using the 2.0 embed code (JS)
Example code: check out the example code we’ve prepared on how to control the Pipe recorder using the JS APIs when using the 2.0 embed code:
When using the 2.0 JavaScript version of the embed code, the recorder object is received in the callback function of the PipeSDK.insert()
method. Once the recorder object is received you can call its record()
method like this:
<input type="button" class="btn" value="Record" id="recordbtn" />
<script>
PipeSDK.insert('UNIQUE_ID_OF_THE_REPLACED_DIV', paramsObject, function(myRecorderObject){
myRecorderObject.onReadyToRecord = function(id, type){
document.getElementById("recordbtn").onclick = function (){
myRecorderObject.record();
};
};
})
</script>
In the example above, in the callback function of PipeSDK.insert()
we get our recorder object named in this case myRecorderObject
. After that, we assign a function to the click event of a button on our page. When this button is clicked, the recording is triggered using myRecorderObject.record()
.
PipeSDK
is the root object that is automatically initialized and accessible after pipe.js
has loaded in the browser.
UNIQUE_ID_OF_THE_REPLACED_DIV
is the ID of any div
element in your page, that will automatically be replaced with a Pipe recorder once the PipeSDK.insert()
method is called. This id will become the ID of the recorder.
onReadyToRecord()
event has been triggered.Methods List
Full list of control methods you can use when using the 2.0 embed code
Here is the full list of methods that you can call on the Pipe recorder and that make up the JS Control API:
- record()
- stopVideo()
- playVideo()
- pause()
- save()
- download()
- getStreamTime()
- getPlaybackTime()
- getStreamName()
- remove()
record()
Method
Description: This call will trigger the recorder to record a video or audio stream or to rerecord one if one is already recorded (equivalent to pressing the RECORD button).
It should be executed only after:
onCamAccess(recorderId, allowed)
is called by Pipe and the value ofallowed
istrue
ANDonReadyToRecord()
is called by Pipe
If executed before the above 2 events, the initial recording screen might be shown by Pipe, in which case calling record()
will do nothing.
Return Value: none
stopVideo()
Method
Description: This call will trigger the Pipe desktop client to stop the recording of a stream if a recording is in progress.
Return Value: none
playVideo()
Method
Description: This call will play the recorded stream if there is one. This will not be available during or before the recording process (equivalent to pressing the PLAY button).
Return Value: none
pause()
Method
Description: This call will pause the video recording that is currently playing. The call will not do anything if a video recording is not playing. The call is equivalent to pressing the PAUSE PLAYBACK button. Calling the function a second time will not do anything; you need to call playVideo()
to resume playback.
Return Value: none
save()
Method
Description: If recording autosaving is disabled, you can use this call to save the desired recording (equivalent to pressing the Save button). This will not be available if recording autosaving is enabled.
Return Value: none
download()
Method
Description: If recording download is enabled, you can use this call to download the desired recording locally (equivalent to pressing the Download button). This will not be available if recording download is disabled.
Return Value: none
getStreamTime()
Method
Description: This will return the time of the played or the currently recording stream.
Return Value: a number with the current length of the recording (if called during the recording process)
getPlaybackTime()
Method
Description: This will return the current time of the recording during playback.
Return Value: a number with the current time of the recording if called during the playback process or 0 if called outside of playback
getStreamName()
Method
Description: This call will return the stream name at any time, but beware that the name of the stream might not be set at the time of the call. This is useful when you need the name of the stream during the recording.
Return Value: a string, the stream name WITHOUT the file extension. If the stream name is not set, it will return an empty string
remove()
Method
Description: Executing this method will remove the Pipe recorder HTML elements from the page and releases any in-use resources (webcam, connection to media server) without removing the div
or piperecorder
element in which it was first inserted. After removal, the div
or piperecorder
element can be reused to re-insert the recorder in the page. It works for all the Pipe clients.
Return Value: none
JavaScript Events API v2.0 (Desktop recorder)
Every time something happens with the desktop recorder (a button is pressed, the connection succeeds, etc.), the recorder will execute a specific JavaScript function with information about the event.
You can add these event functions to your HTML/JS app and extend them with your own code to do your bidding.
Here are some of the things you can do by extending these event functions:
- show a message, a warning, or a timer on the HTML page
- activate an input field or button in the HTML page
- redirect the user to another page
Example code: check out the example code we’ve prepared on how to listen for JS events when using the 2.0 embed code:
Since the v2 embed code supports multiple recorders on the same page, to override a recorde’s event functions, we need to get the desired recorder object 1st. Here’s how to do it:
Getting the Recorder Object
This is done differently depending on what version of the embed code you are using.
v2.0 HTML
When using the v2.0 HTML embed code you can use the PipeSDK.getRecorderById()
method to get a reference to a recorder object.
For example:
var myRecorderObject = PipeSDK.getRecorderById('UNIQUE_ID_OF_THE_RECORDER');
will get a reference to the recorder which replaced the <piperecorder...>
HTML element with the id UNIQUE_ID_OF_THE_RECORDER
.
To make sure all the recorder object/objects have been initialized and they’re ready you must execute PipeSDK.getRecorderById()
only once the PipeSDK.onRecordersInserted()
method fires.
Example: add this JS code to your HTML page to be notified when the user clicks the record button in the desktop recorder:
<script>
PipeSDK.onRecordersInserted = function(){
myRecorderObject = PipeSDK.getRecorderById('UNIQUE_ID_OF_THE_RECORDER');
myRecorderObject.btRecordPressed = function(id){
var args = Array.prototype.slice.call(arguments);
console.log("btRecordPressed("+args.join(', ')+")");
}
}
</script>
v2.0 via JavaScript
When using the v2.0 JavaScript version of the embed code, the recorder object is retrieved in the callback function of the PipeSDK.insert()
method. This is where you can override the event functions.
Example: add this JS code to your app to insert a recorder in the app and get notified via console.log when the user clicks the record button in the desktop recorder:
PipeSDK.insert('UNIQUE_ID_OF_THE_RECORDER', paramsObject, function(myRecorderObject){
myRecorderObject.btRecordPressed = function(id){
var args = Array.prototype.slice.call(arguments);
console.log("btRecordPressed("+args.join(', ')+")");
}
});
Functions List
The desktop recorder has 2 different sets of events and corresponding event functions:
- Event functions executed when recording a new video using the desktop recorder with embed code 2.0
- Event functions executed when uploading an existing file using the desktop recorder with embed code 2.0
Event functions executed when recording a new video using the desktop recorder with embed code 2.0
Below is the list of JavaScript event functions that the Pipe client will trigger when the user is recording a video from a desktop device.
- onReadyToRecord(recorderId, recorderType)
- userHasCamMic(recorderId,cam_number,mic_number)
- btRecordPressed(recorderId)
- btStopRecordingPressed(recorderId)
- btPlayPressed(recorderId)
- btPausePressed(recorderId)
- onUploadDone(recorderId, streamName, streamDuration, audioCodec, videoCodec, fileType, audioOnly, location)
- onUploadProgress(recorderId, percent)
- onCamAccess(recorderId, allowed)
- onPlaybackComplete(recorderId)
- onRecordingStarted(recorderId)
- onConnectionClosed(recorderId)
- onConnectionStatus(recorderId, status)
- onMicActivityLevel(recorderId, currentActivityLevel)
- onSaveOk(recorderId, streamName, streamDuration, cameraName, micName, audioCodec, videoCodec, filetype, videoId, audioOnly, location)
- onDesktopVideoUploadStarted(recorderId, filename, filetype, audioOnly)
- onDesktopVideoUploadSuccess(recorderId, filename, filetype, videoId, audioOnly, location)
- onDesktopVideoUploadProgress(recorderId, percent)
- onDesktopVideoUploadFailed(recorderId, error)
onReadyToRecord(recorderId,recorderType)
Function
Description: The Pipe recorder is ready to start recording (the interface has been built, you have allowed access to your webcam and you can see yourself in the browser)
Passed Parameters:
recorderId
- the recorder idrecorderType
- a string representing the type of the recorder (HTML5
).
Example:
myRecorderObject.onReadyToRecord = function(recorderId, recorderType) {
var args = Array.prototype.slice.call(arguments);
console.log("onReadyToRecord("+args.join(', ')+")");
});
userHasCamMic(recorderId,cam_number,mic_number)
Function
Description: Pipe detects the number of cams and mics a user has
Passed Parameters:
recorderId
- the recorder idcam_number
- number of webcam drivers the user has installed on his computermic_number
- number of sound cards and sound sources the user has installed on his computer
Example:
myRecorderObject.userHasCamMic = function(recorderId,cam_number,mic_number){
var args = Array.prototype.slice.call(arguments);
console.log("userHasCamMic("+args.join(', ')+")");
}
btRecordPressed(recorderId)
Function
Description: RECORD button is pressed. This event does NOT mark the exact start of the recording. See onRecordingStarted.
Passed Parameters:
recorderId
- the recorder id
Example:
myRecorderObject.btRecordPressed = function(recorderId){
var args = Array.prototype.slice.call(arguments);
console.log("btRecordPressed("+args.join(', ')+")");
}
btStopRecordingPressed(recorderId)
Function
Description: STOP RECORD button is pressed
Passed Parameters:
recorderId
- the recorder id
Example:
myRecorderObject.btStopRecordingPressed = function(recorderId){
var args = Array.prototype.slice.call(arguments);
console.log("btStopRecordingPressed("+args.join(', ')+")");
}
btPlayPressed(recorderId)
Function
Description: PLAY button is pressed
Passed Parameters:
recorderId
- the recorder id
Example:
myRecorderObject.btPlayPressed = function(recorderId){
var args = Array.prototype.slice.call(arguments);
console.log("btPlayPressed("+args.join(', ')+")");
}
btPausePressed(recorderId)
Function
Description: PAUSE button is pressed
Passed Parameters:
recorderId
- the recorder id
Example:
var args = Array.prototype.slice.call(arguments);
console.log("btPausePressed("+args.join(', ')+")");
}
onUploadDone(recorderId, streamName, streamDuration, audioCodec, videoCodec, fileType, audioOnly, location)
Function
Description: Recorded data finishes streaming/uploading to the media server
Passed Parameters:
recorderId
- the recorder idstreamName
- a string representing the name of the stream WITHOUT the file extensionstreamDuration
- the duration of the recording/audio file in seconds but accurate to the millisecond (like this: 4.322)audioCodec
- the audio codec used for the recordingvideoCodec
- the video codec used for the recordingfileType
- the initial file extension for the recordingaudioOnly
- true if it is an audio-only recording, false otherwiselocation
- will take one of 4 values:- eu2-addpipe.s3.nl-ams.scw.cloud
- us1-addpipe.s3-us-west-1.amazonaws.com
- us2-addpipe.s3.us-east-1.amazonaws.com
- ca1-addpipe.s3.ca-central-1.amazonaws.com
The location
contains the subdomain of the regional storage bucket where the final recording and snapshot will be stored by Pipe. For the EU2 region, for example, the recording will be stored at https://eu2-addpipe.s3.nl-ams.scw.cloud/ACCOUNT_HASH/FILE_NAME.mp4. The snapshot will be at the same location but with the .jpg extension. If Do Not Store Files is turned on, the final processed files will not be pushed to this storage location.
Example:
myRecorderObject.onUploadDone = function(recorderId, streamName, streamDuration, audioCodec, videoCodec, fileType, audioOnly, location){
var args = Array.prototype.slice.call(arguments);
console.log("onUploadDone("+args.join(', ')+")");
}
onUploadProgress(recorderId, percent)
Function
Description: Triggers every time upload progress is made.
Passed Parameters:
recorderId
- the recorder idpercent
- the percent at which the upload progress is at
Example:
myRecorderObject.onUploadProgress = function(recorderId, percent){
var args = Array.prototype.slice.call(arguments);
console.log("onUploadProgress("+args.join(', ')+")");
}
onCamAccess(recorderId, allowed)
Function
Description:
onCamAccess
is triggered:
- on macOS, after clicking the Allow or Don’t Allow buttons in the operating system’s privacy dialog box that’s asking permission for camera and microphone access. The dialog box will be brought up by the operating system the first time the browser tries to access the camera or the microphone.
- after clicking the Allow or Block (Don’t Allow for Safari) buttons in the browser’s privacy dialog box that’s asking permission for camera and microphone access. The dialog box will be brought up by the browser when the recorder tries to access the camera or the microphone.
- automatically if a previous choice (Allow or Block) made by the user is persistent.
Here is an example of Chrome’s privacy dialog box:
And here is how macOS asks the user if Firefox can access the camera:
Passed Parameters:
recorderId
- the recorder idallowed
- is true if:
- the user clicked the [Allow] button OR
- clicked [Allow] in a previous session and that choice is persistent (in which case no additional dialog box is shown).
- and false if:
- the user clicked the [Block] button OR
- clicked [Block] in a previous session and that choice is persistent (in which case no additional dialog box is shown).
- is true if:
Example:
myRecorderObject.onCamAccess = function(recorderId, allowed){
var args = Array.prototype.slice.call(arguments);
console.log("onCamAccess("+args.join(', ')+")");
}
onPlaybackComplete(recorderId)
Function
Description: Pipe finishes playback of recording stream
Passed Parameters:
recorderId
- the recorder id
Example:
myRecorderObject.onPlaybackComplete = function(recorderId){
var args = Array.prototype.slice.call(arguments);
console.log("onPlaybackComplete("+args.join(', ')+")");
}
onRecordingStarted(recorderId)
Function
Description: the Pipe desktop client started recording. This event is called ONLY if there’s data to record and, when it is called, it will be called with a 200-220ms delay after the record button is pressed and the btRecordPressed
event is triggered.
Parameters:
recorderId
- the recorder id
Example:
myRecorderObject.onRecordingStarted = function(recorderId){
var args = Array.prototype.slice.call(arguments);
console.log("onRecordingStarted("+args.join(', ')+")");
}
onConnectionClosed(recorderId)
Function
Description: the connection to the media server has failed completely (the connection could not be reestablished even after the 30 reconnection attempts in the desktop recorder)
Parameters:
recorderId
- the recorder id
Example:
myRecorderObject.onConnectionClosed = function(recorderId){
var args = Array.prototype.slice.call(arguments);
console.log("onConnectionClosed("+args.join(', ')+")");
}
onConnectionStatus(recorderId, status)
Function
Description: Called by the Pipe desktop client for every connection event
Passed Parameters:
status
- the actual connection status:
Desktop recorder only
- connected
- The connection is live.
- disconnected: ping timeout
- When the client loses Internet connection.
- disconnected: io server disconnect
- When the media server is shut down.
- disconnected: io client disconnect
- The socket was manually disconnected.
- disconnected: transport close
- The connection was closed (for example the user has lost connection, or the network was changed from WiFi to 4G).
- disconnected: transport error
- The connection has encountered an error (for example the server was killed during an HTTP long-polling cycle).
- error
- Thrown when an error occurs.
- connect_timeout
- Thrown when connection timeouts.
- reconnecting
- Actively trying to reconnect. A total of 30 reconnect attempts will be made, each attempt at an interval between 1000 ms - 5000 ms.
- connect_error: (+ error)
- Thrown after a connection error.
- reconnect_error
- Thrown only after a reconnecting attempt when the reconnection attempt resulted in an error.
- reconnect_failed
- Reconnection has completely failed after a total number of 30 attempts were made. The client is considered fully disconnected.
- reconnected
- Thrown only after a reconnecting attempt when the reconnection was successful.
recorderId
- the value of recorderId
property of flashvars
object in the embed code
Example:
myRecorderObject.onConnectionStatus = function(recorderId, status){
var args = Array.prototype.slice.call(arguments);
console.log("onConnectionStatus("+args.join(', ')+")");
}
onMicActivityLevel(recorderId, currentActivityLevel)
Function
Description: the function is called by the Pipe desktop client every 10th of a second (100 milliseconds) with the current microphone level.
Passed Parameters:
recorderId
- the recorder idcurrentActivityLevel
- The amount of sound the microphone is detecting in numeric values between 0 and 100. From our experience, it’s hard to get values over 50 though.
Example:
myRecorderObject.onMicActivityLevel = function(recorderId, currentActivityLevel){
var args = Array.prototype.slice.call(arguments);
console.log("onMicActivityLevel("+args.join(', ')+")");
}
onSaveOk(recorderId, streamName, streamDuration, cameraName, micName, audioCodec, videoCodec, filetype, videoId, audioOnly, location)
Function
Description: The recording data has been fully streamed to our media servers for further processing.
This is not a confirmation that the recorded file is ready for delivery as the recording will take a few seconds to be processed (conversion to .mp4, snapshot extraction, rotation, push to storage location). Use Pipe’s webhooks to be notified when the recording is fully processed and ready for delivery.
Passed Parameters:
recorderId
- the recorder idstreamName
- a string representing the name of the stream WITHOUT the file extensionstreamDuration
- the duration of the recorded video/audio file in seconds but accurate to milliseconds (like this: 4.322)cameraName
- the name of the webcam driver the user has selected for capturing video datamicName
- the name of the sound card/mic driver that has been selected for capturing audio dataaudioCodec
- the audio codec used for the recordingvideoCodec
- the video codec used for the recordingfileType
- the initial file extension for the recordingvideoId
- a string representing the recording id in Pipe’s database, (same recording id that is sent through the webhook)audioOnly
- true if it is an audio-only recording, false otherwiselocation
- will take one of 4 values:- eu2-addpipe.s3.nl-ams.scw.cloud
- us1-addpipe.s3-us-west-1.amazonaws.com
- us2-addpipe.s3.us-east-1.amazonaws.com
- ca1-addpipe.s3.ca-central-1.amazonaws.com
The location
contains the subdomain of the regional storage bucket where the final recording and snapshot will be stored by Pipe. For the EU2 region, for example, the recording will be stored at https://eu2-addpipe.s3.nl-ams.scw.cloud/ACCOUNT_HASH/FILE_NAME.mp4. The snapshot will be at the same location but with the .jpg extension. If Do Not Store Files is turned on, the final processed files will not be pushed to this storage location.
Example:
myRecorderObject.onSaveOk = function(recorderId, streamName, streamDuration, cameraName, micName, audioCodec, videoCodec, fileType, videoId, audioOnly, location){
var args = Array.prototype.slice.call(arguments);
console.log("onSaveOk("+args.join(', ')+")");
}
Event functions executed when uploading an existing file using the desktop recorder with embed code 2.0
Below is the list of JavaScript events that the Pipe client will dispatch when the user is UPLOADING an existing video using the desktop recorder. You can turn on the feature from your embed code or from the Pipe account dashboard when generating an embed code, details here.
onDesktopVideoUploadStarted(recorderId, filename, filetype, audioOnly)
Function
Description: The user has selected a recording from the computer’s library and the recording is ready for upload.
Passed Parameters:
recorderId
- the recorder idfilename
- the (automatically generated) name of the recording without extensionfiletype
- the file extension of the uploaded video, it can be mp4, mov, 3gp, m4v, mkv, avi, mp3, wma, etc.audioOnly
- true if we’re expecting an audio-only recording, false otherwise
Example:
myRecorderObject.onDesktopVideoUploadStarted = function(recorderId, filename,filetype, audioOnly){
var args = Array.prototype.slice.call(arguments);
console.log("onDesktopVideoUploadStarted("+args.join(', ')+")");
onDesktopVideoUploadSuccess(recorderId, filename, filetype, videoId, audioOnly, location)
Function
Description: The recording has finished uploading successfully.
Passed Parameters:
recorderId
- the recorder idfilename
- the automatically generated name of the recordingfiletype
- the file extension of the uploaded video, it can be mp4, mov, 3gp, m4v, mkv, avi, mp3, wma, etc.videoId
- a string representing the recording id in Pipe’s database (same recording id that is sent through the webhook)audioOnly
- true if it is an audio-only recording, false otherwiselocation
- will take one of 4 values:- eu2-addpipe.s3.nl-ams.scw.cloud
- us1-addpipe.s3-us-west-1.amazonaws.com
- us2-addpipe.s3.us-east-1.amazonaws.com
- ca1-addpipe.s3.ca-central-1.amazonaws.com
The location
contains the subdomain of the regional storage bucket where the final recording and snapshot will be stored by Pipe. For the EU2 region, for example, the recording will be stored at https://eu2-addpipe.s3.nl-ams.scw.cloud/ACCOUNT_HASH/FILE_NAME.mp4. The snapshot will be at the same location but with the .jpg extension. If Do Not Store Files is turned on, the final processed files will not be pushed to this storage location.
Example:
myRecorderObject.onDesktopVideoUploadSuccess = function(recorderId, filename,filetype,videoId,audioOnly,location){
var args = Array.prototype.slice.call(arguments);
console.log("onDesktopVideoUploadSuccess("+args.join(', ')+")");
}
onDesktopVideoUploadProgress(recorderId, percent)
Function
Description: Triggers every time upload progress is made.
Parameters:
recorderId
- the recorder idpercent
- the percent at which the upload progress is at
Example:
myRecorderObject.onDesktopVideoUploadProgress = function(recorderId, percent){
var args = Array.prototype.slice.call(arguments);
console.log("onDesktopVideoUploadProgress("+args.join(', ')+")");
}
onDesktopVideoUploadFailed(recorderId, error)
Function
Description: There was an error while uploading the recording.
Passed Parameters:
recorderId
- the recorder iderror
- The error thrown when the upload fails to complete
Example:
myRecorderObject.onDesktopVideoUploadFailed = function(recorderId, error){
var args = Array.prototype.slice.call(arguments);
console.log("onDesktopVideoUploadFailed("+args.join(', ')+")");
}
JavaScript Events API v2.0 (Mobile native recorder)
Every time something happens with the mobile native recorder (a video is starting to upload, an upload has finished, etc.) the recorder will execute a specific JavaScript function with information about the event.
You can add these mobile native recorder event functions to your HTML/JS app and extend them with your own code to do your bidding.
Since the v2.0 embed code supports multiple recorders on the same page, to override a recorder’s event functions, we need to get the desired recorder object 1st.
Getting the Recorder Object
This is done differently depending on what version of the embed code you are using.
v2.0 via HTML
When using the v2.0 HTML embed code you can use the PipeSDK.getRecorderById()
method to get a reference to a recorder object.
For example:
var myRecorderObject = PipeSDK.getRecorderById('UNIQUE_ID_OF_THE_RECORDER');
will get a reference to the recorder which replaced the <piperecorder>
HTML element with the id UNIQUE_ID_OF_THE_RECORDER
.
To make sure all the recorder object/objects have been initialized and they’re ready you must execute PipeSDK.getRecorderById()
only once the PipeSDK.onRecordersInserted()
method fires.
Example: add this JS code to your HTML page to be notified when the upload starts after the user has recorded a video in the iOS/Android-controlled UI:
<script>
PipeSDK.onRecordersInserted = function(){
myRecorderObject = PipeSDK.getRecorderById('UNIQUE_ID_OF_THE_RECORDER');
myRecorderObject.onVideoUploadStarted = function(id, filename, filetype, audioOnly){
var args = Array.prototype.slice.call(arguments);
console.log("onVideoUploadStarted("+args.join(', ')+")");
}
}
</script>
v2.0 via JavaScript
When using the v2.0 JavaScript version of the embed code, the recorder object is retrieved in the callback function of the PipeSDK.insert() method. This is where you can override the event functions.
Example: add this JS code to your app to insert a recorder in the app and get notified via console.log when the upload starts after the user has recorded a video in the iOS/Android-controlled UI:
PipeSDK.insert('UNIQUE_ID_OF_THE_RECORDER', paramsObject, function(myRecorderObject){
myRecorderObject.onVideoUploadStarted = function(id, filename, filetype, audioOnly){
var args = Array.prototype.slice.call(arguments);
console.log("onVideoUploadStarted("+args.join(', ')+")");
}
});
Functions List
You can replace onVideoUploadStarted(id, filename, filetype, audioOnly)
in the example above with any of the 2.0 mobile event functions below.
- onVideoUploadStarted(recorderId, filename, filetype, audioOnly)
- onVideoUploadSuccess(recorderId, filename, filetype, videoId, audioOnly, location)
- onVideoUploadProgress(recorderId, percent)
- onVideoUploadFailed(recorderId, error)
onVideoUploadStarted(recorderId, filename, filetype, audioOnly)
Function
Description: The user has recorded a new video or chosen an existing video from the device’s library and the video is ready for upload.
Passed Parameters:
recorderId
- the recorder idfilename
- the (automatically generated) name of the recording without extensionfiletype
- the file extension of the uploaded video, it can be mp4, mov, 3gp, m4v, etc.audioOnly
- true if we’re expecting an audio-only recording, false otherwise
Example:
yRecorderObject.onVideoUploadStarted = function(recorderId, filename,filetype, audioOnly){
var args = Array.prototype.slice.call(arguments);
console.log("onVideoUploadStarted("+args.join(', ')+")");
}
onVideoUploadSuccess(recorderId, filename, filetype, videoId, audioOnly, location)
Function
Description: The new or existing recording has finished uploading successfully.
Passed Parameters:
recorderId
- the recorder idfilename
- the automatically generated name of the recordingfiletype
- the file extension of the uploaded video, it can be mp4, mov, 3gp, m4v, etc.videoId
- a string representing the recording id in Pipe’s database (same recording id that is sent through the webhook)audioOnly
- true if it is an audio-only recording, false otherwiselocation
- will take one of 4 values:- eu2-addpipe.s3.nl-ams.scw.cloud
- us1-addpipe.s3-us-west-1.amazonaws.com
- us2-addpipe.s3.us-east-1.amazonaws.com
- ca1-addpipe.s3.ca-central-1.amazonaws.com
The location
contains the subdomain of the regional storage bucket where the final recording and snapshot will be stored by Pipe. For the EU2 region, for example, the recording will be stored at https://eu2-addpipe.s3.nl-ams.scw.cloud/ACCOUNT_HASH/FILE_NAME.mp4. The snapshot will be at the same location but with the .jpg extension. If Do Not Store Files is turned on, the final processed files will not be pushed to this storage location.
Example:
myRecorderObject.onVideoUploadSuccess = function(recorderId, filename,filetype,videoId,audioOnly,location){
var args = Array.prototype.slice.call(arguments);
console.log("onVideoUploadSuccess("+args.join(', ')+")");
}
onVideoUploadProgress(recorderId, percent)
Function
Description: Triggers every time upload progress is made.
Passed Parameters:
recorderId
- the recorder idpercent
- the percent at which the upload progress is at
Example:
myRecorderObject.onVideoUploadProgress = function(recorderId, percent){
var args = Array.prototype.slice.call(arguments);
console.log("onVideoUploadProgress("+args.join(', ')+")");
}
onVideoUploadFailed(recorderId, error)
Function
Description:There was an error while uploading the recording.
Passed Parameters:
recorderId
- the recorder iderror
- The error is thrown when the upload fails to complete
Example:
myRecorderObject.onVideoUploadFailed = function(recorderId, error){
var args = Array.prototype.slice.call(arguments);
console.log("onVideoUploadFailed("+args.join(', ')+")");
}