public void SaveWebRTCTrace()
        {
            if (!WebRTC.IsTracing())
            {
                return;
            }

            Task.Run(async() =>
            {
                WebRTC.StopTracing(); //stop tracing so that trace file can be properly saved.
                ToastNotificationService.ShowToastNotification("Saving Webrtc trace");
                var webrtcTraceInternalFile = ApplicationData.Current.LocalFolder.Path + "\\" + "_webrtc_trace.txt";

                WebRTC.SaveTrace(webrtcTraceInternalFile);

                await SaveToUserPickedFolder(webrtcTraceInternalFile);

                WebRTC.StartTracing();

                ToastNotificationService.ShowToastNotification("Saving Webrtc trace finished!");
            });
        }
Exemple #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            using (new BackgroundTaskDeferralWrapper(taskInstance.GetDeferral()))
            {
                try
                {
                    var details = (SocketActivityTriggerDetails)taskInstance.TriggerDetails;
                    switch (details.Reason)
                    {
                    case SocketActivityTriggerReason.SocketActivity:
                        string request = null;
                        using (var socketOperation = Hub.Instance.SignalingSocketChannel.SocketOperation)
                        {
                            if (socketOperation.Socket != null)
                            {
                                var socket = socketOperation.Socket;

                                const uint length  = 65536;
                                var        readBuf = new Buffer(length);

                                var readOp = socket.InputStream.ReadAsync(readBuf, length,
                                                                          InputStreamOptions.Partial);
                                // This delay is to limit how long we wait for reading.
                                // StreamSocket has no ability to peek to see if there's any
                                // data waiting to be read.  So we have to limit it this way.
                                for (var i = 0; i < 100 && readOp.Status == AsyncStatus.Started; ++i)
                                {
                                    await Task.Delay(10);
                                }
                                await socket.CancelIOAsync();

                                try
                                {
                                    var localBuffer = await readOp;
                                    var dataReader  = DataReader.FromBuffer(localBuffer);
                                    request = dataReader.ReadString(dataReader.UnconsumedBufferLength);
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine($"ReadAsync exception: {ex}");
                                }
                            }
                        }
                        if (request != null)
                        {
                            await Hub.Instance.SignalingClient.HandleRequest(request);
                        }
                        break;

                    case SocketActivityTriggerReason.KeepAliveTimerExpired:
                        await Hub.Instance.SignalingClient.ClientHeartBeatAsync();

                        break;

                    case SocketActivityTriggerReason.SocketClosed:
                        await Hub.Instance.SignalingClient.ServerConnectionErrorAsync();

                        //ToastNotificationService.ShowToastNotification("Disconnected.");
                        break;
                    }
                }
                catch (Exception exception)
                {
                    await Hub.Instance.SignalingClient.ServerConnectionErrorAsync();

                    ToastNotificationService.ShowToastNotification(string.Format("Error in SignalingTask: {0}",
                                                                                 exception.Message));
                }
            }
        }