| 1 |
** |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
using System; |
| 12 |
using System.Diagnostics; |
| 13 |
using System.Threading.Tasks; |
| 14 |
using VoipTasks.BackgroundOperations; |
| 15 |
using Windows.ApplicationModel.Calls; |
| 16 |
using Windows.Foundation.Collections; |
| 17 |
using Windows.Foundation.Metadata; |
| 18 |
using VoipBackEnd; |
| 19 |
|
| 20 |
namespace VoipTasks.Helpers |
| 21 |
{ |
| 22 |
class VccCallHelper |
| 23 |
{ |
| 24 |
private int RTcTaskAlreadyRuningErrorCode = -2147024713; |
| 25 |
public async Task<VoipPhoneCallResourceReservationStatus> RequestNewCallAsync(string dstURI) |
| 26 |
{ |
| 27 |
VoipPhoneCallResourceReservationStatus status = VoipPhoneCallResourceReservationStatus.ResourcesNotAvailable; |
| 28 |
|
| 29 |
status = await LaunchRTCTaskAsync(); |
| 30 |
if (status == VoipPhoneCallResourceReservationStatus.Success) |
| 31 |
{ |
| 32 |
NewOutgoingCall(dstURI); |
| 33 |
} |
| 34 |
|
| 35 |
Current.Request = BackgroundRequest.InValid; |
| 36 |
|
| 37 |
return status; |
| 38 |
} |
| 39 |
|
| 40 |
private async Task<VoipPhoneCallResourceReservationStatus> LaunchRTCTaskAsync() |
| 41 |
{ |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
Current.EndCall(); |
| 47 |
|
| 48 |
VoipCallCoordinator vCC = VoipCallCoordinator.GetDefault(); |
| 49 |
VoipPhoneCallResourceReservationStatus status = VoipPhoneCallResourceReservationStatus.ResourcesNotAvailable; |
| 50 |
|
| 51 |
try |
| 52 |
{ |
| 53 |
status = await vCC.ReserveCallResourcesAsync(Current.RtcCallTaskName); |
| 54 |
} |
| 55 |
catch (Exception ex) |
| 56 |
{ |
| 57 |
if (ex.HResult == RTcTaskAlreadyRuningErrorCode ) |
| 58 |
{ |
| 59 |
Debug.WriteLine("RTC Task Already running"); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return status; |
| 64 |
} |
| 65 |
|
| 66 |
internal void NewOutgoingCall(string dstURI) |
| 67 |
{ |
| 68 |
bool status = false; |
| 69 |
try |
| 70 |
{ |
| 71 |
VoipCallCoordinator vCC = VoipCallCoordinator.GetDefault(); |
| 72 |
VoipPhoneCall call = vCC.RequestNewOutgoingCall( "Pjsua Test Call ", dstURI, "", VoipPhoneCallMedia.Audio); |
| 73 |
if (call != null) |
| 74 |
{ |
| 75 |
call.EndRequested += Call_EndRequested; |
| 76 |
call.RejectRequested += Call_RejectRequested; |
| 77 |
|
| 78 |
call.NotifyCallActive(); |
| 79 |
|
| 80 |
Current.VoipCall = call; |
| 81 |
|
| 82 |
MyAppRT.Instance.makeCall(dstURI); |
| 83 |
|
| 84 |
status = true; |
| 85 |
} |
| 86 |
} |
| 87 |
catch (Exception e) |
| 88 |
{ |
| 89 |
Debug.WriteLine(e.ToString()); |
| 90 |
} |
| 91 |
|
| 92 |
ValueSet response = new ValueSet(); |
| 93 |
response[BackgroundOperation.Result] = status ? (int)OperationResult.Succeeded : (int)OperationResult.Failed; |
| 94 |
|
| 95 |
Current.SendResponse(response); |
| 96 |
} |
| 97 |
|
| 98 |
internal void NewIncomingCall(string context, string contactName, string serviceName) |
| 99 |
{ |
| 100 |
try |
| 101 |
{ |
| 102 |
VoipCallCoordinator vCC = VoipCallCoordinator.GetDefault(); |
| 103 |
VoipPhoneCall call = vCC.RequestNewIncomingCall( |
| 104 |
"Hello", |
| 105 |
contactName, |
| 106 |
context, |
| 107 |
new Uri("file://c:/data/test/bin/FakeVoipAppLight.png"), |
| 108 |
serviceName, |
| 109 |
new Uri("file://c:/data/test/bin/FakeVoipAppLight.png"), |
| 110 |
"", |
| 111 |
new Uri("file://c:/data/test/bin/FakeVoipAppRingtone.wma"), |
| 112 |
VoipPhoneCallMedia.Audio, |
| 113 |
new TimeSpan(0, 1, 20)); |
| 114 |
if (call != null) |
| 115 |
{ |
| 116 |
call.AnswerRequested += Call_AnswerRequested; |
| 117 |
call.EndRequested += Call_EndRequested; |
| 118 |
call.RejectRequested += Call_RejectRequested; |
| 119 |
|
| 120 |
Current.VoipCall = call; |
| 121 |
} |
| 122 |
} |
| 123 |
catch (Exception e) |
| 124 |
{ |
| 125 |
Debug.WriteLine(e.ToString()); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
private void Call_RejectRequested(VoipPhoneCall sender, CallRejectEventArgs args) |
| 130 |
{ |
| 131 |
Current.EndCall(); |
| 132 |
} |
| 133 |
|
| 134 |
private void Call_EndRequested(VoipPhoneCall sender, CallStateChangeEventArgs args) |
| 135 |
{ |
| 136 |
Current.EndCall(); |
| 137 |
} |
| 138 |
|
| 139 |
private void Call_AnswerRequested(VoipPhoneCall sender, CallAnswerEventArgs args) |
| 140 |
{ |
| 141 |
CallOpParamRT param = new CallOpParamRT(); |
| 142 |
param.statusCode = 200; |
| 143 |
param.reason = "OK"; |
| 144 |
|
| 145 |
try |
| 146 |
{ |
| 147 |
Current.MyApp.answerCall(param); |
| 148 |
} |
| 149 |
catch (Exception ex) |
| 150 |
{ |
| 151 |
Current.MyApp.writeLog(2, ex.Message); |
| 152 |
} |
| 153 |
Current.VoipCall = sender; |
| 154 |
try |
| 155 |
{ |
| 156 |
Current.VoipCall.NotifyCallActive(); |
| 157 |
} |
| 158 |
catch (Exception ex) |
| 159 |
{ |
| 160 |
Current.MyApp.writeLog(2, ex.Message); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |