implemented resuming session

This commit is contained in:
Diego Waxemberg
2014-10-20 21:26:08 -04:00
parent 4c646e36c7
commit 84316166eb
4 changed files with 42 additions and 10 deletions

View File

@@ -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