From f321f71dfeced52b02150cf3cef62514dac08bff Mon Sep 17 00:00:00 2001 From: Zakk Date: Sun, 17 Jul 2016 00:18:36 -0400 Subject: [PATCH] Split File and RTMP outputs into separate types. Twitch output config now has a 'fetch stream key' button that does OAuth authentication and then fetches the user's stream key. --- CocoaSplit/en.lproj/MainMenu.xib | 6 +- .../project.pbxproj | 22 +++++ .../CSFileStreamRTMPService.h | 25 ++++++ .../CSFileStreamRTMPService.m | 80 +++++++++++++++++++ .../CSFileStreamRTMPServiceViewController.h | 18 +++++ .../CSFileStreamRTMPServiceViewController.m | 22 +++++ .../CSFileStreamRTMPServiceViewController.xib | 46 +++++++++++ .../CSFileStreamServiceFactory.h | 20 +++++ .../CSFileStreamServiceFactory.m | 29 +++++++ .../CSFileStreamServicePlugin-Info.plist | 2 +- .../FileStreamService.m | 4 +- .../FileStreamServiceViewController.xib | 4 +- .../HitboxStreamServiceViewController.xib | 14 +--- .../project.pbxproj | 4 + .../TwitchStreamService.h | 3 + .../TwitchStreamService.m | 31 +++++++ .../TwitchStreamServiceViewController.h | 6 +- .../TwitchStreamServiceViewController.m | 71 ++++++++++++++++ .../TwitchStreamServiceViewController.xib | 48 ++++++----- 19 files changed, 412 insertions(+), 43 deletions(-) create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.h create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.m create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.h create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.m create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.xib create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.h create mode 100644 StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.m diff --git a/CocoaSplit/en.lproj/MainMenu.xib b/CocoaSplit/en.lproj/MainMenu.xib index 3a478e2e..b5cc6125 100644 --- a/CocoaSplit/en.lproj/MainMenu.xib +++ b/CocoaSplit/en.lproj/MainMenu.xib @@ -511,7 +511,7 @@ - + @@ -689,7 +689,7 @@ - + @@ -1532,7 +1532,7 @@ - + diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin.xcodeproj/project.pbxproj b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin.xcodeproj/project.pbxproj index cb048096..c8ea719e 100644 --- a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin.xcodeproj/project.pbxproj +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin.xcodeproj/project.pbxproj @@ -12,6 +12,10 @@ 34AFC2E919B08C810007C07B /* FileStreamService.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AFC2E819B08C810007C07B /* FileStreamService.m */; }; 34AFC2ED19B08CA80007C07B /* FileStreamServiceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AFC2EB19B08CA80007C07B /* FileStreamServiceViewController.m */; }; 34AFC2EE19B08CA80007C07B /* FileStreamServiceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34AFC2EC19B08CA80007C07B /* FileStreamServiceViewController.xib */; }; + 34EA82211D3A3B6900928A06 /* CSFileStreamServiceFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 34EA82201D3A3B6900928A06 /* CSFileStreamServiceFactory.m */; }; + 34EA82241D3A3C4E00928A06 /* CSFileStreamRTMPService.m in Sources */ = {isa = PBXBuildFile; fileRef = 34EA82231D3A3C4E00928A06 /* CSFileStreamRTMPService.m */; }; + 34EA82281D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34EA82261D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.m */; }; + 34EA82291D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34EA82271D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -33,6 +37,13 @@ 34D6580C19B343290012E32B /* CSCaptureSourceProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSCaptureSourceProtocol.h; path = PluginHeaders/CSCaptureSourceProtocol.h; sourceTree = ""; }; 34D6580D19B343290012E32B /* CSStreamServiceProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSStreamServiceProtocol.h; path = PluginHeaders/CSStreamServiceProtocol.h; sourceTree = ""; }; 34D6580E19B343290012E32B /* CSPluginFactoryProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSPluginFactoryProtocol.h; path = PluginHeaders/CSPluginFactoryProtocol.h; sourceTree = ""; }; + 34EA821F1D3A3B6900928A06 /* CSFileStreamServiceFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSFileStreamServiceFactory.h; sourceTree = ""; }; + 34EA82201D3A3B6900928A06 /* CSFileStreamServiceFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSFileStreamServiceFactory.m; sourceTree = ""; }; + 34EA82221D3A3C4E00928A06 /* CSFileStreamRTMPService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSFileStreamRTMPService.h; sourceTree = ""; }; + 34EA82231D3A3C4E00928A06 /* CSFileStreamRTMPService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSFileStreamRTMPService.m; sourceTree = ""; }; + 34EA82251D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSFileStreamRTMPServiceViewController.h; sourceTree = ""; }; + 34EA82261D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSFileStreamRTMPServiceViewController.m; sourceTree = ""; }; + 34EA82271D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CSFileStreamRTMPServiceViewController.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -93,6 +104,13 @@ 34AFC2EA19B08CA80007C07B /* FileStreamServiceViewController.h */, 34AFC2EB19B08CA80007C07B /* FileStreamServiceViewController.m */, 34AFC2EC19B08CA80007C07B /* FileStreamServiceViewController.xib */, + 34EA821F1D3A3B6900928A06 /* CSFileStreamServiceFactory.h */, + 34EA82201D3A3B6900928A06 /* CSFileStreamServiceFactory.m */, + 34EA82221D3A3C4E00928A06 /* CSFileStreamRTMPService.h */, + 34EA82231D3A3C4E00928A06 /* CSFileStreamRTMPService.m */, + 34EA82251D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.h */, + 34EA82261D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.m */, + 34EA82271D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.xib */, ); path = CSFileStreamServicePlugin; sourceTree = ""; @@ -171,6 +189,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 34EA82291D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.xib in Resources */, 34AFC2EE19B08CA80007C07B /* FileStreamServiceViewController.xib in Resources */, 34AFC2D919B08C050007C07B /* InfoPlist.strings in Resources */, ); @@ -184,7 +203,10 @@ buildActionMask = 2147483647; files = ( 34AFC2ED19B08CA80007C07B /* FileStreamServiceViewController.m in Sources */, + 34EA82281D3A3FF600928A06 /* CSFileStreamRTMPServiceViewController.m in Sources */, 34AFC2E919B08C810007C07B /* FileStreamService.m in Sources */, + 34EA82241D3A3C4E00928A06 /* CSFileStreamRTMPService.m in Sources */, + 34EA82211D3A3B6900928A06 /* CSFileStreamServiceFactory.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.h b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.h new file mode 100644 index 00000000..3a218707 --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.h @@ -0,0 +1,25 @@ +// +// CSFileStreamRTMPService.h +// CSFileStreamServicePlugin +// +// Created by Zakk on 7/16/16. +// Copyright © 2016 Zakk. All rights reserved. +// + +#import +#import "CSStreamServiceProtocol.h" + +@interface CSFileStreamRTMPService : NSObject + + +@property bool isReady; +@property (strong) NSString *destinationURI; + + +-(NSViewController *)getConfigurationView; +-(NSString *)getServiceDestination; ++(NSString *)label; ++(NSString *)serviceDescription; + + +@end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.m b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.m new file mode 100644 index 00000000..0e3b945f --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPService.m @@ -0,0 +1,80 @@ +// +// CSFileStreamRTMPService.m +// CSFileStreamServicePlugin +// +// Created by Zakk on 7/16/16. +// Copyright © 2016 Zakk. All rights reserved. +// + +#import "CSFileStreamRTMPService.h" +#import "CSFileStreamRTMPServiceViewController.h" + + +@implementation CSFileStreamRTMPService + +-(instancetype) init +{ + if(self = [super init]) + { + self.isReady = YES; + } + return self; +} + + +-(void)encodeWithCoder:(NSCoder *)aCoder +{ + [aCoder encodeObject:self.destinationURI forKey:@"destinationURI"]; +} + + +-(instancetype)initWithCoder:(NSCoder *)aDecoder +{ + if (self = [self init]) + { + self.destinationURI = [aDecoder decodeObjectForKey:@"destinationURI"]; + } + + return self; +} + + +-(NSViewController *)getConfigurationView +{ + + CSFileStreamRTMPServiceViewController *configViewController; + + configViewController = [[CSFileStreamRTMPServiceViewController alloc] initWithNibName:@"CSFileStreamRTMPServiceViewController" bundle:[NSBundle bundleForClass:self.class]]; + configViewController.serviceObj = self; + return configViewController; +} + + + +-(NSString *)getServiceFormat +{ + return @"FLV"; +} + + + +-(NSString *)getServiceDestination +{ + + return self.destinationURI; +} + + + ++(NSString *)label +{ + return @"RTMP"; +} + + ++(NSString *)serviceDescription +{ + return @"RTMP"; +} + +@end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.h b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.h new file mode 100644 index 00000000..9979cd48 --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.h @@ -0,0 +1,18 @@ +// +// CSFileStreamRTMPServiceViewController.h +// CSFileStreamServicePlugin +// +// Created by Zakk on 7/16/16. +// Copyright © 2016 Zakk. All rights reserved. +// + +#import +#import "CSFileStreamRTMPService.h" + +@interface CSFileStreamRTMPServiceViewController : NSViewController + +@property (weak) CSFileStreamRTMPService *serviceObj; +@property (strong) IBOutlet NSObjectController *fileStreamRTMPServiceController; + + +@end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.m b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.m new file mode 100644 index 00000000..80d4654e --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.m @@ -0,0 +1,22 @@ +// +// CSFileStreamRTMPServiceViewController.m +// CSFileStreamServicePlugin +// +// Created by Zakk on 7/16/16. +// Copyright © 2016 Zakk. All rights reserved. +// + +#import "CSFileStreamRTMPServiceViewController.h" + +@interface CSFileStreamRTMPServiceViewController () + +@end + +@implementation CSFileStreamRTMPServiceViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do view setup here. +} + +@end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.xib b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.xib new file mode 100644 index 00000000..db9bb091 --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamRTMPServiceViewController.xib @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.h b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.h new file mode 100644 index 00000000..0b5b9f54 --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.h @@ -0,0 +1,20 @@ +// +// CSFileStreamServiceFactory.h +// CSFileStreamServicePlugin +// +// Created by Zakk on 7/16/16. +// Copyright © 2016 Zakk. All rights reserved. +// + +#import +#import "CSPluginFactoryProtocol.h" +#import "FileStreamService.h" +#import "CSFileStreamRTMPService.h" + + +@interface CSFileStreamServiceFactory : NSObject ++(NSArray *)captureSourceClasses; ++(NSArray *)streamServiceClasses; ++(NSArray *)extraPluginClasses; + +@end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.m b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.m new file mode 100644 index 00000000..9377d20b --- /dev/null +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServiceFactory.m @@ -0,0 +1,29 @@ +// +// CSFileStreamServiceFactory.m +// CSFileStreamServicePlugin +// +// Created by Zakk on 7/16/16. +// Copyright © 2016 Zakk. All rights reserved. +// + +#import "CSFileStreamServiceFactory.h" + + +@implementation CSFileStreamServiceFactory ++(NSArray *)captureSourceClasses +{ + return @[[FileStreamService class], [CSFileStreamRTMPService class]];} + + ++(NSArray *)streamServiceClasses +{ + return nil; +} + ++(NSArray *)extraPluginClasses +{ + return nil; +} + + +@end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServicePlugin-Info.plist b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServicePlugin-Info.plist index bceb9c0e..85ee6a3e 100644 --- a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServicePlugin-Info.plist +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/CSFileStreamServicePlugin-Info.plist @@ -25,6 +25,6 @@ NSHumanReadableCopyright Copyright © 2014 Zakk. All rights reserved. NSPrincipalClass - FileStreamService + CSFileStreamServiceFactory diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamService.m b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamService.m index 181cbde2..a274a7a5 100644 --- a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamService.m +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamService.m @@ -98,13 +98,13 @@ +(NSString *)label { - return @"File/RTMP"; + return @"File"; } +(NSString *)serviceDescription { - return @"File/RTMP"; + return @"File"; } @end diff --git a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamServiceViewController.xib b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamServiceViewController.xib index 964835da..cc9af50c 100644 --- a/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamServiceViewController.xib +++ b/StreamServicePlugins/CSFileStreamServicePlugin/CSFileStreamServicePlugin/FileStreamServiceViewController.xib @@ -1,8 +1,8 @@ - + - + diff --git a/StreamServicePlugins/CSHitboxStreamServicePlugin/CSHitboxStreamServicePlugin/HitboxStreamServiceViewController.xib b/StreamServicePlugins/CSHitboxStreamServicePlugin/CSHitboxStreamServicePlugin/HitboxStreamServiceViewController.xib index 7afdb021..f94d5a0f 100644 --- a/StreamServicePlugins/CSHitboxStreamServicePlugin/CSHitboxStreamServicePlugin/HitboxStreamServiceViewController.xib +++ b/StreamServicePlugins/CSHitboxStreamServicePlugin/CSHitboxStreamServicePlugin/HitboxStreamServiceViewController.xib @@ -1,7 +1,7 @@ - + - + @@ -19,7 +19,6 @@ - @@ -28,7 +27,6 @@ - @@ -37,7 +35,6 @@ - @@ -49,7 +46,6 @@ - @@ -64,7 +60,6 @@ - @@ -80,7 +75,6 @@ - - @@ -129,7 +120,6 @@ - diff --git a/StreamServicePlugins/CSTwitchStreamServicePlugin/CSTwitchStreamServicePlugin.xcodeproj/project.pbxproj b/StreamServicePlugins/CSTwitchStreamServicePlugin/CSTwitchStreamServicePlugin.xcodeproj/project.pbxproj index 678c1bf7..7b8d4fff 100644 --- a/StreamServicePlugins/CSTwitchStreamServicePlugin/CSTwitchStreamServicePlugin.xcodeproj/project.pbxproj +++ b/StreamServicePlugins/CSTwitchStreamServicePlugin/CSTwitchStreamServicePlugin.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 34AFC32019B0A5DC0007C07B /* TwitchStreamService.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AFC31F19B0A5DC0007C07B /* TwitchStreamService.m */; }; 34AFC32419B0A5FD0007C07B /* TwitchStreamServiceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AFC32219B0A5FD0007C07B /* TwitchStreamServiceViewController.m */; }; 34AFC32519B0A5FD0007C07B /* TwitchStreamServiceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34AFC32319B0A5FD0007C07B /* TwitchStreamServiceViewController.xib */; }; + 34EA822B1D3AC49600928A06 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34EA822A1D3AC49600928A06 /* WebKit.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -33,6 +34,7 @@ 34D6580619B343210012E32B /* CSCaptureSourceProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSCaptureSourceProtocol.h; path = PluginHeaders/CSCaptureSourceProtocol.h; sourceTree = ""; }; 34D6580719B343210012E32B /* CSStreamServiceProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSStreamServiceProtocol.h; path = PluginHeaders/CSStreamServiceProtocol.h; sourceTree = ""; }; 34D6580819B343210012E32B /* CSPluginFactoryProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSPluginFactoryProtocol.h; path = PluginHeaders/CSPluginFactoryProtocol.h; sourceTree = ""; }; + 34EA822A1D3AC49600928A06 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -40,6 +42,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 34EA822B1D3AC49600928A06 /* WebKit.framework in Frameworks */, 34AFC30219B0A5800007C07B /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -73,6 +76,7 @@ 34AFC30019B0A5800007C07B /* Frameworks */ = { isa = PBXGroup; children = ( + 34EA822A1D3AC49600928A06 /* WebKit.framework */, 34AFC30119B0A5800007C07B /* Cocoa.framework */, 34AFC30319B0A5800007C07B /* Other Frameworks */, ); diff --git a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.h b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.h index 2fd62ca5..d6e1efcb 100644 --- a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.h +++ b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.h @@ -18,13 +18,16 @@ @property (strong) NSArray *twitchServers; @property (strong) NSString *streamKey; @property (strong) NSString *selectedServer; +@property (strong) NSString *oAuthKey; -(NSViewController *)getConfigurationView; -(NSString *)getServiceDestination; +-(void)fetchTwitchStreamKey; +(NSString *)label; +(NSString *)serviceDescription; + @end diff --git a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.m b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.m index a13f7971..439515ab 100644 --- a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.m +++ b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamService.m @@ -85,6 +85,37 @@ return @"TwitchTV"; } + +-(void)fetchTwitchStreamKey +{ + if (!self.oAuthKey) + { + return; + } + + NSString *apiString = @"https://api.twitch.tv/kraken/channel"; + + NSURL *apiURL = [NSURL URLWithString:apiString]; + + NSMutableURLRequest *apiRequest = [NSMutableURLRequest requestWithURL:apiURL]; + + [apiRequest setValue:[NSString stringWithFormat:@"OAuth %@", self.oAuthKey] forHTTPHeaderField:@"Authorization"]; + + [NSURLConnection sendAsynchronousRequest:apiRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *err) { + + NSError *jsonError; + NSDictionary *channel_response = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonError]; + //Handle error + + + NSString *stream_key = [channel_response objectForKey:@"stream_key"]; + + dispatch_async(dispatch_get_main_queue(), ^{self.streamKey = stream_key; }); + return; + }]; +} + + -(void)loadTwitchIngest { diff --git a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.h b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.h index 93759496..06e4d157 100644 --- a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.h +++ b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.h @@ -9,10 +9,14 @@ #import #import "TwitchStreamService.h" +#import -@interface TwitchStreamServiceViewController : NSViewController +@interface TwitchStreamServiceViewController : NSViewController @property (weak) TwitchStreamService *serviceObj; +@property (strong) NSWindow *authWindow; +@property (strong) WebView *authWebView; +- (IBAction)doTwitchAuth:(id)sender; @end diff --git a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.m b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.m index 4ede11ae..11c13419 100644 --- a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.m +++ b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.m @@ -8,6 +8,7 @@ #import "TwitchStreamServiceViewController.h" + @interface TwitchStreamServiceViewController () @end @@ -23,4 +24,74 @@ return self; } + + +-(NSString *)extractAccessTokenFromURL:(NSURL *)url +{ + NSURLComponents *urlComp = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; + NSString *urlFragment = urlComp.percentEncodedFragment; + + NSURLComponents *fakeComponents = [NSURLComponents componentsWithString:[NSString stringWithFormat:@"http://localhost/blah?%@", urlFragment]]; + + NSArray *queryVars = fakeComponents.queryItems; + + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", @"access_token"]; + NSURLQueryItem *tokenItem = [queryVars filteredArrayUsingPredicate:predicate].firstObject; + + return tokenItem.value; +} + + +- (IBAction)doTwitchAuth:(id)sender +{ + + NSURL *authURL = [NSURL URLWithString:@"https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&force_verify=true&client_id=p2onxyxk17dlngdgtj43kl9gaj2yb2a&redirect_uri=cocoasplit-twitch://cocoasplit.com/oauth/redirect&scope=channel_read"]; + + + NSRect winFrame = NSMakeRect(0, 0, 1000, 1000); + self.authWebView = [[WebView alloc] initWithFrame:winFrame frameName:nil groupName:nil]; + self.authWebView.policyDelegate = self; + + self.authWindow = [[NSWindow alloc] initWithContentRect:winFrame styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask backing:NSBackingStoreBuffered defer:NO]; + + [self.authWindow center]; + [self.authWindow setContentView:self.authWebView]; + [self.authWindow makeKeyAndOrderFront:NSApp]; + [[self.authWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:authURL]]; + +} + + +-(void)closeAuthWindow +{ + self.authWindow = nil; +} + + +-(void)receivedOAuth:(NSString *)oToken +{ + self.serviceObj.oAuthKey = oToken; + [self.serviceObj fetchTwitchStreamKey]; + +} + + +-(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener +{ + NSURL *reqUrl = request.URL; + if (reqUrl) + { + if ([reqUrl.scheme isEqualToString:@"cocoasplit-twitch"]) + { + [listener ignore]; + NSString *accessToken = [self extractAccessTokenFromURL:reqUrl]; + [self receivedOAuth:accessToken]; + [self closeAuthWindow]; + + } + } + + [listener use]; +} + @end diff --git a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.xib b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.xib index 2cbb1753..30db0c85 100644 --- a/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.xib +++ b/StreamServicePlugins/CSTwitchStreamServicePlugin/TwitchStreamServiceViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -13,33 +13,30 @@ - + - - - - + + + - - - - + + + - - - + + - + @@ -56,10 +53,9 @@ - - - - + + + @@ -67,9 +63,18 @@ + - - + @@ -85,7 +90,6 @@ -