Beispiel #1
0
 private void startReceiveLoop()
 {
     Console.WriteLine("Now receiving");
     while (isConnected)
     {
         try
         {
             Console.WriteLine("Waiting for next packet... from " + groupEP.Address.ToString() + ":" + groupEP.Port);
             byte[]        bytes = Socket.Receive(ref groupEP);
             StringBuilder sb    = new StringBuilder();
             sb.Append(Encoding.ASCII.GetString(bytes, 0, bytes.Length));
             Console.WriteLine(sb.ToString());
             try
             {
                 ResponsePayload rp = JsonConvert.DeserializeObject <ResponsePayload>(sb.ToString());
                 if (queueList > 0)
                 {
                     //while (responseWaiter != null)
                     //{
                     //
                     //}
                     responseWaiter = rp;
                 }
             }
             catch
             {
                 Console.WriteLine("Received data is not a response payload!");
             }
             try
             {
                 NotifyPayload r = JsonConvert.DeserializeObject <NotifyPayload>(sb.ToString());
                 if (r.status == "notify")
                 {
                     var ee      = new ConnectorReceiveEventArgs(r);
                     var handler = ReceivedData;
                     if (handler != null)
                     {
                         handler(null, ee);
                     }
                 }
             }
             catch (Exception e)
             {
                 Console.WriteLine("Received data is not a notify payload! " + e.StackTrace);
             }
         }
         catch (SocketException ex)
         {
             isConnected = false;
             Console.WriteLine(ex.StackTrace);
         }
     }
 }
Beispiel #2
0
 private void CancelRequested(object sender, ConnectorReceiveEventArgs e)
 {
     Console.Write("xxx");
     if (e.payload.type == "cancel" || e.payload.type == "revoke")
     {
         isTalking = false;
         var handler = onAudioStop;
         if (handler != null)
         {
             handler(this, null);
         }
     }
 }
Beispiel #3
0
 private void waitForPermit(object sender, ConnectorReceiveEventArgs e)
 {
     if (e.payload.identity == packetIdentity && e.payload.status == "notify")
     {
         if (e.payload.type == "permit")
         {
             connector.ReceivedData -= waitForPermit;
             audioCaller             = null;
             int retryAttempts = 0;
             while (audioCaller == null)
             {
                 try
                 {
                     audioCaller = new UdpClient();
                 }
                 catch
                 {
                     if (retryAttempts > 10)
                     {
                         //Cancel queue
                         return;
                     }
                     retryAttempts++;
                     Thread.Sleep(1010);
                 }
             }
             IPAddress  ip      = IPAddress.Parse(client.endpoint);
             IPEndPoint groupEP = new IPEndPoint(ip, AUDIOPORT);
             audioCaller.Connect(groupEP);
             this.AudioSessionId = Convert.ToInt32(e.payload.payload["sessionid"]);
             this.startTalking(audioCaller);
             var handler = onAudioAccept;
             if (handler != null)
             {
                 onAudioAccept(this, null);
             }
             connector.ReceivedData += CancelRequested;
         }
         else if (e.payload.type == "revoke")
         {
             this.stopTalking();
         }
     }
 }
Beispiel #4
0
 private void waitForPermit(object sender, ConnectorReceiveEventArgs e)
 {
     if (e.payload.identity == packetIdentity && e.payload.status == "notify")
     {
         if (e.payload.type == "permit")
         {
             connector.ReceivedData -= waitForPermit;
             audioCaller = null;
             int retryAttempts = 0;
             while (audioCaller == null)
             {
                 try
                 {
                     audioCaller = new UdpClient();
                 }
                 catch
                 {
                     if (retryAttempts > 10)
                     {
                         //Cancel queue
                         return;
                     }
                     retryAttempts++;
                     Thread.Sleep(1010);
                 }
             }
             IPAddress ip = IPAddress.Parse(client.endpoint);
             IPEndPoint groupEP = new IPEndPoint(ip, AUDIOPORT);
             audioCaller.Connect(groupEP);
             this.AudioSessionId = Convert.ToInt32(e.payload.payload["sessionid"]);
             this.startTalking(audioCaller);
             var handler = onAudioAccept;
             if (handler != null) onAudioAccept(this, null);
             connector.ReceivedData += CancelRequested;
         } else if (e.payload.type == "revoke") {
             this.stopTalking ();
         }
     }
 }
Beispiel #5
0
 private void CancelRequested(object sender, ConnectorReceiveEventArgs e)
 {
     Console.Write ("xxx");
     if (e.payload.type == "cancel" || e.payload.type == "revoke")
     {
         isTalking = false;
         var handler = onAudioStop;
         if (handler != null)
             handler (this, null);
     }
 }
Beispiel #6
0
 private void startReceiveLoop()
 {
     Console.WriteLine ("Now receiving");
     while (isConnected)
     {
         try
         {
             byte[] bytes = Socket.Receive(ref groupEP);
             StringBuilder sb = new StringBuilder();
             sb.Append(Encoding.ASCII.GetString(bytes, 0, bytes.Length));
             Console.WriteLine(sb.ToString());
             try
             {
                 ResponsePayload rp = JsonConvert.DeserializeObject<ResponsePayload>(sb.ToString());
                 if (queueList > 0)
                 {
                     //while (responseWaiter != null)
                     //{
                     //
                     //}
                     responseWaiter = rp;
                 }
             }
             catch
             {
                 Console.WriteLine("Received data is not a response payload!");
             }
             try
             {
                 NotifyPayload r = JsonConvert.DeserializeObject<NotifyPayload>(sb.ToString());
                 if (r.status == "notify")
                 {
                     var ee = new ConnectorReceiveEventArgs(r);
                     var handler = ReceivedData;
                     if (handler != null) handler(null, ee);
                 }
             }
             catch (Exception e)
             {
                 Console.WriteLine("Received data is not a notify payload! " + e.StackTrace);
             }
         }
         catch (SocketException)
         {
             isConnected = false;
         }
     }
 }