mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-23 04:33:05 +00:00
Properly stop the stream when exiting or switching apps
This commit is contained in:
parent
c36fb14b15
commit
34d871403c
@ -19,6 +19,7 @@
|
||||
@interface Connection : NSOperation <NSStreamDelegate>
|
||||
|
||||
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id<ConTermCallback>)callback;
|
||||
-(void) terminate;
|
||||
-(void) main;
|
||||
|
||||
@end
|
||||
|
@ -182,8 +182,8 @@ void ClConnectionStarted(void)
|
||||
void ClConnectionTerminated(long errorCode)
|
||||
{
|
||||
NSLog(@"ConnectionTerminated: %ld", errorCode);
|
||||
|
||||
[_callback connectionTerminated];
|
||||
NSLog(@"Tried calling callback");
|
||||
}
|
||||
|
||||
void ClDisplayMessage(char* message)
|
||||
@ -196,6 +196,16 @@ void ClDisplayTransientMessage(char* message)
|
||||
NSLog(@"DisplayTransientMessage: %s", message);
|
||||
}
|
||||
|
||||
-(void) terminate
|
||||
{
|
||||
// We dispatch this async to get out because this can be invoked
|
||||
// on a thread inside common and we don't want to deadlock
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// This is safe to call even before LiStartConnection
|
||||
LiStopConnection();
|
||||
});
|
||||
}
|
||||
|
||||
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id<ConTermCallback>)callback
|
||||
{
|
||||
self = [super init];
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
@implementation StreamFrameViewController {
|
||||
ControllerSupport *_controllerSupport;
|
||||
StreamManager *_streamMan;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
@ -28,18 +29,29 @@
|
||||
|
||||
_controllerSupport = [[ControllerSupport alloc] init];
|
||||
|
||||
StreamManager* streamMan = [[StreamManager alloc] initWithConfig:[MainFrameViewController getStreamConfiguration] renderView:self.view connectionTerminatedCallback:self];
|
||||
_streamMan = [[StreamManager alloc] initWithConfig:[MainFrameViewController getStreamConfiguration] renderView:self.view connectionTerminatedCallback:self];
|
||||
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
|
||||
[opQueue addOperation:streamMan];
|
||||
[opQueue addOperation:_streamMan];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillResignActive:)
|
||||
name:UIApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification {
|
||||
[_streamMan stopStream];
|
||||
[self performSegueWithIdentifier:@"returnToMainFrame" sender:self];
|
||||
}
|
||||
|
||||
- (void)connectionTerminated {
|
||||
NSLog(@"StreamFrame - Connection Terminated");
|
||||
UIAlertController* conTermAlert = [UIAlertController alertControllerWithTitle:@"Connection Terminated" message:@"The connection terminated unexpectedly" preferredStyle:UIAlertControllerStyleAlert];
|
||||
[conTermAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
|
||||
[self performSegueWithIdentifier:@"returnToMainFrame" sender:self];
|
||||
}]];
|
||||
[self presentViewController:conTermAlert animated:YES completion:nil];
|
||||
|
||||
[_streamMan stopStream];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
|
@ -13,4 +13,6 @@
|
||||
@interface StreamManager : NSOperation
|
||||
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionTerminatedCallback:(id<ConTermCallback>)callback;
|
||||
- (void) stopStream;
|
||||
|
||||
@end
|
||||
|
@ -15,6 +15,7 @@
|
||||
StreamConfiguration* _config;
|
||||
UIView* _renderView;
|
||||
id<ConTermCallback> _callback;
|
||||
Connection* _connection;
|
||||
}
|
||||
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionTerminatedCallback:(id<ConTermCallback>)callback {
|
||||
@ -49,9 +50,14 @@
|
||||
}
|
||||
|
||||
VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:_renderView];
|
||||
Connection* conn = [[Connection alloc] initWithConfig:_config renderer:renderer connectionTerminatedCallback:_callback];
|
||||
_connection = [[Connection alloc] initWithConfig:_config renderer:renderer connectionTerminatedCallback:_callback];
|
||||
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
|
||||
[opQueue addOperation:conn];
|
||||
[opQueue addOperation:_connection];
|
||||
}
|
||||
|
||||
- (void) stopStream
|
||||
{
|
||||
[_connection terminate];
|
||||
}
|
||||
|
||||
- (void) launchApp:(HttpManager*)hMan {
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 25faaa9e6bd04ed35bb94d66c38f6229c5a1c30a
|
||||
Subproject commit 88d8c8ede77915f980f38d07728233bfb19a328b
|
Loading…
x
Reference in New Issue
Block a user