Commit 40ca6f13 authored by Tobias's avatar Tobias

create VLCMediaDiscoverer based LocalNetworkServiceBrowsers for SAP and DSM

parent f0455452
/*****************************************************************************
* VLCLocalNetworkServiceBrowserMediaDiscoverer.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowser-Protocol.h"
@interface VLCLocalNetworkServiceBrowserMediaDiscoverer : NSObject <VLCLocalNetworkServiceBrowser>
- (instancetype)initWithName:(NSString *)name serviceServiceName:(NSString *)serviceName; NS_DESIGNATED_INITIALIZER;
@property (nonatomic, weak) id<VLCLocalNetworkServiceBrowserDelegate> delegate;
@end
@interface VLCLocalNetworkServiceBrowserMediaDiscoverer ()
@property (nonatomic, readonly) NSString *serviceName;
@property (nonatomic, readonly) VLCMediaDiscoverer* mediaDiscoverer;
@end
@interface VLCLocalNetworkServiceBrowserSAP : VLCLocalNetworkServiceBrowserMediaDiscoverer
- (instancetype)init;
@end
@interface VLCLocalNetworkServiceBrowserDSM : VLCLocalNetworkServiceBrowserMediaDiscoverer
- (instancetype)init;
@end
\ No newline at end of file
/*****************************************************************************
* VLCLocalNetworkServiceBrowserMediaDiscoverer.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserMediaDiscoverer.h"
@interface VLCLocalNetworkServiceBrowserMediaDiscoverer () <VLCMediaListDelegate>
@end
@implementation VLCLocalNetworkServiceBrowserMediaDiscoverer
@synthesize name = _name;
- (instancetype)initWithName:(NSString *)name serviceServiceName:(NSString *)serviceName
{
self = [super init];
if (self) {
_name = name;
_serviceName = serviceName;
_mediaDiscoverer = [[VLCMediaDiscoverer alloc] initWithName:serviceName];
_mediaDiscoverer.discoveredMedia.delegate = self;
}
return self;
}
- (void)startDiscovery
{
[self.mediaDiscoverer startDiscoverer];
}
- (void)stopDiscovery
{
[self.mediaDiscoverer stopDiscoverer];
}
- (NSUInteger)numberOfItems {
return self.mediaDiscoverer.discoveredMedia.count;
}
- (id<VLCLocalNetworkService>)networkServiceForIndex:(NSUInteger)index {
VLCMedia *media = [self.mediaDiscoverer.discoveredMedia mediaAtIndex:index];
return [[VLCLocalNetworkServiceVLCMedia alloc] initWithMediaItem:media];
}
#pragma mark - VLCMediaListDelegate
- (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
{
[self.delegate localNetworkServiceBrowserDidUpdateServices:self];
}
- (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(NSInteger)index
{
[self.delegate localNetworkServiceBrowserDidUpdateServices:self];
}
@end
#pragma mark - service specific subclasses
@implementation VLCLocalNetworkServiceBrowserSAP
- (instancetype)init {
return [super initWithName:@"SAP"
serviceServiceName:@"sap"];
}
- (id<VLCLocalNetworkService>)networkServiceForIndex:(NSUInteger)index {
VLCMedia *media = [self.mediaDiscoverer.discoveredMedia mediaAtIndex:index];
return [[VLCLocalNetworkServiceSAP alloc] initWithMediaItem:media];
}
@end
@implementation VLCLocalNetworkServiceBrowserDSM
- (instancetype)init {
return [super initWithName:NSLocalizedString(@"SMB_CIFS_FILE_SERVERS", nil)
serviceServiceName:@"dsm"];
}
- (id<VLCLocalNetworkService>)networkServiceForIndex:(NSUInteger)index {
VLCMedia *media = [self.mediaDiscoverer.discoveredMedia mediaAtIndex:index];
return [[VLCLocalNetworkServiceDSM alloc] initWithMediaItem:media];
}
@end
......@@ -32,6 +32,7 @@
#import "Reachability.h"
#import "VLCLocalNetworkServiceBrowserNetService.h"
#import "VLCLocalNetworkServiceBrowserMediaDiscoverer.h"
typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
......@@ -56,8 +57,8 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
NSArray<VLCLocalNetworkServiceUPnP*> *_filteredUPNPDevices;
NSArray *_UPNPdevices;
VLCMediaDiscoverer *_sapDiscoverer;
VLCMediaDiscoverer *_dsmDiscoverer;
id<VLCLocalNetworkServiceBrowser> _sapBrowser;
id<VLCLocalNetworkServiceBrowser> _dsmBrowser;
VLCSharedLibraryParser *_httpParser;
......@@ -85,8 +86,8 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
- (void)stopDiscovery
{
[self _stopUPNPDiscovery];
[self _stopSAPDiscovery];
[self _stopDSMDiscovery];
[_sapBrowser stopDiscovery];
[_dsmBrowser stopDiscovery];
[_FTPBrowser stopDiscovery];
[_plexBrowser stopDiscovery];
......@@ -110,8 +111,8 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
_plexBrowser.name,
_FTPBrowser.name,
_HTTPBrowser.name,
NSLocalizedString(@"SMB_CIFS_FILE_SERVERS", nil),
@"SAP"];
_dsmBrowser.name,
_sapBrowser.name];
}
- (instancetype)init
......@@ -140,6 +141,10 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
_HTTPBrowser = [[VLCLocalNetworkServiceBrowserHTTP alloc] init];
_HTTPBrowser.delegate = self;
_sapBrowser = [[VLCLocalNetworkServiceBrowserSAP alloc] init];
_sapBrowser.delegate = self;
_reachability = [Reachability reachabilityForLocalWiFi];
[_reachability startNotifier];
......@@ -156,20 +161,17 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
{
if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
[self _startUPNPDiscovery];
[self _startSAPDiscovery];
[self _startDSMDiscovery];
[self startDiscovery];
} else {
[self _stopUPNPDiscovery];
[self _stopSAPDiscovery];
[self _stopDSMDiscovery];
[self stopDiscovery];
}
}
- (IBAction)goBack:(id)sender
{
[self _stopUPNPDiscovery];
[self _stopSAPDiscovery];
[self _stopDSMDiscovery];
[self stopDiscovery];
[[VLCSidebarController sharedInstance] toggleSidebar];
}
......@@ -220,12 +222,12 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
case VLCLocalServerSectionSMB:
{
return [[VLCLocalNetworkServiceDSM alloc] initWithMediaItem:[_dsmDiscoverer.discoveredMedia mediaAtIndex:row]];
return [_dsmBrowser networkServiceForIndex:row];
}
case VLCLocalServerSectionSAP:
{
return [[VLCLocalNetworkServiceSAP alloc] initWithMediaItem:[_sapDiscoverer.discoveredMedia mediaAtIndex:row]];
return [_sapBrowser networkServiceForIndex:row];
}
default:
......@@ -255,10 +257,10 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
return _HTTPBrowser.numberOfItems;
case VLCLocalServerSectionSMB:
return _dsmDiscoverer.discoveredMedia.count;
return _dsmBrowser.numberOfItems;
case VLCLocalServerSectionSAP:
return _sapDiscoverer.discoveredMedia.count;
return _sapBrowser.numberOfItems;
default:
return 0;
......@@ -273,11 +275,8 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
UPnPManager *managerInstance = [UPnPManager GetInstance];
[[managerInstance DB] removeObserver:self];
[[managerInstance SSDP] stopSSDP];
[self _stopDSMDiscovery];
[self _startUPNPDiscovery];
[self _startSAPDiscovery];
[self _startDSMDiscovery];
return YES;
}
......@@ -367,63 +366,4 @@ typedef NS_ENUM(NSUInteger, VLCLocalServerSections) {
}
}
#pragma mark SAP discovery
- (void)_startSAPDiscovery
{
if (_reachability.currentReachabilityStatus != ReachableViaWiFi)
return;
if (!_sapDiscoverer)
_sapDiscoverer = [[VLCMediaDiscoverer alloc] initWithName:@"sap"];
[_sapDiscoverer startDiscoverer];
_sapDiscoverer.discoveredMedia.delegate = self;
}
- (void)_stopSAPDiscovery
{
[_sapDiscoverer stopDiscoverer];
_sapDiscoverer = nil;
}
- (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
{
[media parseWithOptions:VLCMediaParseNetwork];
if (self.delegate) {
if ([self.delegate respondsToSelector:@selector(discoveryFoundSomethingNew)]) {
[self.delegate performSelectorOnMainThread:@selector(discoveryFoundSomethingNew) withObject:nil waitUntilDone:NO];
}
}
}
- (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(NSInteger)index
{
if (self.delegate) {
if ([self.delegate respondsToSelector:@selector(discoveryFoundSomethingNew)]) {
[self.delegate performSelectorOnMainThread:@selector(discoveryFoundSomethingNew) withObject:nil waitUntilDone:NO];
}
}
}
#pragma DSM discovery
- (void)_startDSMDiscovery
{
if (_reachability.currentReachabilityStatus != ReachableViaWiFi)
return;
if (_dsmDiscoverer)
return;
_dsmDiscoverer = [[VLCMediaDiscoverer alloc] initWithName:@"dsm"];
[_dsmDiscoverer startDiscoverer];
_dsmDiscoverer.discoveredMedia.delegate = self;
}
- (void)_stopDSMDiscovery
{
[_dsmDiscoverer stopDiscoverer];
_dsmDiscoverer = nil;
}
@end
......@@ -262,6 +262,7 @@
DDC10BE41AEE8EA700890DC3 /* VLCTimeNavigationTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDC10BE31AEE8EA700890DC3 /* VLCTimeNavigationTitleView.m */; };
DDE3C8D91BD1322E00C03B8B /* VLCLocalNetworkServiceBrowserNetService.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE3C8D51BD12E6B00C03B8B /* VLCLocalNetworkServiceBrowserNetService.m */; };
DDE3C8DA1BD1323800C03B8B /* VLCLocalNetworkService.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE3C8CF1BD0246500C03B8B /* VLCLocalNetworkService.m */; };
DDE3C8DD1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE3C8DC1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.m */; };
E0C04F951A25B4410080331A /* VLCDocumentPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C04F941A25B4410080331A /* VLCDocumentPickerController.m */; };
/* End PBXBuildFile section */
......@@ -812,6 +813,8 @@
DDE3C8D41BD12E6B00C03B8B /* VLCLocalNetworkServiceBrowserNetService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCLocalNetworkServiceBrowserNetService.h; path = Sources/LocalNetworkConnectivity/VLCLocalNetworkServiceBrowserNetService.h; sourceTree = SOURCE_ROOT; };
DDE3C8D51BD12E6B00C03B8B /* VLCLocalNetworkServiceBrowserNetService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCLocalNetworkServiceBrowserNetService.m; path = Sources/LocalNetworkConnectivity/VLCLocalNetworkServiceBrowserNetService.m; sourceTree = SOURCE_ROOT; };
DDE3C8D71BD12F6800C03B8B /* VLCLocalNetworkService-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "VLCLocalNetworkService-Protocol.h"; sourceTree = "<group>"; };
DDE3C8DB1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCLocalNetworkServiceBrowserMediaDiscoverer.h; path = Sources/LocalNetworkConnectivity/VLCLocalNetworkServiceBrowserMediaDiscoverer.h; sourceTree = SOURCE_ROOT; };
DDE3C8DC1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCLocalNetworkServiceBrowserMediaDiscoverer.m; path = Sources/LocalNetworkConnectivity/VLCLocalNetworkServiceBrowserMediaDiscoverer.m; sourceTree = SOURCE_ROOT; };
DDF157B31ACB169B00AAFBC6 /* WatchKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WatchKit.framework; path = System/Library/Frameworks/WatchKit.framework; sourceTree = SDKROOT; };
E09EACF57CDD22ABAE66CDD0 /* Pods-vlc-ios.distribution.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-vlc-ios.distribution.xcconfig"; path = "Pods/Target Support Files/Pods-vlc-ios/Pods-vlc-ios.distribution.xcconfig"; sourceTree = "<group>"; };
E0C04F931A25B4410080331A /* VLCDocumentPickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCDocumentPickerController.h; path = Sources/VLCDocumentPickerController.h; sourceTree = SOURCE_ROOT; };
......@@ -1135,6 +1138,8 @@
DDE3C8D11BD1103300C03B8B /* VLCLocalNetworkServiceBrowser-Protocol.h */,
DDE3C8D41BD12E6B00C03B8B /* VLCLocalNetworkServiceBrowserNetService.h */,
DDE3C8D51BD12E6B00C03B8B /* VLCLocalNetworkServiceBrowserNetService.m */,
DDE3C8DB1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.h */,
DDE3C8DC1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.m */,
7D37E3981BC93F7500AFA70E /* VLCLocalServerDiscoveryController.h */,
7D37E3991BC93F7500AFA70E /* VLCLocalServerDiscoveryController.m */,
7D30F3DA183AB2F900FFC021 /* VLCNetworkLoginViewController.h */,
......@@ -2139,6 +2144,7 @@
4184AA151A5492070063DF5A /* VLCCloudStorageController.m in Sources */,
9BE4D1CE183D76950006346C /* VLCCloudStorageTableViewCell.m in Sources */,
DD1CB0321BB9E005006EDDE6 /* VLCMovieViewControlPanelViewController.m in Sources */,
DDE3C8DD1BD246DD00C03B8B /* VLCLocalNetworkServiceBrowserMediaDiscoverer.m in Sources */,
2915540117490A1E00B86CAD /* DDData.m in Sources */,
2915540217490A1E00B86CAD /* DDNumber.m in Sources */,
7D92897A1877467E009108FD /* VLCFirstStepsFourthPageViewController.m in Sources */,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment