public async void Show() { Show(_call, _controller); if (_callDialog != null) { _callDialog.IsOpen = true; } else if (_callLifetime != null) { _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller), 0); } }
private void Hide() { if (_callPage != null) { _callPage.BeginOnUIThread(() => { if (_callDialog != null) { _callDialog.IsOpen = false; _callDialog = null; } else if (_callLifetime != null) { _callLifetime.StopViewInUse(); _callLifetime.WindowWrapper.Window.Close(); _callLifetime = null; } _callPage.Dispose(); _callPage = null; }); } }
private async void Show(Call call, VoIPControllerWrapper controller) { if (_callPage == null) { if (ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "IsViewModeSupported") && ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay)) { _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller), 0); _callLifetime.Released += (s, args) => { _callPage.Dispose(); _callPage = null; }; } else { _callPage = new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller); _callDialog = new ContentDialogBase(); _callDialog.HorizontalAlignment = HorizontalAlignment.Stretch; _callDialog.VerticalAlignment = VerticalAlignment.Stretch; _callDialog.Content = _callPage; _callDialog.IsOpen = true; } } _callPage.BeginOnUIThread(() => { if (controller != null) { _callPage.Connect(controller); } _callPage.Update(call); }); }
private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { var deferral = args.GetDeferral(); var message = args.Request.Message; try { if (message.ContainsKey("caption") && message.ContainsKey("request")) { var caption = message["caption"] as string; var buffer = message["request"] as string; var req = TLSerializationService.Current.Deserialize(buffer); if (caption.Equals("voip.getUser") && req is TLPeerUser userPeer) { var user = InMemoryCacheService.Current.GetUser(userPeer.UserId); if (user != null) { await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(user) } }); } else { await args.Request.SendResponseAsync(new ValueSet { { "error", TLSerializationService.Current.Serialize(new TLRPCError { ErrorMessage = "USER_NOT_FOUND", ErrorCode = 404 }) } }); } } else if (caption.Equals("voip.getConfig")) { var config = InMemoryCacheService.Current.GetConfig(); await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(config) } }); } else if (caption.Equals("voip.callInfo") && req is byte[] data) { using (var from = new TLBinaryReader(data)) { var tupleBase = new TLTuple <int, TLPhoneCallBase, TLUserBase, string>(from); var tuple = new TLTuple <TLPhoneCallState, TLPhoneCallBase, TLUserBase, string>((TLPhoneCallState)tupleBase.Item1, tupleBase.Item2, tupleBase.Item3, tupleBase.Item4); if (tuple.Item2 is TLPhoneCallDiscarded) { if (_phoneView != null) { var newView = _phoneView; _phoneViewExists = false; _phoneView = null; await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { newView.SetCall(tuple); newView.Dispose(); Window.Current.Close(); }); } return; } if (_phoneViewExists == false) { VoIPCallTask.Log("Creating VoIP UI", "Creating VoIP UI"); _phoneViewExists = true; PhoneCallPage newPlayer = null; CoreApplicationView newView = CoreApplication.CreateNewView(); var newViewId = 0; await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { newPlayer = new PhoneCallPage(); Window.Current.Content = newPlayer; Window.Current.Activate(); newViewId = ApplicationView.GetForCurrentView().Id; newPlayer.SetCall(tuple); _phoneView = newPlayer; }); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { if (ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "IsViewModeSupported") && ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay)) { var preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay); preferences.CustomSize = new Size(340, 200); var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences); } else { //await ApplicationViewSwitcher.SwitchAsync(newViewId); await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId); } }); } else if (_phoneView != null) { VoIPCallTask.Log("VoIP UI already exists", "VoIP UI already exists"); await _phoneView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _phoneView.SetCall(tuple); }); } } } else if (caption.Equals("voip.signalBars") && req is byte[] data2) { using (var from = new TLBinaryReader(data2)) { var tuple = new TLTuple <int>(from); if (_phoneView != null) { await _phoneView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _phoneView.SetSignalBars(tuple.Item1); }); } } } else if (caption.Equals("voip.setCallRating") && req is TLInputPhoneCall peer) { Execute.BeginOnUIThread(async() => { var dialog = new PhoneCallRatingView(); var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary) { await MTProtoService.Current.SetCallRatingAsync(peer, dialog.Rating, dialog.Rating >= 0 && dialog.Rating <= 3 ? dialog.Comment : null); } }); } else { var response = await MTProtoService.Current.SendRequestAsync <object>(caption, req as TLObject); if (response.IsSucceeded) { await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(response.Result) } }); } else { await args.Request.SendResponseAsync(new ValueSet { { "error", TLSerializationService.Current.Serialize(response.Error) } }); } } } } finally { deferral.Complete(); } }