soundbeam – Diff between revs 1 and 2
?pathlinks?
Rev 1 | Rev 2 | |||
---|---|---|---|---|
Line 57... | Line 57... | |||
57 | private static readonly RegisterService SoundBeamRegisterService = new RegisterService(); |
57 | private static readonly RegisterService SoundBeamRegisterService = new RegisterService(); |
|
58 | private static readonly ServiceBrowser SoundBeamServiceBrowser = new ServiceBrowser(); |
58 | private static readonly ServiceBrowser SoundBeamServiceBrowser = new ServiceBrowser(); |
|
Line 59... | Line 59... | |||
59 | |
59 | |
|
Line -... | Line 60... | |||
- | 60 | private static readonly Dictionary<TcpClient, WasapiOut> WasapiOut = new Dictionary<TcpClient, WasapiOut>(); |
||
- | 61 | |
||
- | 62 | private static readonly BindingList<DiscoveredServer> DiscoveredServersBindingList = new BindingList<DiscoveredServer>(); |
||
- | 63 | |
||
- | 64 | private static readonly BindingSource DiscoveredServersBindingSource = |
||
60 | private static readonly Dictionary<TcpClient, WasapiOut> WasapiOut = new Dictionary<TcpClient, WasapiOut>(); |
65 | new BindingSource(DiscoveredServersBindingList, null); |
|
61 | |
66 | |
|
62 | public Form1() |
67 | public Form1() |
|
Line -... | Line 68... | |||
- | 68 | { |
||
- | 69 | InitializeComponent(); |
||
- | 70 | |
||
- | 71 | // Set the tool strip combo box binding. |
||
- | 72 | sendToolStripComboBox.ComboBox.DisplayMember = "Hostname"; |
||
- | 73 | sendToolStripComboBox.ComboBox.ValueMember = "Hostname"; |
||
63 | { |
74 | sendToolStripComboBox.ComboBox.DataSource = DiscoveredServersBindingSource; |
|
64 | InitializeComponent(); |
75 | sendToolStripComboBox.ComboBox.BindingContext = this.BindingContext; |
|
65 | |
76 | |
|
66 | // Register local service. |
77 | // Register local service. |
|
- | 78 | SoundBeamRegisterService.Name = "SoundBeam Audio Sink"; |
||
67 | SoundBeamRegisterService.Name = "SoundBeam Audio Sink"; |
79 | SoundBeamRegisterService.RegType = "_soundbeam._tcp"; |
|
Line 68... | Line 80... | |||
68 | SoundBeamRegisterService.RegType = "_soundbeam._tcp"; |
80 | SoundBeamRegisterService.Port = 9000; |
|
69 | SoundBeamRegisterService.Port = 9000; |
81 | SoundBeamRegisterService.UPort = 9000; |
|
Line 70... | Line 82... | |||
70 | SoundBeamRegisterService.ReplyDomain = "local"; |
82 | SoundBeamRegisterService.ReplyDomain = "local."; |
|
71 | |
83 | |
|
72 | SoundBeamRegisterService.Response += OnRegisterServiceResponse; |
84 | SoundBeamRegisterService.Response += OnRegisterServiceResponse; |
|
73 | SoundBeamRegisterService.Register(); |
85 | SoundBeamRegisterService.Register(); |
|
Line 74... | Line 86... | |||
74 | |
86 | |
|
75 | // Browse for services. |
87 | // Browse for services. |
|
76 | SoundBeamServiceBrowser.ServiceAdded += OnSoundBeamServiceBrowserServiceAdded; |
88 | SoundBeamServiceBrowser.ServiceAdded += OnSoundBeamServiceBrowserServiceAdded; |
|
Line 105... | Line 117... | |||
105 | } |
117 | } |
|
106 | } |
118 | } |
|
Line 107... | Line 119... | |||
107 | |
119 | |
|
108 | private void OnSoundBeamServiceBrowserServiceAdded(object o, ServiceBrowseEventArgs args) |
120 | private void OnSoundBeamServiceBrowserServiceAdded(object o, ServiceBrowseEventArgs args) |
|
- | 121 | { |
||
- | 122 | if (args?.Service == null) |
||
- | 123 | return; |
||
- | 124 | |
||
109 | { |
125 | args.Service.Resolved += OnSoundBeamServiceResolved; |
|
- | 126 | args.Service.Resolve(); |
||
- | 127 | } |
||
- | 128 | |
||
- | 129 | private void OnSoundBeamServiceResolved(object o, ServiceResolvedEventArgs args) |
||
- | 130 | { |
||
- | 131 | if (args?.Service == null) |
||
- | 132 | return; |
||
- | 133 | |
||
- | 134 | args.Service.Resolved -= OnSoundBeamServiceResolved; |
||
- | 135 | |
||
- | 136 | // Do not add already added servers. |
||
- | 137 | if (DiscoveredServersBindingList.Any(server => |
||
- | 138 | string.Equals(server.Hostname, args.Service.HostTarget, StringComparison.OrdinalIgnoreCase) && |
||
- | 139 | server.Port == args.Service.Port)) |
||
- | 140 | return; |
||
- | 141 | |
||
- | 142 | Invoke((Action) (() => |
||
- | 143 | { |
||
- | 144 | DiscoveredServersBindingList.Add(new DiscoveredServer(args.Service.HostTarget, args.Service.Port)); |
||
110 | var a = args.Service.HostTarget; |
145 | })); |
|
Line 111... | Line 146... | |||
111 | } |
146 | } |
|
112 | |
147 | |
|
113 | private void OnRegisterServiceResponse(object o, RegisterServiceEventArgs args) |
148 | private void OnRegisterServiceResponse(object o, RegisterServiceEventArgs args) |
|
Line 147... | Line 182... | |||
147 | |
182 | |
|
Line 148... | Line 183... | |||
148 | } |
183 | } |
|
149 | |
184 | |
|
- | 185 | private void OnQuitToolStripMenuItemClick(object sender, EventArgs e) |
||
- | 186 | { |
||
150 | private void OnQuitToolStripMenuItemClick(object sender, EventArgs e) |
187 | Dispose(true); |
|
151 | { |
188 | |
|
- | 189 | Application.Exit(); |
||
- | 190 | } |
||
- | 191 | |
||
- | 192 | private void OnFormLoad(object sender, EventArgs e) |
||
- | 193 | { |
||
152 | Application.Exit(); |
194 | |
|
153 | } |
195 | } |