Exemplo n.º 1
0
 internal async void AddClient(TcpClient tcpClient)
 {
     try
     {
         StreamReader reader = new StreamReader(tcpClient.GetStream());
         string inputLine = await reader.ReadLineAsync();
         if (inputLine.StartsWith("GET", StringComparison.OrdinalIgnoreCase)) // http client
         {
             lock (httpClients)
             {
                 httpClients.Add(tcpClient);
             }
             StreamManager.StartHttpStreaming(tcpClient, reader, inputLine);
         }
         else
         {
             IMPClient impClient = new IMPClient(tcpClient, reader);
             impClient.RemoteEndPoint = tcpClient.Client.RemoteEndPoint as IPEndPoint;
             lock (impClients)
             {
                 impClients[impClient.RemoteEndPoint.ToString()] = impClient;
             }
             impClient.DecodeMessage(inputLine);
             impClient.Start();
             CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, impClient));
         }
     }
     catch (Exception e) { System.Diagnostics.Debug.WriteLine(String.Format("{0} in Clients.AddClient while adding client: {1}", e.Message, tcpClient)); }
 }
Exemplo n.º 2
0
 internal void RemoveIMPClient(IMPClient impClient)
 {
     lock (impClients)
     {
         impClients.Remove(impClient.RemoteEndPoint.ToString());
     }
     CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, impClient));
 }
Exemplo n.º 3
0
 private string SerializeClient(IMPClient client)
 {
     lock (state)
     {
         return @"{""state"":{""partialClientList"":[" + JsonConvert.SerializeObject(client) + "]}}";
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// This client (client A) requests client B to start streaming
 /// client A and B could be the same
 /// This leads to a "RequestStream" call on the client B
 /// </summary>
 /// <param name="jToken"></param>
 private void onStreamRequest(IMPClient client, JToken jToken)
 {
     try
     {
         PlaylistItem playlistItem = Playlist.Instance.GetPlaylistItem(jToken.ToString());
         client.RequestStream(playlistItem);
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.Message + " in onStreamRequest with arg: " + jToken);
     }
 }
Exemplo n.º 5
0
        private static void onSetVolume(IMPClient client, JToken jToken)
        {
            try
            {
                int volumeLevel = Convert.ToInt32(jToken);

                // range check volume
                if (volumeLevel < 0) volumeLevel = 0;
                else if (volumeLevel > 100) volumeLevel = 100;

                client.SetVolume(volumeLevel);
            }
            catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message + " in onSetVolume with arg: " + jToken); }
        }
Exemplo n.º 6
0
 private void onStopPlayback(IMPClient client, JToken jToken)
 {
     try
     {
         client.StopPlayback();
     }
     catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message + " in onStopPlayback with arg: " + jToken); }
 }