add support for recording conference to a file

This commit is contained in:
Dave Horton
2021-11-19 10:05:45 -05:00
parent 2262973f43
commit 0c5150cb30
2 changed files with 28 additions and 3 deletions

View File

@@ -5,11 +5,14 @@ const {TaskName, TaskPreconditions, BONG_TONE} = require('../utils/constants');
const normalizeJambones = require('../utils/normalize-jambones'); const normalizeJambones = require('../utils/normalize-jambones');
const makeTask = require('./make_task'); const makeTask = require('./make_task');
const bent = require('bent'); const bent = require('bent');
const fs = require('fs');
const fsPromises = require('fs/promises');
const assert = require('assert'); const assert = require('assert');
const WAIT = 'wait'; const WAIT = 'wait';
const JOIN = 'join'; const JOIN = 'join';
const START = 'start'; const START = 'start';
function confNoMatch(str) { function confNoMatch(str) {
return str.match(/^No active conferences/) || str.match(/Conference.*not found/); return str.match(/^No active conferences/) || str.match(/Conference.*not found/);
} }
@@ -49,7 +52,7 @@ class Conference extends Task {
'beep', 'startConferenceOnEnter', 'endConferenceOnExit', 'joinMuted', 'beep', 'startConferenceOnEnter', 'endConferenceOnExit', 'joinMuted',
'maxParticipants', 'waitHook', 'statusHook', 'endHook', 'enterHook' 'maxParticipants', 'waitHook', 'statusHook', 'endHook', 'enterHook'
].forEach((attr) => this[attr] = this.data[attr]); ].forEach((attr) => this[attr] = this.data[attr]);
this.record = this.data.record || {};
this.statusEvents = []; this.statusEvents = [];
if (this.statusHook) { if (this.statusHook) {
['start', 'end', 'join', 'leave', 'start-talking', 'stop-talking'].forEach((e) => { ['start', 'end', 'join', 'leave', 'start-talking', 'stop-talking'].forEach((e) => {
@@ -68,6 +71,9 @@ class Conference extends Task {
get name() { return TaskName.Conference; } get name() { return TaskName.Conference; }
get shouldRecord() { return this.record.path; }
get isRecording() { return this.recordingInProgress; }
async exec(cs, ep) { async exec(cs, ep) {
await super.exec(cs); await super.exec(cs);
this.ep = ep; this.ep = ep;
@@ -100,7 +106,7 @@ class Conference extends Task {
this.logger.info(err, `TaskConference:exec - error in conference ${this.confName}`); this.logger.info(err, `TaskConference:exec - error in conference ${this.confName}`);
} }
} }
async kill(cs) { async kill(cs) {
super.kill(cs); super.kill(cs);
this.logger.info(`Conference:kill ${this.confName}`); this.logger.info(`Conference:kill ${this.confName}`);
@@ -346,6 +352,16 @@ class Conference extends Task {
if (response.body && /\d+/.test(response.body)) this.participantCount = parseInt(response.body); if (response.body && /\d+/.test(response.body)) this.participantCount = parseInt(response.body);
this._notifyConferenceEvent(cs, 'join'); this._notifyConferenceEvent(cs, 'join');
// start recording if requested and we just started the conference
if (startConf && this.shouldRecord) {
this.logger.info(`recording conference to ${this.record.path}`);
try {
await this.ep.api(`conference ${this.confName} record ${this.record.path}`);
} catch (err) {
this.logger.info({err}, 'Conference:_joinConference - failed to start recording');
}
}
// listen for conference events // listen for conference events
this.ep.filter('Conference-Unique-ID', this.confUuid); this.ep.filter('Conference-Unique-ID', this.confUuid);
this.ep.conn.on('esl::event::CUSTOM::*', this.__onConferenceEvent.bind(this, cs)) ; this.ep.conn.on('esl::event::CUSTOM::*', this.__onConferenceEvent.bind(this, cs)) ;

View File

@@ -92,7 +92,8 @@
"waitHook": "object|string", "waitHook": "object|string",
"statusEvents": "array", "statusEvents": "array",
"statusHook": "object|string", "statusHook": "object|string",
"enterHook": "object|string" "enterHook": "object|string",
"record": "#record"
}, },
"required": [ "required": [
"name" "name"
@@ -241,6 +242,14 @@
"url" "url"
] ]
}, },
"record": {
"properties": {
"path": "string"
},
"required": [
"path"
]
},
"redirect": { "redirect": {
"properties": { "properties": {
"actionHook": "object|string" "actionHook": "object|string"