void nsBrowser_DidFindService(NetServiceBrowser browser, NetService service, bool moreComing) { Debug.WriteLine(String.Format("{0}: nsBrowser_DidFindService: {1}", System.Threading.Thread.CurrentThread.ManagedThreadId, service.Name)); service.DidUpdateTXT += new NetService.ServiceTXTUpdated(ns_DidUpdateTXT); service.DidResolveService += new NetService.ServiceResolved(ns_DidResolveService); service.StartMonitoring(); ListViewItem item = new ListViewItem(service.Name); item.Tag = service; if (moreComing) { waitingAdd.Add(item); } else { servicesList.BeginUpdate(); while (waitingAdd.Count > 0) { servicesList.Items.Add((ListViewItem)waitingAdd[0]); waitingAdd.RemoveAt(0); } servicesList.Items.Add(item); servicesList.EndUpdate(); } }
/// <summary> /// /// </summary> /// <param name="service"></param> public void ns_DidResolveService(NetService service) { service.DidUpdateTXT += new NetService.ServiceTXTUpdated(ns_DidUpdateTXT); service.StartMonitoring(); Trace.WriteLine("DEBUG: Resolved - " + service.Name); // Use the GUID as my name unless TXT has a better name ListViewItem item = new ListViewItem(getName(service)); item.Tag = service; #if PLAYER_TASKBAR MenuItem newElem = new System.Windows.Forms.MenuItem(); newElem.Text = getName(service); newElem.Click += new System.EventHandler(selectStreamer); newElem.Select += new System.EventHandler(selectStreamer); newElem.Tag = service; // #if PLAYER_USE_STREAMERICON // #endif streamersItem.MenuItems.Add(newElem); #else browserList.BeginUpdate(); browserList.Items.Add(item); browserList.EndUpdate(); #endif }
/// <summary> /// Bonjour callback /// </summary> /// <param name="service"></param> private void didUpdateTXT(NetService service) { ArrayList list = getList(service.Type); if (list == null) return; lock (list.SyncRoot) { foreach (JSONSrcSink player in list) { if (player.id.Equals(service.Name)) { processTXTrecord(service, player); // Kludge. Sometimes, we miss the TXT update record from Bonjour. // So, we stop and restart a new monitoring session. That forces the system to continously get updates/stop/new update/stop, yuck service.StopMonitoring(); service.DidUpdateTXT += new NetService.ServiceTXTUpdated(didUpdateTXT); service.StartMonitoring(); return; } } } }
/// <summary> /// Bonjour callback. Remember resolved services and initiate monitoring TXT record updates /// </summary> /// <param name="service"></param> private void didResolvePlayers(NetService service) { JSONSrcSink newPlayer = new JSONSrcSink(); newPlayer.id = service.Name; if (service.TXTRecordData != null) processTXTrecord(service, newPlayer); // Remove any previous remembered entries ArrayList list = getList(service.Type); lock (list.SyncRoot) { ArrayList toRemove = new ArrayList(); foreach (JSONSrcSink item in list) { if (item.id.Equals(service.Name)) toRemove.Add(item); } if (toRemove.Count > 0) { foreach (JSONSrcSink item in toRemove) list.Remove(item); toRemove.Clear(); } list.Add(newPlayer); } // Store the service in either sink or sources. ArrayList services = null; if (service.Type.StartsWith(Shared.DisplayCastGlobals.PLAYER) || service.Type.StartsWith(Shared.DisplayCastGlobals.ARCHIVER)) services = sinkServices; if (service.Type.StartsWith(Shared.DisplayCastGlobals.STREAMER)) services = sourceServices; Debug.Assert(services != null); // First remove any old entries lock (services.SyncRoot) { ArrayList toRemove = new ArrayList(); foreach (NetService item in services) { if (item.Name.Equals(service.Name)) toRemove.Add(item); } if (toRemove.Count > 0) { foreach (NetService item in toRemove) services.Remove(item); toRemove.Clear(); } // Add the current service services.Add(service); } service.DidUpdateTXT += new NetService.ServiceTXTUpdated(didUpdateTXT); service.StartMonitoring(); }
/// <summary> /// /// </summary> /// <param name="service"></param> public void nsBrowser_DidResolveService(NetService service) { // Start monitoring to see whether the name changes service.DidUpdateTXT += new NetService.ServiceTXTUpdated(nsBrowser_DidUpdateTXT); service.StartMonitoring(); MenuItem newElem = new System.Windows.Forms.MenuItem(); newElem.Text = getName(service); newElem.Click += new System.EventHandler(selectPlayer); newElem.Select += new System.EventHandler(selectPlayer); newElem.Tag = service; if (service.Type.StartsWith(Shared.DisplayCastGlobals.PLAYER)) { newElem.Index = numPlayers++; playersItem.MenuItems.Add(newElem); } else if (service.Type.StartsWith(Shared.DisplayCastGlobals.ARCHIVER)) { newElem.Index = numArchivers++; archiversItem.MenuItems.Add(newElem); } }