VLCLocalServerListViewController.m 21 KB

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