diff --git a/Limelight/HttpManager.h b/Limelight/HttpManager.h
index c0b680e..efd4547 100644
--- a/Limelight/HttpManager.h
+++ b/Limelight/HttpManager.h
@@ -22,6 +22,7 @@
- (NSURLRequest*) newAppListRequest;
- (NSURLRequest*) newServerInfoRequest;
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid;
+- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId;
- (NSData*) executeRequestSynchronously:(NSURLRequest*)request;
@end
diff --git a/Limelight/HttpManager.m b/Limelight/HttpManager.m
index b7654fb..0a47d98 100644
--- a/Limelight/HttpManager.m
+++ b/Limelight/HttpManager.m
@@ -155,6 +155,11 @@ static const NSString* PORT = @"47984";
return [self createRequestFromString:urlString];
}
+- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId {
+ NSString* urlString = [NSString stringWithFormat:@"%@/resume?uniqueid=%@&rikey=%@&rikeyid=%d", _baseURL, _uniqueId, riKey, riKeyId];
+ return [self createRequestFromString:urlString];
+}
+
- (NSString*) bytesToHex:(NSData*)data {
const unsigned char* bytes = [data bytes];
NSMutableString *hex = [[NSMutableString alloc] init];
diff --git a/Limelight/StreamManager.m b/Limelight/StreamManager.m
index 5506b77..afaec5c 100644
--- a/Limelight/StreamManager.m
+++ b/Limelight/StreamManager.m
@@ -21,6 +21,9 @@
self = [super init];
_config = config;
_renderView = view;
+ _config.riKey = [Utils randomBytes:16];
+ _config.riKeyId = arc4random();
+ _config.bitRate = 10000;
return self;
}
@@ -30,23 +33,43 @@
NSString* uniqueId = [CryptoManager getUniqueID];
NSData* cert = [CryptoManager readCertFromFile];
- HttpManager* hMan = [[HttpManager alloc] initWithHost:_config.host uniqueId:uniqueId deviceName:@"roth" cert:cert];
- NSData* riKey = [Utils randomBytes:16];
- int riKeyId = arc4random();
+ HttpManager* hMan = [[HttpManager alloc] initWithHost:_config.host
+ uniqueId:uniqueId
+ deviceName:@"roth"
+ cert:cert];
- NSData* launchResp = [hMan executeRequestSynchronously:[hMan newLaunchRequest:@"67339056" width:_config.width height:_config.height refreshRate:_config.frameRate rikey:[Utils bytesToHex:riKey] rikeyid:riKeyId]];
- [HttpManager getStringFromXML:launchResp tag:@"gamesession"];
+ NSData* serverInfoResp = [hMan executeRequestSynchronously:[hMan newServerInfoRequest]];
+ if (![[HttpManager getStringFromXML:serverInfoResp tag:@"currentgame"] isEqualToString:@"0"]) {
+ // App already running, resume it
+ [self resumeApp:hMan];
+ } else {
+ // Start app
+ [self launchApp:hMan];
+ }
VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:_renderView];
-
- _config.bitRate = 10000;
- _config.riKey = riKey;
- _config.riKeyId = riKeyId;
-
Connection* conn = [[Connection alloc] initWithConfig:_config renderer:renderer];
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
[opQueue addOperation:conn];
}
+- (void) launchApp:(HttpManager*)hMan {
+ NSData* launchResp = [hMan executeRequestSynchronously:
+ [hMan newLaunchRequest:@"67339056"
+ width:_config.width
+ height:_config.height
+ refreshRate:_config.frameRate
+ rikey:[Utils bytesToHex:_config.riKey]
+ rikeyid:_config.riKeyId]];
+ [HttpManager getStringFromXML:launchResp tag:@"gamesession"];
+}
+
+- (void) resumeApp:(HttpManager*)hMan {
+ NSData* resumeResp = [hMan executeRequestSynchronously:
+ [hMan newResumeRequestWithRiKey:[Utils bytesToHex:_config.riKey]
+ riKeyId:_config.riKeyId]];
+ [HttpManager getStringFromXML:resumeResp tag:@"gamesession"];
+}
+
@end
diff --git a/MainFrame-iPhone.storyboard b/MainFrame-iPhone.storyboard
index f25c60d..ebb9dc2 100644
--- a/MainFrame-iPhone.storyboard
+++ b/MainFrame-iPhone.storyboard
@@ -102,6 +102,9 @@
+
+
+