Skip to content

Commit

Permalink
Merge pull request #263 from plivo/VT-4655
Browse files Browse the repository at this point in the history
VT-4655 (Audio Streaming)
  • Loading branch information
abhishekGupta-Plivo authored Jun 29, 2023
2 parents 248d8b3 + cb1128f commit f128549
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 90 deletions.
12 changes: 4 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [v4.50.0](https://github.com/plivo/plivo-go/tree/v4.50.0) (2023-06-28)
**Feature - Audio Streaming**
- `Audio Stream over Call` added API to start and stop streaming on a live call and get details of running or stopped streams. Also implemented the ability to generate stream XML.

## [4.49.0](https://github.com/plivo/plivo-node/tree/v4.49.0) (2023-06-02)
**Feature - CNAM Lookup**
- Added New Param `cnam_lookup` in to the response of the [list all numbers API], [list single number API]
Expand Down Expand Up @@ -66,14 +70,6 @@
**Delete Brand and Campaign Request**
- Delete Brand and Campaign Request endpoint added

## [v4.37.0](https://github.com/plivo/plivo-node/tree/v4.37.0) (2022-12-16)
**Update Campaign Request**
- Update Campaign Request endpoint added

## [v4.36.0](https://github.com/plivo/plivo-node/tree/v4.36.0) (2022-12-06)
**Delete Brand and Campaign Request**
- Delete Brand and Campaign Request endpoint added

## [v4.35.0](https://github.com/plivo/plivo-node/tree/v4.35.0) (2022-11-04)
**Brand Usecase Request**
- Brand Usecase Request endpoint added
Expand Down
183 changes: 182 additions & 1 deletion lib/resources/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class CreateCallResponse {
}
}


export class GetQueuedCallResponse {
constructor(params) {
params = params || {};
Expand Down Expand Up @@ -172,6 +171,15 @@ export class RecordCallResponse {
}
}

export class StartStreamResponse {
constructor(params) {
params = params || {};
this.apiId = params.apiId;
this.message = params.message;
this.streamId = params.streamId;
}
}

/**
* Represents a Call
* @constructor
Expand Down Expand Up @@ -235,6 +243,60 @@ export class Call extends PlivoResource {
});
});
}


/**
* start audio stream over a call
* @method
* @param {object} params - to start stream
* @promise {object} return PlivoGenericResponse Object
* @fail {Error} return Error
*/
stream(params= {}) {
params.isVoiceRequest = 'true';
return this.startStreaming(params);
}

/**
* start audio stream over a call
* @method
* @param {object} params - to start stream
* @promise {object} return PlivoGenericResponse Object
* @fail {Error} return Error
*/
startStreaming(params) {
let client = this[clientKey];
return new Promise((resolve, reject) => {
client('POST', action + this.id + '/Stream/', params)
.then(response => {
resolve(new StartStreamResponse(response.body, idField));
})
.catch(error => {
reject(error);
});
});
}

stopStream(params= {}) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Stream/' + this.secondaryId, 'DELETE', params);
}

stopAllStream(params= {}) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Stream/', 'DELETE', params);
}

getStream(params= {}) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Stream/' + this.secondaryId, 'GET', params);
}

getAllStream(params= {}) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Stream/', 'GET', params);
}

/**
* record call
* @method
Expand Down Expand Up @@ -645,6 +707,125 @@ export class CallInterface extends PlivoResourceInterface {
}).transfer(params, callUUID);
}

/**
* Start a Stream over a Call
* @method
* @param {string} serviceUrl - Wss url over which data packets will be send.
* @param {string} callUuid - For this callUuid audio streaming will start.
* @param {object} params - optional params to start a stream
* @param {string} [params.bidirectional] Specifies if the audio being streamed over web-sockets is oneway (read only for the wss service) only or bidirectional (the wss service can read as well as write audio back).
* @param {string} [params.audioTrack] The audio track (inbound or outbound) of the underlying call which Plivo will fork and stream to the wss service. Inbound [default], outbound, both. Note: only inbound is allowed if bidirectional is true.
* @param {string} [params.streamTimeout] Maximum duration, in seconds, for which audio will be streamed once streaming starts. At the end of the specified duration, streaming will stop. This will have no impact on the rest of the call flow. Defaults to 86400 (24 hrs).
* @param {string} [params.statusCallbackUrl] URL that is notified by Plivo when stream is connected, stopped, failed to connect or disconnected. Note: not called when the call gets disconnected.
* @param {string} [params.statusCallbackMethod] POST[default], GET.
* @param {string} [params.contentType] Preferred audio codec and sampling rate. Allowed, audio/x-l16;rate=8000 [default], audio/x-l16;rate=16000 and audio/x-mulaw;rate=8000.
* @param {string} [params.extraHeaders] These are key value pairs which will be passed to the wss service along with your stream. Total length of the string being passed should be less than equal to 512 bytes.
* @promise {object} returns PlivoGenericResponse Object
* @fail {Error} returns Error
*/
stream(callUUID, serviceUrl, optionalParams = {}) {
let errors = validate([{
field: 'serviceUrl',
value: serviceUrl,
validators: ['isRequired']
},
{
field: 'callUUID',
value: callUUID,
validators: ['isRequired']
}
]);

if (errors) {
return errors;
}

optionalParams.serviceUrl = serviceUrl
return new Call(this[clientKey], {
id: callUUID
}).stream(optionalParams);
}

stopStream(callUUID, streamId){
let errors = validate([{
field: 'callUUID',
value: callUUID,
validators: ['isRequired']
},
{
field: 'streamId',
value: streamId,
validators: ['isRequired']
}
]);

if (errors) {
return errors;
}

return new Call(this[clientKey], {
id: callUUID,
secondaryId: streamId
}).stopStream();
}

stopAllStream(callUUID){
let errors = validate([{
field: 'callUUID',
value: callUUID,
validators: ['isRequired']
}
]);

if (errors) {
return errors;
}

return new Call(this[clientKey], {
id: callUUID
}).stopAllStream();
}

getStream(callUUID, streamId){
let errors = validate([{
field: 'callUUID',
value: callUUID,
validators: ['isRequired']
},
{
field: 'streamId',
value: streamId,
validators: ['isRequired']
}
]);

if (errors) {
return errors;
}

return new Call(this[clientKey], {
id: callUUID,
secondaryId: streamId
}).getStream();
}

getAllStream(callUUID){
let errors = validate([{
field: 'callUUID',
value: callUUID,
validators: ['isRequired']
}
]);

if (errors) {
return errors;
}

return new Call(this[clientKey], {
id: callUUID
}).getAllStream();
}

/**
* Record a Call
* @method
Expand Down
10 changes: 10 additions & 0 deletions lib/rest/request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ export function Request(config) {
}
});
}
else if (action == 'Call/aaa-deeiei3-dfddd/Stream/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'stream started',
stream_id: 'db1d8121-1a75-4b75-bb69-35339bb26240',
api_id: 'c7b69074-58be-11e1-86da-adf28403fe48'
}
});
}
else if (action == 'Call/aaa-deeiei3-dfddd/Record/' && method == 'DELETE') {
resolve({
response: {},
Expand Down
Loading

0 comments on commit f128549

Please sign in to comment.