mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-30 06:12:08 -06:00
MPC API changes, TODO : Dev Testing
This commit is contained in:
parent
326831d98c
commit
93c85714a9
2 changed files with 117 additions and 34 deletions
46
lib/base.js
46
lib/base.js
|
|
@ -4,9 +4,9 @@ let actionKey = Symbol('api action');
|
|||
let klassKey = Symbol('constructor');
|
||||
let idKey = Symbol('id filed');
|
||||
let clientKey = Symbol('make api call');
|
||||
// let secondaryActionKey = Symbol('api action');
|
||||
// let secondaryKlassKey = Symbol('constructor');
|
||||
// let secondaryIdKey = Symbol('id filed');
|
||||
let secondaryActionKey = Symbol('api action');
|
||||
let secondaryKlassKey = Symbol('constructor');
|
||||
let secondaryIdKey = Symbol('id filed');
|
||||
|
||||
export class PlivoGenericResponse {
|
||||
constructor(params, idString) {
|
||||
|
|
@ -126,17 +126,35 @@ export class PlivoResource {
|
|||
}
|
||||
}
|
||||
|
||||
// export class PlivoSecondaryResource {
|
||||
// constructor(action, klass, idField, secondaryAction, secondaryKlass, secondaryIdField, request) {
|
||||
// this[actionKey] = action;
|
||||
// this[klassKey] = klass;
|
||||
// this[idKey] = idField;
|
||||
// this[clientKey] = request;
|
||||
// this[secondaryActionKey] = secondaryAction;
|
||||
// this[secondaryKlassKey] = secondaryKlass;
|
||||
// this[secondaryIdKey] = secondaryIdField;
|
||||
// }
|
||||
// }
|
||||
export class PlivoSecondaryResource {
|
||||
constructor(action, klass, idField, secondaryAction, secondaryKlass, secondaryIdField, request) {
|
||||
this[actionKey] = action;
|
||||
this[klassKey] = klass;
|
||||
this[idKey] = idField;
|
||||
this[clientKey] = request;
|
||||
this[secondaryActionKey] = secondaryAction;
|
||||
this[secondaryKlassKey] = secondaryKlass;
|
||||
this[secondaryIdKey] = secondaryIdField;
|
||||
}
|
||||
|
||||
executeAction(task = '', secondaryTask = '', method = 'GET', params = {}, action, secondaryAction) {
|
||||
let client = this[clientKey];
|
||||
action = action == null ? this[actionKey] : action;
|
||||
let idField = this[idKey];
|
||||
secondaryAction = secondaryAction == null ? this[secondaryActionKey] : secondaryAction;
|
||||
let secondaryIdField = this[secondaryIdKey]
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
client(method, action + task + '/' + secondaryAction + secondaryTask, params)
|
||||
.then(response => {
|
||||
resolve(new PlivoGenericResponse(response.body, secondaryIdField));
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class PlivoResourceInterface {
|
||||
constructor(action, klass, idField, request) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {extend, validate} from '../utils/common.js';
|
||||
import {PlivoResource, PlivoResourceInterface} from '../base';
|
||||
import {PlivoResource, PlivoResourceInterface, PlivoSecondaryResource} from '../base';
|
||||
import {
|
||||
validSubAccount,
|
||||
validUrl,
|
||||
|
|
@ -13,8 +13,8 @@ import {
|
|||
const clientKey = Symbol();
|
||||
const action = 'MultiPartyCall/';
|
||||
const idField = 'mpcUuid';
|
||||
// const secondaryAction = 'Participant/';
|
||||
// const secondaryIdField = 'participantUuid';
|
||||
const secondaryAction = 'Participant/';
|
||||
const secondaryIdField = 'participantUuid';
|
||||
|
||||
export class MPCError extends Error { }
|
||||
|
||||
|
|
@ -338,23 +338,47 @@ export class MultiPartyCall extends PlivoResource{
|
|||
}
|
||||
}
|
||||
|
||||
// export class MultiPartyCallParticipant extends PlivoSecondaryResource{
|
||||
// constructor(client, data = {}) {
|
||||
// super(action, MultiPartyCall, idField, secondaryAction, MultiPartyCallParticipant, secondaryIdField, client);
|
||||
//
|
||||
// if (idField in data) {
|
||||
// this.id = data[idField];
|
||||
// }
|
||||
//
|
||||
// if(secondaryIdField in data){
|
||||
// this.secondaryId = data[secondaryIdField];
|
||||
// }
|
||||
//
|
||||
// extend(this, data);
|
||||
// this[clientKey] = client;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
export class MultiPartyCallParticipant extends PlivoSecondaryResource{
|
||||
constructor(client, data = {}) {
|
||||
super(action, MultiPartyCall, idField, secondaryAction, MultiPartyCallParticipant, secondaryIdField, client);
|
||||
|
||||
if (idField in data) {
|
||||
this.id = data[idField];
|
||||
}
|
||||
|
||||
if(secondaryIdField in data){
|
||||
this.secondaryId = data[secondaryIdField];
|
||||
}
|
||||
|
||||
extend(this, data);
|
||||
this[clientKey] = client;
|
||||
}
|
||||
|
||||
updateParticipant(params){
|
||||
if(params.coachMode){
|
||||
validParam('coachMode', params.coachMode, [Boolean], false)
|
||||
}
|
||||
|
||||
if(params.mute){
|
||||
validParam('mute', params.mute, [Boolean], false)
|
||||
}
|
||||
|
||||
if(params.hold){
|
||||
validParam('hold', params.hold, [Boolean], false)
|
||||
}
|
||||
|
||||
return super.executeAction(this.id, this.secondaryId, 'POST', params)
|
||||
}
|
||||
|
||||
kickParticipant(){
|
||||
return super.executeAction(this.id, this.secondaryId, 'DELETE')
|
||||
}
|
||||
|
||||
getParticipant(){
|
||||
return super.executeAction(this.id, this.secondaryId, 'GET')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class MultiPartyCallInterface extends PlivoResourceInterface{
|
||||
constructor(client, data = {}) {
|
||||
|
|
@ -555,5 +579,46 @@ export class MultiPartyCallInterface extends PlivoResourceInterface{
|
|||
return new MultiPartyCall(this[clientKey], {id: mpcId[0] + mpcId[1]}).listParticipants(params)
|
||||
}
|
||||
|
||||
updateParticipant(participantId, uuid= null, friendlyName = null, params){
|
||||
if(participantId){
|
||||
validParam('participantId', participantId, [String, Number], true)
|
||||
}
|
||||
if(uuid){
|
||||
validParam('uuid', uuid, [String], false)
|
||||
}
|
||||
if(friendlyName){
|
||||
validParam('friendlyName', friendlyName, [String], false)
|
||||
}
|
||||
let mpcId = this.makeMpcId(uuid, friendlyName)
|
||||
return new MultiPartyCallParticipant(this[clientKey], {id: mpcId[0] + mpcId[1], secondaryId: participantId}).updateParticipant(params)
|
||||
}
|
||||
|
||||
kickParticipant(participantId, uuid = null, friendlyName = null){
|
||||
if(participantId){
|
||||
validParam('participantId', participantId, [String, Number], true)
|
||||
}
|
||||
if(uuid){
|
||||
validParam('uuid', uuid, [String], false)
|
||||
}
|
||||
if(friendlyName){
|
||||
validParam('friendlyName', friendlyName, [String], false)
|
||||
}
|
||||
let mpcId = this.makeMpcId(uuid, friendlyName)
|
||||
return new MultiPartyCallParticipant(this[clientKey], {id: mpcId[0] + mpcId[1], secondaryId: participantId}).kickParticipant()
|
||||
}
|
||||
|
||||
getParticipant(participantId, uuid = null, friendlyName = null){
|
||||
if(participantId){
|
||||
validParam('participantId', participantId, [String, Number], true)
|
||||
}
|
||||
if(uuid){
|
||||
validParam('uuid', uuid, [String], false)
|
||||
}
|
||||
if(friendlyName){
|
||||
validParam('friendlyName', friendlyName, [String], false)
|
||||
}
|
||||
let mpcId = this.makeMpcId(uuid, friendlyName)
|
||||
return new MultiPartyCallParticipant(this[clientKey], {id: mpcId[0] + mpcId[1], secondaryId: participantId}).getParticipant()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue