VLCLocalNetworkServiceBrowserHTTP.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*****************************************************************************
  2. * VLCLocalNetworkServiceBrowserHTTP.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCLocalNetworkServiceBrowserHTTP.h"
  13. #import "VLCSharedLibraryParser.h"
  14. #import "VLCHTTPUploaderController.h"
  15. #import "VLCNetworkServerBrowserSharedLibrary.h"
  16. @interface VLCLocalNetworkServiceBrowserHTTP()
  17. @property (nonatomic) VLCSharedLibraryParser *httpParser;
  18. @end
  19. @implementation VLCLocalNetworkServiceBrowserHTTP
  20. - (instancetype)init {
  21. return [super initWithName:NSLocalizedString(@"SHARED_VLC_IOS_LIBRARY", nil)
  22. serviceType:@"_http._tcp."
  23. domain:@""];
  24. }
  25. - (VLCSharedLibraryParser *)httpParser {
  26. if (!_httpParser) {
  27. _httpParser = [[VLCSharedLibraryParser alloc] init];
  28. [[NSNotificationCenter defaultCenter] addObserver:self
  29. selector:@selector(sharedLibraryFound:)
  30. name:VLCSharedLibraryParserDeterminedNetserviceAsVLCInstance
  31. object:_httpParser];
  32. }
  33. return _httpParser;
  34. }
  35. - (void)netServiceDidResolveAddress:(NSNetService *)sender {
  36. #if !TARGET_OS_TV
  37. NSString *ownHostname = [[VLCHTTPUploaderController sharedInstance] hostname];
  38. if ([[sender hostName] rangeOfString:ownHostname].location != NSNotFound) {
  39. return;
  40. }
  41. #endif
  42. [self.httpParser checkNetserviceForVLCService:sender];
  43. }
  44. - (void)sharedLibraryFound:(NSNotification *)aNotification {
  45. NSNetService *netService = [aNotification.userInfo objectForKey:@"aNetService"];
  46. [[NSOperationQueue mainQueue] addOperationWithBlock:^{
  47. [self addResolvedLocalNetworkService:[self localServiceForNetService:netService]];
  48. }];
  49. }
  50. - (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
  51. return [[VLCLocalNetworkServiceHTTP alloc] initWithNetService:netService serviceName:self.name];
  52. }
  53. @end
  54. @implementation VLCLocalNetworkServiceHTTP
  55. - (UIImage *)icon {
  56. return [UIImage imageNamed:@"WifiIcon"];
  57. }
  58. - (id<VLCNetworkServerBrowser>)serverBrowser {
  59. NSNetService *service = self.netService;
  60. if (service.hostName == nil || service.port == 0) {
  61. return nil;
  62. }
  63. NSString *name = service.name;
  64. NSString *hostName = service.hostName;
  65. NSUInteger portNum = service.port;
  66. VLCNetworkServerBrowserSharedLibrary *serverBrowser = [[VLCNetworkServerBrowserSharedLibrary alloc] initWithName:name host:hostName portNumber:portNum];
  67. return serverBrowser;
  68. }
  69. @end