Skip to content

Commit

Permalink
Merge branch 'main' into fix/removeCustomEventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu authored Mar 21, 2024
2 parents 153e5a9 + d687a80 commit 250d223
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions lib/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const EVENTS_OF_INTEREST = [
'CHANNEL_ANSWER',
'DTMF',
'DETECTED_TONE',
'SWITCH_EVENT_PLAYBACK_START',
'SWITCH_EVENT_PLAYBACK_STOP',
'CUSTOM conference::maintenance'
];

Expand Down Expand Up @@ -94,6 +96,8 @@ class Endpoint extends Emitter {
this.conn.on(`esl::event::CHANNEL_CALLSTATE::${this.uuid}`, this._onChannelCallState.bind(this)) ;
this.conn.on(`esl::event::DTMF::${this.uuid}`, this._onDtmf.bind(this)) ;
this.conn.on(`esl::event::DETECTED_TONE::${this.uuid}`, this._onToneDetect.bind(this)) ;
this.conn.on(`esl::event::PLAYBACK_START::${this.uuid}`, this._onPlaybackStart.bind(this)) ;
this.conn.on(`esl::event::PLAYBACK_STOP::${this.uuid}`, this._onPlaybackStop.bind(this)) ;

this.conn.on(`esl::event::CUSTOM::${this.uuid}`, this._onCustomEvent.bind(this)) ;

Expand Down Expand Up @@ -1480,6 +1484,34 @@ class Endpoint extends Emitter {
this.emit('tone', {tone});
}

_onPlaybackStart(evt) {
if (evt.getHeader('Playback-File-Type') === 'tts_stream') {
let header;
const opts = {};
evt.firstHeader();
do {
header = evt.nextHeader();
if (header && header.startsWith('variable_tts_')) opts[header] = evt.getHeader(header);
} while (header);
this.emit('playback-start', opts);
}
else this.emit('playback-start', {file: evt.getHeader('Playback-File-Path')});
}

_onPlaybackStop(evt) {
if (evt.getHeader('Playback-File-Type') === 'tts_stream') {
let header;
const opts = {};
evt.firstHeader();
do {
header = evt.nextHeader();
if (header && header.startsWith('variable_tts_')) opts[header] = evt.getHeader(header);
} while (header);
this.emit('playback-stop', opts);
}
else this.emit('playback-stop', {file: evt.getHeader('Playback-File-Path')});
}

_emitReady() {
if (!this._ready) {
this._ready = true ;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drachtio-fsmrf",
"version": "3.0.33",
"version": "3.0.37",
"description": "freeswitch-based media resource function for drachtio",
"main": "lib/mrf.js",
"scripts": {
Expand Down

0 comments on commit 250d223

Please sign in to comment.