public void SetCallActive(string userId, bool videoEnabled) { if (_voipCall != null) { _voipCall.NotifyCallActive(); } else { StartOutgoingCall(userId, videoEnabled); } }
public static async Task <bool> GetCallDurationAsync() { VoipPhoneCall call = VoipCall; AppServiceRequest request = AppRequest; AppServiceDeferral deferal = AppRequestDeferal; TimeSpan timeSpan = new TimeSpan(); if (call != null) { call.NotifyCallActive(); timeSpan = DateTimeOffset.Now.Subtract(call.StartTime); } if (request != null) { ValueSet response = new ValueSet(); response[BackgroundOperation.Result] = timeSpan.ToString(); await request.SendResponseAsync(response); } if (deferal != null) { deferal.Complete(); } return(true); }
private void NewOutgoingCall(string context, string contactName, string serviceName) { bool status = false; try { VoipCallCoordinator vCC = VoipCallCoordinator.GetDefault(); VoipPhoneCall call = vCC.RequestNewOutgoingCall(context, contactName, serviceName, VoipPhoneCallMedia.Audio); if (call != null) { call.EndRequested += Call_EndRequested; call.HoldRequested += Call_HoldRequested; call.RejectRequested += Call_RejectRequested; call.ResumeRequested += Call_ResumeRequested; call.NotifyCallActive(); Current.VoipCall = call; Current.StartAudio(); status = true; } } catch (Exception e) { Debug.WriteLine(e.ToString()); } ValueSet response = new ValueSet(); response[BackgroundOperation.Result] = status ? (int)OperationResult.Succeeded : (int)OperationResult.Failed; Current.SendResponse(response); }
public static async void ConnectToVoiceChannel(VoiceServerUpdate data) { string name; if (data.GuildId == null) { data.GuildId = data.ChannelId; name = $"DM - {LocalState.DMs[data.ChannelId].Name}"; } else { name = $"{LocalState.Guilds[data.GuildId].Raw.Name} - {LocalState.Guilds[data.GuildId].channels[LocalState.VoiceState.ChannelId].raw.Name}"; } App.UpdateLocalDeaf(false); App.UpdateVoiceStateHandler += App_UpdateVoiceStateHandler; //App.UpdateLocalMute(true); //LocalState.Muted); VoiceConnection = new VoiceConnection(data, LocalState.VoiceState); VoiceConnection.VoiceDataRecieved += VoiceConnection_VoiceDataRecieved; await VoiceConnection.ConnectAsync(); ConnectoToVoiceHandler?.Invoke(typeof(App), new ConnectToVoiceArgs() { ChannelId = LocalState.VoiceState.ChannelId, GuildId = data.GuildId }); AudioManager.InputRecieved += AudioManager_InputRecieved; if (Storage.Settings.BackgroundVoice) { VoipCallCoordinator vcc = VoipCallCoordinator.GetDefault(); voipCall = vcc.RequestNewOutgoingCall("", name, "Quarrel", VoipPhoneCallMedia.Audio); voipCall.NotifyCallActive(); } }
internal void NewOutgoingCall(string dstURI) { bool status = false; try { VoipCallCoordinator vCC = VoipCallCoordinator.GetDefault(); VoipPhoneCall call = vCC.RequestNewOutgoingCall("Pjsua Test Call ", dstURI, "", VoipPhoneCallMedia.Audio); if (call != null) { call.EndRequested += Call_EndRequested; call.RejectRequested += Call_RejectRequested; call.NotifyCallActive(); Current.VoipCall = call; MyAppRT.Instance.makeCall(dstURI); status = true; } } catch (Exception e) { Debug.WriteLine(e.ToString()); } ValueSet response = new ValueSet(); response[BackgroundOperation.Result] = status ? (int)OperationResult.Succeeded : (int)OperationResult.Failed; Current.SendResponse(response); }
async void callObj_AnswerRequested(VoipPhoneCall sender, CallAnswerEventArgs args) { sender.NotifyCallActive(); await Task.Delay(3000); sender.NotifyCallEnded(); }
private async void ConnectToVoiceChannel(VoiceServerUpdate data, VoiceState state) { voipCall?.NotifyCallEnded(); VoipCallCoordinator vcc = VoipCallCoordinator.GetDefault(); var status = await vcc.ReserveCallResourcesAsync("WebRTCBackgroundTask.VoipBackgroundTask"); // TODO: More info for Mobile voipCall = vcc.RequestNewOutgoingCall(string.Empty, string.Empty, "Quarrel", VoipPhoneCallMedia.Audio); voipCall.NotifyCallActive(); voiceConnection = new VoiceConnection(data, state, webrtcManager); voiceConnection.Speak += Speak; await voiceConnection.ConnectAsync(); }
public void StartOutgoingCall(string userId, bool videoEnabled) { var capabilities = VoipPhoneCallMedia.Audio; if (videoEnabled) { capabilities |= VoipPhoneCallMedia.Video; } var voipCallCoordinator = VoipCallCoordinator.GetDefault(); _voipCall = voipCallCoordinator.RequestNewOutgoingCall( userId, userId, "ChatterBox", capabilities); if (_voipCall == null) { return; } SubscribeToVoipCallEvents(); // Immediately set the call as active. _voipCall.NotifyCallActive(); }
private static void Call_AnswerRequested(VoipPhoneCall sender, CallAnswerEventArgs args) { sender.NotifyCallActive(); }
private static void Call_ResumeRequested(VoipPhoneCall sender, CallStateChangeEventArgs args) { sender.NotifyCallActive(); }
private void Call_ResumeRequested(VoipPhoneCall sender, CallStateChangeEventArgs args) { sender.NotifyCallActive(); Current.VoipCall = sender; Current.StartAudio(); }
private void Call_AnswerRequested(VoipPhoneCall sender, CallAnswerEventArgs args) { sender.NotifyCallActive(); Current.VoipCall = sender; Current.StartAudio(); }
private async void ProcessUpdates() { while (_queue.Count > 0) { var update = _queue.Dequeue(); _phoneCall = update.PhoneCall; if (update.PhoneCall is TLPhoneCallRequested requested) { _peer = requested.ToInputPhoneCall(); var req = new TLPhoneReceivedCall { Peer = new TLInputPhoneCall { Id = requested.Id, AccessHash = requested.AccessHash } }; const string caption = "phone.receivedCall"; var response = await SendRequestAsync <bool>(caption, req); var responseUser = await SendRequestAsync <TLUser>("voip.getUser", new TLPeerUser { UserId = requested.AdminId }); if (responseUser.Result == null) { return; } var user = responseUser.Result; var photo = new Uri("ms-appx:///Assets/Logos/Square150x150Logo/Square150x150Logo.png"); if (user.Photo is TLUserProfilePhoto profile && profile.PhotoSmall is TLFileLocation location) { var fileName = string.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); var temp = FileUtils.GetTempFileUri(fileName); photo = temp; } var coordinator = VoipCallCoordinator.GetDefault(); var call = coordinator.RequestNewIncomingCall("Unigram", user.FullName, user.DisplayName, photo, "Unigram", null, "Unigram", null, VoipPhoneCallMedia.Audio, TimeSpan.FromSeconds(128)); _user = user; _outgoing = false; _systemCall = call; _systemCall.AnswerRequested += OnAnswerRequested; _systemCall.RejectRequested += OnRejectRequested; } else if (update.PhoneCall is TLPhoneCallDiscarded discarded) { if (false) { discarded.IsNeedRating = true; } if (discarded.IsNeedRating) { await _connection.SendMessageAsync(new ValueSet { { "caption", "voip.setCallRating" }, { "request", TLSerializationService.Current.Serialize(_peer) } }); } if (discarded.IsNeedDebug) { var req = new TLPhoneSaveCallDebug(); req.Debug = new TLDataJSON { Data = _controller.GetDebugLog() }; req.Peer = _peer; await SendRequestAsync <bool>("phone.saveCallDebug", req); } await UpdateStateAsync(TLPhoneCallState.Ended); if (_controller != null) { _controller.Dispose(); _controller = null; } if (_connection != null) { _connection.RequestReceived -= OnRequestReceived; _connection = null; } if (_systemCall != null) { try { _systemCall.AnswerRequested -= OnAnswerRequested; _systemCall.RejectRequested -= OnRejectRequested; _systemCall.NotifyCallEnded(); _systemCall = null; } catch { if (_deferral != null) { _deferral.Complete(); } } Debug.WriteLine("VoIP call disposed"); } else if (_deferral != null) { _deferral.Complete(); } } else if (update.PhoneCall is TLPhoneCallAccepted accepted) { await UpdateStateAsync(TLPhoneCallState.ExchangingKeys); _phoneCall = accepted; auth_key = computeAuthKey(accepted); byte[] authKeyHash = Utils.ComputeSHA1(auth_key); byte[] authKeyId = new byte[8]; Buffer.BlockCopy(authKeyHash, authKeyHash.Length - 8, authKeyId, 0, 8); long fingerprint = Utils.BytesToLong(authKeyId); //this.authKey = authKey; //keyFingerprint = fingerprint; var request = new TLPhoneConfirmCall { GA = g_a, KeyFingerprint = fingerprint, Peer = new TLInputPhoneCall { Id = accepted.Id, AccessHash = accepted.AccessHash }, Protocol = new TLPhoneCallProtocol { IsUdpP2p = true, IsUdpReflector = true, MinLayer = Telegram.Api.Constants.CallsMinLayer, MaxLayer = Telegram.Api.Constants.CallsMaxLayer, } }; var response = await SendRequestAsync <TLPhonePhoneCall>("phone.confirmCall", request); if (response.IsSucceeded) { _systemCall.NotifyCallActive(); Handle(new TLUpdatePhoneCall { PhoneCall = response.Result.PhoneCall }); } } else if (update.PhoneCall is TLPhoneCall call) { _phoneCall = call; if (auth_key == null) { auth_key = computeAuthKey(call); g_a = call.GAOrB; } var buffer = TLUtils.Combine(auth_key, g_a); var sha256 = Utils.ComputeSHA256(buffer); _emojis = EncryptionKeyEmojifier.EmojifyForCall(sha256); var response = await SendRequestAsync <TLDataJSON>("phone.getCallConfig", new TLPhoneGetCallConfig()); if (response.IsSucceeded) { var responseConfig = await SendRequestAsync <TLConfig>("voip.getConfig", new TLPeerUser()); var config = responseConfig.Result; VoIPControllerWrapper.UpdateServerConfig(response.Result.Data); var logFile = ApplicationData.Current.LocalFolder.Path + "\\tgvoip.logFile.txt"; var statsDumpFile = ApplicationData.Current.LocalFolder.Path + "\\tgvoip.statsDump.txt"; if (_controller != null) { _controller.Dispose(); _controller = null; } _controller = new VoIPControllerWrapper(); _controller.SetConfig(config.CallPacketTimeoutMs / 1000.0, config.CallConnectTimeoutMs / 1000.0, DataSavingMode.Never, true, true, true, logFile, statsDumpFile); SettingsHelper.CleanUp(); if (SettingsHelper.IsCallsProxyEnabled) { var server = SettingsHelper.ProxyServer ?? string.Empty; var port = SettingsHelper.ProxyPort; var user = SettingsHelper.ProxyUsername ?? string.Empty; var pass = SettingsHelper.ProxyPassword ?? string.Empty; _controller.SetProxy(ProxyProtocol.SOCKS5, server, (ushort)port, user, pass); } else { _controller.SetProxy(ProxyProtocol.None, string.Empty, 0, string.Empty, string.Empty); } _controller.SetStateCallback(this); _controller.SetEncryptionKey(auth_key, _outgoing); var connection = call.Connection; var endpoints = new Endpoint[call.AlternativeConnections.Count + 1]; endpoints[0] = connection.ToEndpoint(); for (int i = 0; i < call.AlternativeConnections.Count; i++) { connection = call.AlternativeConnections[i]; endpoints[i + 1] = connection.ToEndpoint(); } _controller.SetPublicEndpoints(endpoints, call.Protocol.IsUdpP2p && ApplicationSettings.Current.IsPeerToPeer); _controller.Start(); _controller.Connect(); } //await Task.Delay(50000); //var req = new TLPhoneDiscardCall { Peer = new TLInputPhoneCall { Id = call.Id, AccessHash = call.AccessHash }, Reason = new TLPhoneCallDiscardReasonHangup() }; //const string caption = "phone.discardCall"; //await SendRequestAsync<TLUpdatesBase>(caption, req); //_systemCall.NotifyCallEnded(); } else if (update.PhoneCall is TLPhoneCallWaiting waiting) { _peer = waiting.ToInputPhoneCall(); if (_state == TLPhoneCallState.Waiting && waiting.HasReceiveDate && waiting.ReceiveDate != 0) { await UpdateStateAsync(TLPhoneCallState.Ringing); } } } }