From 0c5150cb30989a70dfb5a92188960d2e92c0fd7e Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 19 Nov 2021 10:05:45 -0500 Subject: [PATCH] add support for recording conference to a file --- lib/tasks/conference.js | 20 ++++++++++++++++++-- lib/tasks/specs.json | 11 ++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/tasks/conference.js b/lib/tasks/conference.js index 440bbf25..7c4f37a1 100644 --- a/lib/tasks/conference.js +++ b/lib/tasks/conference.js @@ -5,11 +5,14 @@ const {TaskName, TaskPreconditions, BONG_TONE} = require('../utils/constants'); const normalizeJambones = require('../utils/normalize-jambones'); const makeTask = require('./make_task'); const bent = require('bent'); +const fs = require('fs'); +const fsPromises = require('fs/promises'); const assert = require('assert'); const WAIT = 'wait'; const JOIN = 'join'; const START = 'start'; + function confNoMatch(str) { return str.match(/^No active conferences/) || str.match(/Conference.*not found/); } @@ -49,7 +52,7 @@ class Conference extends Task { 'beep', 'startConferenceOnEnter', 'endConferenceOnExit', 'joinMuted', 'maxParticipants', 'waitHook', 'statusHook', 'endHook', 'enterHook' ].forEach((attr) => this[attr] = this.data[attr]); - + this.record = this.data.record || {}; this.statusEvents = []; if (this.statusHook) { ['start', 'end', 'join', 'leave', 'start-talking', 'stop-talking'].forEach((e) => { @@ -68,6 +71,9 @@ class Conference extends Task { get name() { return TaskName.Conference; } + get shouldRecord() { return this.record.path; } + get isRecording() { return this.recordingInProgress; } + async exec(cs, ep) { await super.exec(cs); this.ep = ep; @@ -100,7 +106,7 @@ class Conference extends Task { this.logger.info(err, `TaskConference:exec - error in conference ${this.confName}`); } } - + async kill(cs) { super.kill(cs); 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); 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 this.ep.filter('Conference-Unique-ID', this.confUuid); this.ep.conn.on('esl::event::CUSTOM::*', this.__onConferenceEvent.bind(this, cs)) ; diff --git a/lib/tasks/specs.json b/lib/tasks/specs.json index 0282f8c1..93aa145e 100644 --- a/lib/tasks/specs.json +++ b/lib/tasks/specs.json @@ -92,7 +92,8 @@ "waitHook": "object|string", "statusEvents": "array", "statusHook": "object|string", - "enterHook": "object|string" + "enterHook": "object|string", + "record": "#record" }, "required": [ "name" @@ -241,6 +242,14 @@ "url" ] }, + "record": { + "properties": { + "path": "string" + }, + "required": [ + "path" + ] + }, "redirect": { "properties": { "actionHook": "object|string"