public Task<AppleTv> FindAppleTv() { var tcs = new TaskCompletionSource<AppleTv>(); var domainBrowser = new Mono.Zeroconf.ServiceBrowser(); domainBrowser.ServiceAdded += (o, args) => { args.Service.Resolved += (orsv, arsv) => { if(arsv == null) tcs.SetException(new ArgumentNullException("Service not found")); var s = (IResolvableService)args.Service; var tv = new AppleTv { Model = s.TxtRecord["model"].ValueString, Version = s.TxtRecord["srcvers"].ValueString, Features = int.Parse(s.TxtRecord["features"].ValueString.Substring(2), System.Globalization.NumberStyles.HexNumber), DeviceID = s.TxtRecord["deviceid"].ValueString, IPAddress = s.HostEntry.AddressList[0].ToString () }; tcs.SetResult(tv); }; args.Service.Resolve (); }; domainBrowser.Browse("_airplay._tcp", "local"); return tcs.Task; }
async public Task<AppleTv> TV() { if (tv == null) tv = await FindAppleTv(); return tv; }