VLCLocalNetworkServiceBrowserHTTP.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. - (void)dealloc {
  26. [[NSNotificationCenter defaultCenter] removeObserver:self];
  27. }
  28. - (VLCSharedLibraryParser *)httpParser {
  29. if (!_httpParser) {
  30. _httpParser = [[VLCSharedLibraryParser alloc] init];
  31. [[NSNotificationCenter defaultCenter] addObserver:self
  32. selector:@selector(sharedLibraryFound:)
  33. name:VLCSharedLibraryParserDeterminedNetserviceAsVLCInstance
  34. object:_httpParser];
  35. }
  36. return _httpParser;
  37. }
  38. - (void)netServiceDidResolveAddress:(NSNetService *)sender {
  39. #if !TARGET_OS_TV
  40. NSString *ownHostname = [[VLCHTTPUploaderController sharedInstance] hostname];
  41. if ([[sender hostName] rangeOfString:ownHostname].location != NSNotFound) {
  42. return;
  43. }
  44. #endif
  45. [self.httpParser checkNetserviceForVLCService:sender];
  46. }
  47. - (void)sharedLibraryFound:(NSNotification *)aNotification {
  48. NSNetService *netService = [aNotification.userInfo objectForKey:@"aNetService"];
  49. [[NSOperationQueue mainQueue] addOperationWithBlock:^{
  50. [self addResolvedLocalNetworkService:[self localServiceForNetService:netService]];
  51. }];
  52. }
  53. - (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
  54. return [[VLCLocalNetworkServiceHTTP alloc] initWithNetService:netService];
  55. }
  56. @end
  57. @implementation VLCLocalNetworkServiceHTTP
  58. - (UIImage *)icon {
  59. return [UIImage imageNamed:@"menuCone"];
  60. }
  61. - (id<VLCNetworkServerBrowser>)serverBrowser {
  62. NSNetService *service = self.netService;
  63. if (service.hostName == nil || service.port == 0) {
  64. return nil;
  65. }
  66. NSString *name = service.name;
  67. NSString *hostName = service.hostName;
  68. NSUInteger portNum = service.port;
  69. VLCNetworkServerBrowserSharedLibrary *serverBrowser = [[VLCNetworkServerBrowserSharedLibrary alloc] initWithName:name host:hostName portNumber:portNum];
  70. return serverBrowser;
  71. }
  72. @end