I am a university student and I have a graduation project. How can I make a stop recording? I can’t stop the recording for the second time at the same session. I don`t understand “recording.id”. I use sessionID for startRecording. But i cant do stopRecordng.
Hello,
When you start a recording using the OpenVidu REST API it will return a Recording object that includes the recording id: REST API - OpenVidu Docs .
When you want to stop the recording you pass the recording id returned above to the REST API: REST API - OpenVidu Docs .
Cheers,
Mihail
Hello Mihail,
I used node.js. I need different answer. I need to learning “recording.id”
If you use the openvidu-node-client API then it’s very easy, after you start the recording you will get the Recording object with the id in the Promise then
function, you can see here: openvidu-node-client API - OpenVidu Docs .
I wrote to console “then” function but couldnt see id. I’ve tried what you say. I did not get positive results.
I wrote a small Node.js script (index.js
) to help you out (replace the ...
dots with your OpenVidu server address and secret):
var OpenViduNode = require('openvidu-node-client').OpenVidu;
const OPENVIDU_SERVER = '...';
const OPENVIDU_SECRET = '...';
var ovNode = new OpenViduNode(OPENVIDU_SERVER, OPENVIDU_SECRET);
var sessionId = 'test-rec';
ovNode.createSession({customSessionId: sessionId})
.then(session => {
//console.log(session);
ovNode.startRecording(sessionId).then(recordingStarted => {
console.log('recordingStarted:', recordingStarted);
var recordingId = recordingStarted.id;
ovNode.stopRecording(recordingId).then(recordingStopped => {
console.log('recordingStopped:', recordingStopped);
session.close().then(() => console.log('Session closed'));
}).catch(err => {
console.error(err);
});
}).catch(err => {
console.error(err);
});
}).catch(err => {
console.error(err);
});
Add a package.json
file that includes the openvidu-node-client
package:
{
"name": "ov-node-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"openvidu-node-client": "2.20.0"
}
}
Run npm i
after adding the package.json
file.
First connect a publisher to your server in the test-rec
room, then run node index.js
. You should get an output like this:
recordingStarted: Recording {
size: 0,
duration: 0,
id: 'test-rec-1',
sessionId: 'test-rec',
createdAt: 1635339819957,
url: null,
status: 'started',
properties: {
name: 'test-rec-1',
hasAudio: true,
hasVideo: true,
outputMode: 'COMPOSED',
mediaNode: undefined,
recordingLayout: 'BEST_FIT',
resolution: '1280x720',
frameRate: 25,
shmSize: 536870912
}
}
recordingStopped: Recording {
size: 5432,
duration: 0.76,
id: 'test-rec-1',
sessionId: 'test-rec',
createdAt: 1635339819957,
url: 'https://.../openvidu/recordings/test-rec-1/test-rec-1.mp4',
status: 'ready',
properties: {
name: 'test-rec-1',
hasAudio: true,
hasVideo: true,
outputMode: 'COMPOSED',
mediaNode: undefined,
recordingLayout: 'BEST_FIT',
resolution: '1280x720',
frameRate: 25,
shmSize: 536870912
}
}
Session closed