VLCLocalServerListViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*****************************************************************************
  2. * VLCLocalServerListViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2014 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Pierre SAGASPE <pierre.sagaspe # me.com>
  10. * Gleb Pinigin <gpinigin # gmail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCLocalServerListViewController.h"
  15. #import "UIBarButtonItem+Theme.h"
  16. #import "VLCAppDelegate.h"
  17. #import "UPnPManager.h"
  18. #import "VLCLocalNetworkListCell.h"
  19. #import "VLCLocalServerFolderListViewController.h"
  20. #import "VLCLocalPlexFolderListViewController.h"
  21. #import <QuartzCore/QuartzCore.h>
  22. #import "GHRevealViewController.h"
  23. #import "VLCNetworkLoginViewController.h"
  24. #import "UINavigationController+Theme.h"
  25. #import "VLCPlaylistViewController.h"
  26. #import "Reachability.h"
  27. #define kPlexServiceType @"_plexmediasvr._tcp."
  28. @interface VLCLocalServerListViewController () <UITableViewDataSource, UITableViewDelegate, NSNetServiceBrowserDelegate, VLCNetworkLoginViewController, NSNetServiceDelegate, VLCMediaListDelegate, UPnPDBObserver>
  29. {
  30. UIBarButtonItem *_backToMenuButton;
  31. NSArray *_sectionHeaderTexts;
  32. NSNetServiceBrowser *_ftpNetServiceBrowser;
  33. NSNetServiceBrowser *_PlexNetServiceBrowser;
  34. NSMutableArray *_PlexServices;
  35. NSMutableArray *_PlexServicesInfo;
  36. NSMutableArray *_rawNetServices;
  37. NSMutableArray *_ftpServices;
  38. NSArray *_filteredUPNPDevices;
  39. NSArray *_UPNPdevices;
  40. VLCMediaDiscoverer * _sapDiscoverer;
  41. VLCNetworkLoginViewController *_loginViewController;
  42. UIRefreshControl *_refreshControl;
  43. UIActivityIndicatorView *_activityIndicator;
  44. Reachability *_reachability;
  45. BOOL _udnpDiscoveryRunning;
  46. NSTimer *_searchTimer;
  47. }
  48. @end
  49. @implementation VLCLocalServerListViewController
  50. - (void)dealloc
  51. {
  52. [_reachability stopNotifier];
  53. [_ftpNetServiceBrowser stop];
  54. [_PlexNetServiceBrowser stop];
  55. }
  56. - (void)loadView
  57. {
  58. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  59. _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  60. _tableView.delegate = self;
  61. _tableView.dataSource = self;
  62. _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  63. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. self.view = _tableView;
  65. _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  66. _activityIndicator.center = _tableView.center;
  67. _activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  68. _activityIndicator.hidesWhenStopped = YES;
  69. [self.view addSubview:_activityIndicator];
  70. }
  71. - (void)viewDidLoad
  72. {
  73. [super viewDidLoad];
  74. /* if (SYSTEM_RUNS_IOS7_OR_LATER)
  75. _sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"File Transfer Protocol (FTP)", @"Network Streams (SAP)"];
  76. else*/
  77. _sectionHeaderTexts = @[@"Universal Plug'n'Play (UPnP)", @"Plex Media Server (via Bonjour)", @"File Transfer Protocol (FTP)"];
  78. _backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
  79. self.navigationItem.leftBarButtonItem = _backToMenuButton;
  80. self.tableView.rowHeight = [VLCLocalNetworkListCell heightOfCell];
  81. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  82. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  83. self.title = NSLocalizedString(@"LOCAL_NETWORK", nil);
  84. _ftpServices = [[NSMutableArray alloc] init];
  85. [_ftpServices addObject:NSLocalizedString(@"CONNECT_TO_SERVER", nil)];
  86. _rawNetServices = [[NSMutableArray alloc] init];
  87. _ftpNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
  88. _ftpNetServiceBrowser.delegate = self;
  89. _PlexServices = [[NSMutableArray alloc] init];
  90. _PlexServicesInfo = [[NSMutableArray alloc] init];
  91. _PlexNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
  92. _PlexNetServiceBrowser.delegate = self;
  93. _refreshControl = [[UIRefreshControl alloc] init];
  94. [_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
  95. [self.tableView addSubview:_refreshControl];
  96. if (SYSTEM_RUNS_IOS7_OR_LATER)
  97. _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCFutureNetworkLoginViewController" bundle:nil];
  98. else
  99. _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
  100. _loginViewController.delegate = self;
  101. _reachability = [Reachability reachabilityForLocalWiFi];
  102. [_reachability startNotifier];
  103. [self netReachabilityChanged:nil];
  104. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
  105. }
  106. - (void)viewWillDisappear:(BOOL)animated
  107. {
  108. [super viewWillDisappear:animated];
  109. [_activityIndicator stopAnimating];
  110. [_ftpNetServiceBrowser stop];
  111. [_PlexNetServiceBrowser stop];
  112. }
  113. - (void)viewWillAppear:(BOOL)animated
  114. {
  115. [_ftpNetServiceBrowser searchForServicesOfType:@"_ftp._tcp." inDomain:@""];
  116. [_PlexNetServiceBrowser searchForServicesOfType:kPlexServiceType inDomain:@""];
  117. [_activityIndicator stopAnimating];
  118. [super viewWillAppear:animated];
  119. [self netReachabilityChanged:nil];
  120. }
  121. - (void)netReachabilityChanged:(NSNotification *)notification
  122. {
  123. if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
  124. [self performSelectorInBackground:@selector(_startUPNPDiscovery) withObject:nil];
  125. [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
  126. } else {
  127. [self _stopUPNPDiscovery];
  128. [self _stopSAPDiscovery];
  129. }
  130. }
  131. - (void)_startUPNPDiscovery
  132. {
  133. if (_reachability.currentReachabilityStatus != ReachableViaWiFi)
  134. return;
  135. UPnPManager *managerInstance = [UPnPManager GetInstance];
  136. _UPNPdevices = [[managerInstance DB] rootDevices];
  137. if (_UPNPdevices.count > 0)
  138. [self UPnPDBUpdated:nil];
  139. [[managerInstance DB] addObserver:self];
  140. //Optional; set User Agent
  141. [[managerInstance SSDP] setUserAgentProduct:[NSString stringWithFormat:@"VLCforiOS/%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]] andOS:[NSString stringWithFormat:@"iOS/%@", [[UIDevice currentDevice] systemVersion]]];
  142. //Search for UPnP Devices
  143. [[managerInstance SSDP] startSSDP];
  144. [[managerInstance SSDP] notifySSDPAlive];
  145. _searchTimer = [NSTimer timerWithTimeInterval:10.0 target:self selector:@selector(_performSSDPSearch) userInfo:nil repeats:YES];
  146. [_searchTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  147. [[NSRunLoop mainRunLoop] addTimer:_searchTimer forMode:NSRunLoopCommonModes];
  148. _udnpDiscoveryRunning = YES;
  149. }
  150. - (void)_performSSDPSearch
  151. {
  152. UPnPManager *managerInstance = [UPnPManager GetInstance];
  153. [[managerInstance SSDP] searchSSDP];
  154. [[managerInstance SSDP] searchForMediaServer];
  155. [[managerInstance SSDP] SSDPDBUpdate];
  156. }
  157. - (void)_stopUPNPDiscovery
  158. {
  159. if (_udnpDiscoveryRunning) {
  160. UPnPManager *managerInstance = [UPnPManager GetInstance];
  161. [[managerInstance SSDP] notifySSDPByeBye];
  162. [_searchTimer invalidate];
  163. _searchTimer = nil;
  164. [[managerInstance DB] removeObserver:self];
  165. [[managerInstance SSDP] stopSSDP];
  166. _udnpDiscoveryRunning = NO;
  167. }
  168. }
  169. - (IBAction)goBack:(id)sender
  170. {
  171. [self _stopUPNPDiscovery];
  172. [self _stopSAPDiscovery];
  173. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  174. }
  175. - (BOOL)shouldAutorotate
  176. {
  177. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  178. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  179. return NO;
  180. return YES;
  181. }
  182. #pragma mark - table view handling
  183. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  184. {
  185. return _sectionHeaderTexts.count;
  186. }
  187. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  188. {
  189. if (section == 0)
  190. return _filteredUPNPDevices.count;
  191. else if (section == 1)
  192. return _PlexServices.count;
  193. else if (section == 2)
  194. return _ftpServices.count;
  195. else if (section == 3)
  196. return _sapDiscoverer.discoveredMedia.count;
  197. return 0;
  198. }
  199. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCLocalNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  200. {
  201. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  202. cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  203. }
  204. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  205. {
  206. static NSString *CellIdentifier = @"LocalNetworkCell";
  207. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  208. if (cell == nil)
  209. cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  210. NSUInteger row = indexPath.row;
  211. NSUInteger section = indexPath.section;
  212. [cell setIsDirectory:YES];
  213. [cell setIcon:nil];
  214. if (section == 0) {
  215. UIImage *icon;
  216. if (_filteredUPNPDevices.count > row) {
  217. BasicUPnPDevice *device = _filteredUPNPDevices[row];
  218. [cell setTitle:[device friendlyName]];
  219. icon = [device smallIcon];
  220. }
  221. [cell setIcon:icon != nil ? icon : [UIImage imageNamed:@"serverIcon"]];
  222. } else if (section == 1) {
  223. [cell setTitle:[_PlexServices[row] name]];
  224. [cell setIcon:[UIImage imageNamed:@"PlexServerIcon"]];
  225. } else if (section == 2) {
  226. if (row == 0)
  227. [cell setTitle:_ftpServices[row]];
  228. else {
  229. [cell setTitle:[_ftpServices[row] name]];
  230. [cell setIcon:[UIImage imageNamed:@"serverIcon"]];
  231. }
  232. } else if (section == 3)
  233. [cell setTitle:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] metadataForKey: VLCMetaInformationTitle]];
  234. return cell;
  235. }
  236. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  237. {
  238. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  239. NSUInteger row = indexPath.row;
  240. NSUInteger section = indexPath.section;
  241. if (section == 0) {
  242. if (_filteredUPNPDevices.count < row || _filteredUPNPDevices.count == 0)
  243. return;
  244. [_activityIndicator startAnimating];
  245. BasicUPnPDevice *device = _filteredUPNPDevices[row];
  246. if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
  247. MediaServer1Device *server = (MediaServer1Device*)device;
  248. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithUPNPDevice:server header:[device friendlyName] andRootID:@"0"];
  249. [self.navigationController pushViewController:targetViewController animated:YES];
  250. }
  251. } else if (section == 1) {
  252. NSString *name = [_PlexServicesInfo[row] objectForKey:@"name"];
  253. NSString *hostName = [_PlexServicesInfo[row] objectForKey:@"hostName"];
  254. NSString *portNum = [_PlexServicesInfo[row] objectForKey:@"port"];
  255. VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:name serverAddress:hostName portNumber:portNum atPath:@""];
  256. [[self navigationController] pushViewController:targetViewController animated:YES];
  257. } else if (section == 2) {
  258. UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_loginViewController];
  259. [navCon loadTheme];
  260. navCon.navigationBarHidden = NO;
  261. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  262. navCon.modalPresentationStyle = UIModalPresentationFormSheet;
  263. [self presentViewController:navCon animated:YES completion:nil];
  264. if (_loginViewController.navigationItem.leftBarButtonItem == nil) {
  265. UIBarButtonItem *doneButton = [UIBarButtonItem themedDoneButtonWithTarget:_loginViewController andSelector:@selector(dismissWithAnimation:)];
  266. _loginViewController.navigationItem.leftBarButtonItem = doneButton;
  267. }
  268. } else
  269. [self.navigationController pushViewController:_loginViewController animated:YES];
  270. if (row != 0 && [_ftpServices[row] hostName].length > 0) // FTP Connect To Server Special Item and hostname is long enough
  271. _loginViewController.hostname = [_ftpServices[row] hostName];
  272. else
  273. _loginViewController.hostname = @"";
  274. } else if (section == 3) {
  275. VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
  276. [appDelegate openMovieFromURL:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] url]];
  277. }
  278. }
  279. #pragma mark - Refresh
  280. -(void)handleRefresh
  281. {
  282. if (_reachability.currentReachabilityStatus != ReachableViaWiFi) {
  283. [_refreshControl endRefreshing];
  284. return;
  285. }
  286. UPnPManager *managerInstance = [UPnPManager GetInstance];
  287. [[managerInstance DB] removeObserver:self];
  288. [[managerInstance SSDP] stopSSDP];
  289. //set the title while refreshing
  290. _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"LOCAL_SERVER_REFRESH",nil)];
  291. //set the date and time of refreshing
  292. NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
  293. [formattedDate setDateFormat:@"MMM d, h:mm a"];
  294. NSString *lastupdated = [NSString stringWithFormat:NSLocalizedString(@"LOCAL_SERVER_LAST_UPDATE",nil),[formattedDate stringFromDate:[NSDate date]]];
  295. _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated];
  296. //end the refreshing
  297. [_refreshControl endRefreshing];
  298. [self.tableView reloadData];
  299. [self performSelectorInBackground:@selector(_startUPNPDiscovery) withObject:nil];
  300. [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
  301. }
  302. #pragma mark - login panel protocol
  303. - (void)loginToURL:(NSURL *)url confirmedWithUsername:(NSString *)username andPassword:(NSString *)password
  304. {
  305. if ([url.scheme isEqualToString:@"ftp"]) {
  306. if (url.host.length > 0) {
  307. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithFTPServer:url.host userName:username andPassword:password atPath:@"/"];
  308. [self.navigationController pushViewController:targetViewController animated:YES];
  309. }
  310. } else
  311. APLog(@"Unsupported URL Scheme requested %@", url.scheme);
  312. }
  313. #pragma mark - custom table view appearance
  314. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  315. {
  316. return 21.f;
  317. }
  318. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  319. {
  320. NSObject *headerText = NSLocalizedString(_sectionHeaderTexts[section], nil);
  321. UIView *headerView = nil;
  322. if (headerText != [NSNull null]) {
  323. headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 21.0f)];
  324. if (!SYSTEM_RUNS_IOS7_OR_LATER) {
  325. CAGradientLayer *gradient = [CAGradientLayer layer];
  326. gradient.frame = headerView.bounds;
  327. gradient.colors = @[
  328. (id)[UIColor colorWithRed:(66.0f/255.0f) green:(66.0f/255.0f) blue:(66.0f/255.0f) alpha:1.0f].CGColor,
  329. (id)[UIColor colorWithRed:(56.0f/255.0f) green:(56.0f/255.0f) blue:(56.0f/255.0f) alpha:1.0f].CGColor,
  330. ];
  331. [headerView.layer insertSublayer:gradient atIndex:0];
  332. } else
  333. headerView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  334. UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 12.0f, 0.f)];
  335. textLabel.text = (NSString *) headerText;
  336. textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:([UIFont systemFontSize] * 0.8f)];
  337. textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
  338. textLabel.shadowColor = [UIColor VLCDarkTextShadowColor];
  339. textLabel.textColor = [UIColor colorWithRed:(118.0f/255.0f) green:(118.0f/255.0f) blue:(118.0f/255.0f) alpha:1.0f];
  340. textLabel.backgroundColor = [UIColor clearColor];
  341. [headerView addSubview:textLabel];
  342. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
  343. topLine.backgroundColor = [UIColor colorWithRed:(95.0f/255.0f) green:(95.0f/255.0f) blue:(95.0f/255.0f) alpha:1.0f];
  344. [headerView addSubview:topLine];
  345. UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 21.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
  346. bottomLine.backgroundColor = [UIColor colorWithRed:(16.0f/255.0f) green:(16.0f/255.0f) blue:(16.0f/255.0f) alpha:1.0f];
  347. [headerView addSubview:bottomLine];
  348. }
  349. return headerView;
  350. }
  351. #pragma mark - bonjour discovery
  352. - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
  353. {
  354. APLog(@"found bonjour service: %@ (%@)", aNetService.name, aNetService.type);
  355. [_rawNetServices addObject:aNetService];
  356. aNetService.delegate = self;
  357. [aNetService resolveWithTimeout:5.];
  358. }
  359. - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
  360. {
  361. APLog(@"bonjour service disappeared: %@ (%i)", aNetService.name, moreComing);
  362. if ([_rawNetServices containsObject:aNetService])
  363. [_rawNetServices removeObject:aNetService];
  364. if ([aNetService.type isEqualToString:@"_ftp._tcp."])
  365. [_ftpServices removeObject:aNetService];
  366. if ([aNetService.type isEqualToString:kPlexServiceType]) {
  367. [_PlexServices removeObject:aNetService];
  368. [_PlexServicesInfo removeAllObjects];
  369. }
  370. if (!moreComing)
  371. [self.tableView reloadData];
  372. }
  373. - (void)netServiceDidResolveAddress:(NSNetService *)aNetService
  374. {
  375. if ([aNetService.type isEqualToString:@"_ftp._tcp."]) {
  376. if (![_ftpServices containsObject:aNetService])
  377. [_ftpServices addObject:aNetService];
  378. } else if ([aNetService.type isEqualToString:kPlexServiceType]) {
  379. if (![_PlexServices containsObject:aNetService]) {
  380. [_PlexServices addObject:aNetService];
  381. NSMutableDictionary *_dictService = [[NSMutableDictionary alloc] init];
  382. [_dictService setObject:[aNetService name] forKey:@"name"];
  383. [_dictService setObject:[aNetService hostName] forKey:@"hostName"];
  384. NSString *portStr = [[NSString alloc] initWithFormat:@":%ld", (long)[aNetService port]];
  385. [_dictService setObject:portStr forKey:@"port"];
  386. [_PlexServicesInfo addObject:_dictService];
  387. }
  388. }
  389. [_rawNetServices removeObject:aNetService];
  390. [self.tableView reloadData];
  391. }
  392. - (void)netService:(NSNetService *)aNetService didNotResolve:(NSDictionary *)errorDict
  393. {
  394. APLog(@"failed to resolve: %@", aNetService.name);
  395. [_rawNetServices removeObject:aNetService];
  396. }
  397. #pragma mark - UPNP details
  398. //protocol UPnPDBObserver
  399. - (void)UPnPDBWillUpdate:(UPnPDB*)sender
  400. {
  401. }
  402. - (void)UPnPDBUpdated:(UPnPDB*)sender
  403. {
  404. NSUInteger count = _UPNPdevices.count;
  405. BasicUPnPDevice *device;
  406. NSMutableArray *mutArray = [[NSMutableArray alloc] init];
  407. for (NSUInteger x = 0; x < count; x++) {
  408. device = _UPNPdevices[x];
  409. if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"])
  410. [mutArray addObject:device];
  411. else
  412. APLog(@"found device '%@' with unsupported urn '%@'", [device friendlyName], [device urn]);
  413. }
  414. _filteredUPNPDevices = nil;
  415. _filteredUPNPDevices = [NSArray arrayWithArray:mutArray];
  416. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
  417. }
  418. #pragma mark SAP discovery
  419. - (void)_startSAPDiscovery
  420. {
  421. return;
  422. if (_reachability.currentReachabilityStatus != ReachableViaWiFi)
  423. return;
  424. _sapDiscoverer = [[VLCMediaDiscoverer alloc] initWithName:@"sap"];
  425. _sapDiscoverer.discoveredMedia.delegate = self;
  426. }
  427. - (void)_stopSAPDiscovery
  428. {
  429. return;
  430. _sapDiscoverer = nil;
  431. }
  432. - (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
  433. {
  434. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  435. }
  436. - (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(NSInteger)index
  437. {
  438. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  439. }
  440. @end