/// <summary> /// A method that is called as a result of /// </summary> protected override void OnLaunched() { Debug.WriteLine("[ForegroundLifetimeAgentImpl] The UI has entered the foreground."); // Indicate that an agent has started running AgentHost.OnAgentStarted(); }
/// <summary> /// The first call has become active. /// </summary> protected override void OnFirstCallStarting() { Debug.WriteLine("[CallInProgressAgentImpl] The first call has started."); // Indicate that an agent has started running AgentHost.OnAgentStarted(); }
/// <summary> /// The first call has become active. /// </summary> protected override void OnFirstCallStarting() { Debug.WriteLine("[CallInProgressAgentImpl {0}] The first call has started.", GetHashCode()); Log("Start timer"); // Indicate that an agent has started running AgentHost.OnAgentStarted(); _timer.Change(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(5.0)); }
/// <summary> /// Agent that runs a scheduled task /// </summary> protected override void OnInvoke(ScheduledTask task) { Debug.WriteLine("[ScheduledAgentImpl] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType()); // Indicate that an agent has started running AgentHost.OnAgentStarted(); VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask; if (incomingCallTask != null) { this.isIncomingCallAgent = true; // Parse the the incoming push notification payload Notification pushNotification; using (MemoryStream ms = new MemoryStream(incomingCallTask.MessageBody)) { XmlSerializer xs = new XmlSerializer(typeof(Notification)); pushNotification = (Notification)xs.Deserialize(ms); } Debug.WriteLine("[{0}] Incoming call from caller {1}, number {2}", ScheduledAgentImpl.incomingCallAgentId, pushNotification.Name, pushNotification.Number); // Initiate incoming call processing // If you want to pass in additional information such as pushNotification.Number, you can bool incomingCallProcessingStarted = BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(pushNotification.Name, pushNotification.Number, this.OnIncomingCallDialogDismissed); if (!incomingCallProcessingStarted) { // For some reasons, the incoming call processing was not started. // There is nothing more to do. this.Complete(); return; } } else { VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask; if (keepAliveTask != null) { this.isIncomingCallAgent = false; // Refresh tokens, get new certs from server, etc. BackEnd.Globals.Instance.DoPeriodicKeepAlive(); this.Complete(); } else { throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType())); } } }
protected override void OnInvoke(ScheduledTask task) { Debug.WriteLine("[ScheduledAgentImpl {0}] ScheduledAgentImpl has been invoked with argument of type {1}.", GetHashCode(), task.GetType()); // Indicate that an agent has started running AgentHost.OnAgentStarted(); Log(string.Format("start with argument of type {0}", task.GetType())); if (!_appOpenMutex.WaitOne(0)) { Log("cancel"); Complete(); return; } _appOpenMutex.ReleaseMutex(); var incomingCallTask = task as VoipHttpIncomingCallTask; if (incomingCallTask != null) { isIncomingCallAgent = true; var messageBody = HttpUtility.HtmlDecode(Encoding.UTF8.GetString(incomingCallTask.MessageBody, 0, incomingCallTask.MessageBody.Length)); Notification pushNotification = null; try { using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(messageBody ?? string.Empty))) { var xs = new XmlSerializer(typeof(Notification)); pushNotification = (Notification)xs.Deserialize(ms); } } catch (Exception ex) { Log(string.Format("cannot deserialize message_body={0}", messageBody)); #if DEBUG var toastNotifier = ToastNotificationManager.CreateToastNotifier(); var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); SetText(toastXml, "Notification Exception", string.Empty); try { var toast = new ToastNotification(toastXml); //RemoveToastGroup(group); toastNotifier.Show(toast); } catch (Exception ex2) { Telegram.Logs.Log.Write(ex.ToString()); } #endif } if (pushNotification != null) { var rootObject = PushUtils2.GetRootObject <RootObject>(pushNotification.Data); if (rootObject != null && rootObject.data != null) { if (rootObject.data.custom != null && rootObject.data.custom.from_id != null && rootObject.data.custom.call_id != null && rootObject.data.custom.call_ah != null) { var contactImage = PushUtils2.GetImageSource(rootObject.data.custom.mtpeer) ?? string.Empty; var contactName = rootObject.data.loc_args != null && rootObject.data.loc_args.Length > 0 ? rootObject.data.loc_args[0] : string.Empty; Debug.WriteLine("[{0}] Incoming call from caller {1}, id {2}", incomingCallAgentId, contactName, rootObject.data.custom.from_id); long contactId = 0; long callId = 0; long callAccessHash = 0; if (long.TryParse(rootObject.data.custom.from_id, out contactId) && long.TryParse(rootObject.data.custom.call_id, out callId) && long.TryParse(rootObject.data.custom.call_ah, out callAccessHash)) { if (string.Equals(rootObject.data.loc_key, "PHONE_CALL_REQUEST", StringComparison.OrdinalIgnoreCase)) { if (BackEnd.Globals.Instance.CallController.CallStatus == CallStatus.InProgress) { OnIncomingCallDialogDismissed(callId, callAccessHash, true); return; } // Initiate incoming call processing // If you want to pass in additional information such as pushNotification.Number, you can var incomingCallProcessingStarted = BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(contactName, contactId, contactImage, callId, callAccessHash, OnIncomingCallDialogDismissed); if (incomingCallProcessingStarted) { // will Complete() at OnIncomingCallDialogDismissed return; } //PushUtils2.AddToast(rootObject, "Caption", "Message", "", "", "tag", "group"); } else if (string.Equals(rootObject.data.loc_key, "PHONE_CALL_DECLINE", StringComparison.OrdinalIgnoreCase)) { var currentCallId = BackEnd.Globals.Instance.CallController.CallId; if (currentCallId == callId) { Log(string.Format("PHONE_CALL_DECLINE CallController.EndCall call_id={0}", callId)); var result = BackEnd.Globals.Instance.CallController.EndCall(); Log(string.Format("PHONE_CALL_DECLINE CallController.EndCall call_id={0} result={1}", callId, result)); } } } } else if (string.Equals(rootObject.data.loc_key, "GEO_LIVE_PENDING")) { ProcessLiveLocations(); } else { //PushUtils2.UpdateToastAndTiles(rootObject); } } } Complete(); return; } else { VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask; if (keepAliveTask != null) { this.isIncomingCallAgent = false; // Refresh tokens, get new certs from server, etc. BackEnd.Globals.Instance.DoPeriodicKeepAlive(); this.Complete(); } else { throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType())); } } }