Skip to content

Commit

Permalink
Merge pull request #224 from plivo/VT-4697
Browse files Browse the repository at this point in the history
VT-4697 (Audio Streaming)
  • Loading branch information
abhishekGupta-Plivo authored Jun 29, 2023
2 parents c6d8ef6 + 8e159c5 commit 31abccf
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [v5.31.0](https://github.com/plivo/plivo-dotnet/tree/v5.31.0) (2023-06-28)
**Feature - Streaming API and XML**
- Added Stream API endpoints
- Added Stream XML creation ability

## [5.30.0](https://github.com/plivo/plivo-dotnet/tree/v5.30.0) (2023-05-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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ You can install this SDK either by referencing the .dll file or using NuGet.
Use the following line to install the latest SDK using the NuGet CLI.

```
PM> Install-Package Plivo -Version 5.28.0
PM> Install-Package Plivo -Version 5.31.0
```

You can also use the .NET CLI to install this package as follows

```
> dotnet add package Plivo --version 5.28.0
> dotnet add package Plivo --version 5.31.0
```

## Getting started
Expand Down
2 changes: 1 addition & 1 deletion src/Plivo/Plivo.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.3</TargetFrameworks>
<ReleaseVersion>5.30.0</ReleaseVersion>
<ReleaseVersion>5.31.0</ReleaseVersion>
<Version />
<Authors>Plivo SDKs Team</Authors>
<Owners>Plivo Inc.</Owners>
Expand Down
3 changes: 2 additions & 1 deletion src/Plivo/Plivo.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<summary>A .NET SDK to make voice calls and send SMS using Plivo and to generate Plivo XML</summary>
<description>A .NET SDK to make voice calls and send SMS using Plivo and to generate Plivo XML</description>
<id>Plivo</id>
<version>5.30.0</version>
<version>5.31.0</version>
<title>Plivo</title>
<authors>Plivo SDKs Team</authors>
<owners>Plivo, Inc.</owners>
<licenseUrl>https://github.com/plivo/plivo-dotnet/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>http://github.com/plivo/plivo-dotnet</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>
* 5.31.0 Added functionality to start, stop and fetch audio streams
* 5.30.0 Added New Param 'cnam_lookup' in to the response of the [list all numbers API], [list single number API]
* 5.29.0 Added New Param 'cnam_lookup_number_config' in GetCall and ListCalls
* 5.28.0 Added new Params 'MonthlyRecordingStorageAmount', 'RecordingStorageRate', 'RecordingStorageDuration' and 'RoundedRecordingDuration' to List Recordings and Get Recording APIs
Expand Down
69 changes: 69 additions & 0 deletions src/Plivo/Resource/Call/Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,75 @@ public async Task<AsyncResponse> CancelCallAsync(string callbackUrl = null, stri
.CancelCallAsync(Id, callbackUrl, callbackMethod);
}
#endregion

#region StartStream
public StreamCreateResponse StartStream(
string callUuid = null, string serviceUrl = null, string bidirectional = null,
string audioTrack = null, string streamTimeout = null,
string statusCallbackUrl = null, string statusCallbackMethod = null,
string contentType = null, string extraHeaders = null)
{
return ((CallInterface)Interface).StartStream(callUuid, serviceUrl, bidirectional, audioTrack,
streamTimeout, statusCallbackUrl, statusCallbackMethod, contentType, extraHeaders);
}

public async Task<Stream.AsyncResponse> StartStreamAsync(
string callUuid = null, string serviceUrl = null, string bidirectional = null,
string audioTrack = null, string streamTimeout = null,
string statusCallbackUrl = null, string statusCallbackMethod = null,
string contentType = null, string extraHeaders = null)
{
return await ((CallInterface)Interface).StartStreamAsync(callUuid, serviceUrl, bidirectional, audioTrack,
streamTimeout, statusCallbackUrl, statusCallbackMethod, contentType, extraHeaders);
}
#endregion

#region GetStream
public ListResponse<Stream.Stream> GetAllStreams(
string callUuid = null)
{
return ((CallInterface)Interface).GetAllStreams(callUuid);
}

public async Task<AsyncResponse> GetAllStreamsAsync(
string callUuid = null)
{
return await ((CallInterface)Interface).GetAllStreamsAsync(callUuid);
}

public Stream.Stream GetStream(string callUuid = null, string streamId = null)
{
return ((CallInterface)Interface).GetStream(callUuid, streamId);
}

public async Task<AsyncResponse> GetStreamAsync(string callUuid = null, string streamId = null)
{
return await ((CallInterface)Interface).GetStreamAsync(callUuid, streamId);
}
#endregion

#region StopStream
public DeleteResponse<Stream.Stream> StopStream(string callUuid = null, string streamId = null)
{
return ((CallInterface)Interface).StopStream(callUuid, streamId);
}

public async Task<AsyncResponse> StopStreamAsync (string callUuid = null, string streamId = null) {
return await ((CallInterface)Interface).StopStreamAsync(callUuid, streamId);
}

public DeleteResponse<Stream.Stream> StopAllStreams(string callUuid = null)
{
return ((CallInterface)Interface).StopAllStreams(callUuid);
}

public async Task<AsyncResponse> StopAllStreamAsync(string callUuid = null)
{
return await ((CallInterface)Interface).StopAllStreamsAsync(callUuid);
}
#endregion


/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:plivo.Resource.Call.Call"/>.
/// </summary>
Expand Down
246 changes: 246 additions & 0 deletions src/Plivo/Resource/Call/CallInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,5 +1264,251 @@ public async Task<AsyncResponse> CancelCallAsync (string requestUuid = null, str
return result.Object;
}
#endregion

#region StartStream
/// <summary>
/// Starts the recording.
/// </summary>
/// <returns>The stream.</returns>
/// <param name="callUuid">Call UUID.</param>
/// <param name="serviceUrl">Call UUID.</param>
/// <param name="bidirectional">Time limit.</param>
/// <param name="audioTrack">File format.</param>
/// <param name="streamTimeout">Transaction type.</param>
/// <param name="statusCallbackUrl">Transaction URL.</param>
/// <param name="statusCallbackMethod">Transaction method.</param>
/// <param name="contentType">Callback URL.</param>
/// <param name="extraHeaders">Callback method.</param>
public StreamCreateResponse StartStream (
string callUuid = null, string serviceUrl = null, string bidirectional = null,
string audioTrack = null, string streamTimeout = null,
string statusCallbackUrl = null, string statusCallbackMethod = null,
string contentType = null, string extraHeaders = null) {
StreamUtils.ValidParamString("callUuid",callUuid,true);
var mandatoryParams = new List<string> { "serviceUrl" };
bool isVoiceRequest = true;
var data = CreateData (
mandatoryParams,
new {
serviceUrl,
bidirectional,
audioTrack,
streamTimeout,
statusCallbackUrl,
statusCallbackMethod,
contentType,
extraHeaders,
isVoiceRequest
});

return ExecuteWithExceptionUnwrap(() =>
{
var result = Task.Run (async () => await Client.Update<StreamCreateResponse> (Uri + callUuid + "/Stream/", data).ConfigureAwait (false)).Result;
result.Object.StatusCode = result.StatusCode;
JObject responseJson = JObject.Parse(result.Content);
result.Object.ApiId = responseJson["api_id"].ToString();
result.Object.StreamId = responseJson["stream_id"].ToString();
result.Object.Message = responseJson["message"].ToString();
return result.Object;
});
}

/// <summary>
/// Asynchronously starts the recording.
/// </summary>
/// <returns>The stream.</returns>
/// <param name="callUuid">Call UUID.</param>
/// <param name="serviceUrl">Call UUID.</param>
/// <param name="bidirectional">Time limit.</param>
/// <param name="audioTrack">File format.</param>
/// <param name="streamTimeout">Transaction type.</param>
/// <param name="statusCallbackUrl">Transaction URL.</param>
/// <param name="statusCallbackMethod">Transaction method.</param>
/// <param name="contentType">Callback URL.</param>
/// <param name="extraHeaders">Callback method.</param>
public async Task<Stream.AsyncResponse> StartStreamAsync (
string callUuid = null, string serviceUrl = null, string bidirectional = null,
string audioTrack = null, string streamTimeout = null,
string statusCallbackUrl = null, string statusCallbackMethod = null,
string contentType = null, string extraHeaders = null) {
StreamUtils.ValidParamString("callUuid",callUuid,true);
var mandatoryParams = new List<string> { "serviceUrl" };
bool isVoiceRequest = true;
var data = CreateData (
mandatoryParams,
new {
serviceUrl,
bidirectional,
audioTrack,
streamTimeout,
statusCallbackUrl,
statusCallbackMethod,
contentType,
extraHeaders,
isVoiceRequest
});

var result = Task.Run (async () => await Client.Update<Stream.AsyncResponse> (Uri + callUuid + "/Stream/", data).ConfigureAwait (false)).Result;
await Task.WhenAll();
result.Object.StatusCode = result.StatusCode;
JObject responseJson = JObject.Parse(result.Content);
result.Object.ApiId = responseJson["api_id"].ToString();
result.Object.Message = responseJson["message"].ToString();
return result.Object;
}
#endregion

#region GetStream
public ListResponse<Stream.Stream> GetAllStreams(
string callUuid = null)
{
StreamUtils.ValidParamString("callUuid",callUuid,true);
var mandatoryParams = new List<string> { "callUuid" };
bool isVoiceRequest = true;
var data = CreateData(
mandatoryParams,
new
{
callUuid,
isVoiceRequest
});

return ExecuteWithExceptionUnwrap (() =>
{
var resources = Task.Run (async () => await ListResources<ListResponse<Stream.Stream>>(callUuid + "/Stream" , data).ConfigureAwait(false)).Result;
resources.Objects.ForEach (
(obj) => obj.Interface = this
);
return resources;
});
}

public async Task<AsyncResponse> GetAllStreamsAsync(
string callUuid = null)
{
StreamUtils.ValidParamString("callUuid",callUuid,true);
var mandatoryParams = new List<string> { "callUuid" };
bool isVoiceRequest = true;
var data = CreateData(
mandatoryParams,
new
{
callUuid,
isVoiceRequest
});
var result = Task.Run (async () => await Client.Fetch<AsyncResponse> (callUuid + "/Stream" , data).ConfigureAwait(false)).Result;
await Task.WhenAll();
result.Object.StatusCode = result.StatusCode;
JObject responseJson = JObject.Parse(result.Content);
result.Object.ApiId = responseJson["api_id"].ToString();
result.Object.Message = responseJson["message"].ToString();
return result.Object;
}

public Stream.Stream GetStream(string callUuid = null, string streamId = null)
{
StreamUtils.ValidParamString("callUuid", callUuid, true);
StreamUtils.ValidParamString("streamId", streamId, true);

return ExecuteWithExceptionUnwrap(() =>
{
var stream = Task.Run(async () =>
await GetSecondaryResource<Stream.Stream>(callUuid,
new Dictionary<string, object>() {{"is_voice_request", true}},
"Stream", streamId).ConfigureAwait(false)).Result;
stream.Interface = this;
return stream;
});
}

public async Task<AsyncResponse> GetStreamAsync(string callUuid = null, string streamId = null)
{
StreamUtils.ValidParamString("callUuid", callUuid, true);
StreamUtils.ValidParamString("streamId", streamId, true);

var result = Task.Run (async () => await Client.Fetch<AsyncResponse> (
Uri + callUuid + "/Stream/" + streamId + "/",
new Dictionary<string, object>() {{"is_voice_request", true}}).ConfigureAwait(false)).Result;
await Task.WhenAll();
result.Object.StatusCode = result.StatusCode;
JObject responseJson = JObject.Parse(result.Content);
result.Object.ApiId = responseJson["api_id"].ToString();
result.Object.Message = responseJson["message"].ToString();
return result.Object;
}
#endregion

#region StopStream
public DeleteResponse<Stream.Stream> StopStream (string callUuid = null, string streamId = null) {
StreamUtils.ValidParamString("callUuid",callUuid,true);
StreamUtils.ValidParamString("streamId",streamId,true);
var mandatoryParams = new List<string> { "" };
bool isVoiceRequest = true;
var data = CreateData (
mandatoryParams, new { isVoiceRequest });

return ExecuteWithExceptionUnwrap (() => {
var result = Task.Run (async () =>
await Client.Delete<DeleteResponse<Stream.Stream>> (Uri + callUuid + "/Stream/" + streamId, data).
ConfigureAwait (false)).Result;
try {
result.Object.StatusCode = result.StatusCode;
} catch (System.NullReferenceException) {
}
return result.Object;
});
}

public async Task<AsyncResponse> StopStreamAsync (string callUuid = null, string streamId = null) {
StreamUtils.ValidParamString("callUuid",callUuid,true);
StreamUtils.ValidParamString("streamId",streamId,true);
var mandatoryParams = new List<string> { "" };
bool isVoiceRequest = true;
var data = CreateData (
mandatoryParams, new { isVoiceRequest });

var result = Task.Run (async () =>
await Client.Delete<AsyncResponse> (Uri + callUuid + "/Stream/" + streamId, data).ConfigureAwait (false)).Result;
await Task.WhenAll();
result.Object.StatusCode = result.StatusCode;
return result.Object;
}

public DeleteResponse<Stream.Stream> StopAllStreams (string callUuid = null) {
StreamUtils.ValidParamString("callUuid",callUuid,true);
var mandatoryParams = new List<string> { "" };
bool isVoiceRequest = true;
var data = CreateData (
mandatoryParams, new { isVoiceRequest });

return ExecuteWithExceptionUnwrap (() => {
var result = Task.Run (async () =>
await Client.Delete<DeleteResponse<Stream.Stream>> (Uri + callUuid + "/Stream/", data).
ConfigureAwait (false)).Result;
try {
result.Object.StatusCode = result.StatusCode;
} catch (System.NullReferenceException) {
}
return result.Object;
});
}

public async Task<AsyncResponse> StopAllStreamsAsync (string callUuid = null) {
StreamUtils.ValidParamString("callUuid",callUuid,true);
var mandatoryParams = new List<string> { "" };
bool isVoiceRequest = true;
var data = CreateData (
mandatoryParams, new { isVoiceRequest });

var result = Task.Run (async () =>
await Client.Delete<AsyncResponse> (Uri + callUuid + "/Stream/", data).ConfigureAwait (false)).Result;
await Task.WhenAll();
result.Object.StatusCode = result.StatusCode;
return result.Object;
}
#endregion
}
}
6 changes: 6 additions & 0 deletions src/Plivo/Resource/Stream/AsyncResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Plivo.Resource.Stream
{
public class AsyncResponse : BaseResponse
{
}
}
Loading

0 comments on commit 31abccf

Please sign in to comment.