VLCLocalNetworkServiceBrowserHTTP.m 2.8 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. - (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. NSString *ownHostname = [[VLCHTTPUploaderController sharedInstance] hostname];
  40. if ([[sender hostName] rangeOfString:ownHostname].location != NSNotFound) {
  41. return;
  42. }
  43. [self.httpParser checkNetserviceForVLCService:sender];
  44. }
  45. - (void)sharedLibraryFound:(NSNotification *)aNotification {
  46. NSNetService *netService = [aNotification.userInfo objectForKey:@"aNetService"];
  47. [self addResolvedLocalNetworkService:[self localServiceForNetService:netService]];
  48. }
  49. - (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
  50. return [[VLCLocalNetworkServiceHTTP alloc] initWithNetService:netService];
  51. }
  52. @end
  53. @implementation VLCLocalNetworkServiceHTTP
  54. - (UIImage *)icon {
  55. return [UIImage imageNamed:@"menuCone"];
  56. }
  57. - (id<VLCNetworkServerBrowser>)serverBrowser {
  58. NSNetService *service = self.netService;
  59. if (service.hostName == nil || service.port == 0) {
  60. return nil;
  61. }
  62. NSString *name = service.name;
  63. NSString *hostName = service.hostName;
  64. NSUInteger portNum = service.port;
  65. VLCNetworkServerBrowserSharedLibrary *serverBrowser = [[VLCNetworkServerBrowserSharedLibrary alloc] initWithName:name host:hostName portNumber:portNum];
  66. return serverBrowser;
  67. }
  68. @end