private void StartCloudThread(object threadInfos) { CloudThreadInfos cloudThreadInfos = (CloudThreadInfos)threadInfos; Console.WriteLine("Thread Cloud sender started"); while (true) { Cloud cloud = cloudThreadInfos.CloudToWebRTC.Take(); //On envoi les points par paquets de nbPointsParPaquet int nbPointsParPaquet = 200; int cpt1 = 0; while (cpt1 + nbPointsParPaquet <= cloud.Points.Count) { var pointsToSend = cloud.Points.GetRange(cpt1, nbPointsParPaquet); string formattedMsg = FormateMessage(cloud.Timestamp, pointsToSend); // Handle peer disconnected while sending data try { foreach (KeyValuePair <string, SpitfireRtc> peer in cloudThreadInfos.RTCPeerConnection) { peer.Value.DataChannelSendText("cloudChannel", formattedMsg); } } catch (Exception ex) { Console.WriteLine("Error, sending data to a disconnected peer : " + ex.Message); } cpt1 += nbPointsParPaquet; } //On envoi le reste (s'il y en a) if (cpt1 < cloud.Points.Count) { var pointsToSend = cloud.Points.GetRange(cpt1, cloud.Points.Count - cpt1); string formattedMsg = FormateMessage(cloud.Timestamp, pointsToSend); // Handle peer disconnected while sending data try { foreach (KeyValuePair <string, SpitfireRtc> peer in cloudThreadInfos.RTCPeerConnection) { peer.Value.DataChannelSendText("cloudChannel", formattedMsg); } } catch (Exception ex) { Console.WriteLine("Error, sending data to a disconnected peer : " + ex.Message); } } //Console.WriteLine($"Frame send with {cloud.Points.Count} points. (Timestamp = {cloud.Timestamp})"); } }
public CloudThreadWebRTC(BlockingCollection <Cloud> cloudToWebRTC, Dictionary <string, SpitfireRtc> rtcPeerConnection) { _cloudThreadInfos = new CloudThreadInfos(cloudToWebRTC, rtcPeerConnection); _cloudThread = new Thread(new ParameterizedThreadStart(StartCloudThread)); }