Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ gulp.task('pre-test', function () {
gulp.task('test', ['pre-test'], function (cb) {
var mochaErr;

gulp.src('test/**/*.js')
gulp.src('test/**/test.phloConferenceBridge.js')
.pipe(plumber())
.pipe(mocha({ reporter: 'spec' }))
.on('error', function (err) {
Expand Down
12 changes: 12 additions & 0 deletions lib/resources/phlo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { extend, validate } from '../utils/common.js';
import { PlivoResource, PlivoResourceInterface } from '../base';
import { PhloMultiPartyCall, PhloMultiPartyCallInterface } from "../resources/phloMultipartyCall";
import { PhloConfBridge, PhloConfBridgeInterface } from "../resources/phloConfBridge";
import * as _ from "lodash";

const clientKey = Symbol();
Expand Down Expand Up @@ -32,6 +33,17 @@ export class Phlo extends PlivoResource {
return dd.get(item.phloId, nodeId);
}

// Define conference bridge getters
this.conferenceBridge = function (nodeId) {
let dd = new PhloConfBridge(client, { phloId: item.phloId, nodeId: nodeId });
return dd;
};

this.conferenceBridge.get = function (nodeId) {
let dd = new PhloConfBridgeInterface(client, { phloId: item.phloId, nodeId: nodeId });
return dd.get(item.phloId, nodeId);
}

}

/**
Expand Down
72 changes: 72 additions & 0 deletions lib/resources/phloConfBridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { extend, validate } from '../utils/common.js';
import { PlivoResource, PlivoResourceInterface } from '../base';
import { PhloConfBridgeMember, PhloConfBridgeMemberInterface } from './phloConfBridgeMember';

const clientKey = Symbol();
const idField = 'nodeId';

export class PhloConfBridge extends PlivoResource {
constructor(client, data = {}) {
let action = 'phlo/' + data.phloId + '/conference_bridge/';
super(action, PhloConfBridge, idField, client);
extend(this, data);
this.action = action;
this.client = client;

// Define member getters
let item = this;
this.member = function (memberAddress) {
let dd = new PhloConfBridgeMember(client, { phloId: item.phloId, nodeId: item.nodeId, memberAddress: memberAddress });
return dd;
};

this.member.get = function (memberAddress) {
let dd = new PhloConfBridgeMemberInterface(client, { phloId: item.phloId, nodeId: item.nodeId, memberAddress: memberAddress });
return dd.get(item.phloId, item.nodeId, memberAddress);
}

}
}

export class PhloConfBridgeInterface extends PlivoResourceInterface {


constructor(client, data = {}) {
let action = 'phlo/' + data.phloId + '/conference_bridge/';
super(action, PhloConfBridge, idField, client);
extend(this, data);
}

/**
* Get A Phlo Detail
* @method
* @param {string} id - phlo uuid to get information of.
* @promise {object} returns Phlo Object
* @fail {Error} returns Error
*/
get(phloId, id) {

//Validate id first
let errors = validate([{
field: 'id',
value: id,
validators: ['isRequired']
}]);

if (errors) {
return errors;
}

let params = {
phlo_id: phloId,
node_type: 'conference_bridge',
node_id: id
};

// Url pattern for getting phlo resource by id
// https://phlorunner.plivo.com/v1/phlo/{phlo_id}
// console.log('get multi party call with ', id, params);
return super.get(id, params);

}
}
77 changes: 77 additions & 0 deletions lib/resources/phloConfBridgeMember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { extend, validate } from '../utils/common.js';
import { PlivoResource, PlivoResourceInterface } from '../base';

const clientKey = Symbol();
const action = 'Phlo/';
const idField = 'phloUuid';

/**
* Represents a Phlo Conference Bridge Call Member
* @constructor
* @param {function} client - make api call
* @param {object} [data] - data of phlo
*/
export class PhloConfBridgeMember extends PlivoResource {

constructor(client, data = {}) {
let action = 'phlo/' + data.phloId + '/conference_bridge/' + data.nodeId + '/members/';
super(action, PhloConfBridgeMember, idField, client);
extend(this, data);
this.action = action;
this.client = client;
}

mute() {
return this.update('mute');
}

unmute() {
return this.update('unmute');
}

leave() {
return this.update('leave');
}

update(action) {

let params = {
action: action
};

// Build Url
// https://phlorunner.plivo.com/v1/phlo/{PHLO_ID}/multi_party_call/{NODE_ID}/members/{MemberAddress}
let task = this.action + this.memberAddress;

return super.executeAction(task, 'POST', params, '');
}
}

export class PhloConfBridgeMemberInterface extends PlivoResourceInterface {


constructor(client, data = {}) {
let action = 'phlo/' + data.phloId + '/conference_bridge/' + data.nodeId + '/members/';
super(action, PhloConfBridgeMember, idField, client);
extend(this, data);
this.action = action;
this.client = client;
}

get(phloId, nodeId, memberAddress) {

//Validate id first
let errors = validate([{
field: 'id',
value: memberAddress,
validators: ['isRequired']
}]);
if (errors) {
return errors;
}

return new PhloConfBridgeMember(this.client, { phloId: phloId, nodeId, memberAddress });

}

}
32 changes: 30 additions & 2 deletions lib/rest/request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function Request(config) {
headers: headers,
json: true
};

// console.log('action:', action, ', method:', method);
if (method == 'GET' && options.formData !== '') {
let query = '?' + queryString.stringify(params);
options.url += query;
Expand Down Expand Up @@ -1129,9 +1129,37 @@ export function Request(config) {
});
}

// ============ Conference Bridge ============ //

// Get conference details
else if (method == 'GET' && action == 'phlo/2a38dc9b-b48e-4e4e-b49b-0677c556989c/conference_bridge/f501faf1-0703-4619-86fa-d537b689e331/') {
resolve({
response: {},
body:
{
apiId: 'a7fc7bde-1aa3-449d-9d8a-3de1da5f8b71',
nodeId: 'f501faf1-0703-4619-86fa-d537b689e331',
phloId: '2a38dc9b-b48e-4e4e-b49b-0677c556989c',
name: 'Conference Bridge_1',
nodeType: 'conference_bridge',
createdOn: '2019-01-21 04:11:10.387710+00:00',
action:
'phlo/2a38dc9b-b48e-4e4e-b49b-0677c556989c/conference_bridge/',
}
})
}

// Mute Member, Unmute Member & Leave Member
else if (method == 'POST' && action == 'phlo/2a38dc9b-b48e-4e4e-b49b-0677c556989c/conference_bridge/f501faf1-0703-4619-86fa-d537b689e331/members/919920700964') {
resolve({
response: {},
body: { api_id: '0000dae0-7596-4219-be84-a85efbbe8562', error: '' }
})
}

// =========== If no combination found, raise issue ============================
else {
console.log('===>--->', method, action, '=>', params);
// console.log('===>--->', method, action, '=>', params);
reject(new Error('not found'));
}
});
Expand Down
Loading