From ba4e55aac4bc121626efae7120eac4add828b8d7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 23 Jul 2019 18:43:41 -0400 Subject: [PATCH] Add on-screen connection status warning --- Limelight/Stream/Connection.h | 1 + Limelight/Stream/Connection.m | 6 +++ .../StreamFrameViewController.m | 48 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Limelight/Stream/Connection.h b/Limelight/Stream/Connection.h index aa6852f..0ba2733 100644 --- a/Limelight/Stream/Connection.h +++ b/Limelight/Stream/Connection.h @@ -18,6 +18,7 @@ - (void) stageFailed:(const char*)stageName withError:(long)errorCode; - (void) launchFailed:(NSString*)message; - (void) rumble:(unsigned short)controllerNumber lowFreqMotor:(unsigned short)lowFreqMotor highFreqMotor:(unsigned short)highFreqMotor; +- (void) connectionStatusUpdate:(int)status; @end diff --git a/Limelight/Stream/Connection.m b/Limelight/Stream/Connection.m index 97abba5..48ea231 100644 --- a/Limelight/Stream/Connection.m +++ b/Limelight/Stream/Connection.m @@ -238,6 +238,11 @@ void ClRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsi [_callbacks rumble:controllerNumber lowFreqMotor:lowFreqMotor highFreqMotor:highFreqMotor]; } +void ClConnectionStatusUpdate(int status) +{ + [_callbacks connectionStatusUpdate:status]; +} + -(void) terminate { // Interrupt any action blocking LiStartConnection(). This is @@ -369,6 +374,7 @@ void ClRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsi _clCallbacks.connectionTerminated = ClConnectionTerminated; _clCallbacks.logMessage = ClLogMessage; _clCallbacks.rumble = ClRumble; + _clCallbacks.connectionStatusUpdate = ClConnectionStatusUpdate; return self; } diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 332b4e5..ed1e3c8 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -15,6 +15,7 @@ #include #include #include +#include @implementation StreamFrameViewController { ControllerSupport *_controllerSupport; @@ -22,6 +23,7 @@ NSTimer *_inactivityTimer; UITapGestureRecognizer *_menuGestureRecognizer; UITapGestureRecognizer *_menuDoubleTapGestureRecognizer; + UITextView *_overlayView; } - (void)viewDidAppear:(BOOL)animated @@ -118,6 +120,31 @@ } } +- (void)updateOverlayText:(NSString*)text { + if (_overlayView == nil) { + _overlayView = [[UITextView alloc] init]; + [_overlayView setEditable:NO]; + [_overlayView setSelectable:NO]; + [_overlayView setScrollEnabled:NO]; + [_overlayView setTextAlignment:NSTextAlignmentCenter]; + [_overlayView setTextColor:[OSColor lightGrayColor]]; + [_overlayView setBackgroundColor:[OSColor blackColor]]; + [_overlayView setFont:[UIFont systemFontOfSize:12]]; + [_overlayView setAlpha:0.5]; + [self.view addSubview:_overlayView]; + } + + if (text != nil) { + [_overlayView setText:text]; + [_overlayView sizeToFit]; + [_overlayView setCenter:CGPointMake(self.view.frame.size.width / 2, _overlayView.frame.size.height / 2)]; + [_overlayView setHidden:NO]; + } + else { + [_overlayView setHidden:YES]; + } +} + - (void) returnToMainFrame { [self.navigationController popToRootViewControllerAnimated:YES]; } @@ -264,6 +291,27 @@ [_controllerSupport rumble:controllerNumber lowFreqMotor:lowFreqMotor highFreqMotor:highFreqMotor]; } +- (void)connectionStatusUpdate:(int)status { + Log(LOG_W, @"Connection status update: %d", status); + + dispatch_async(dispatch_get_main_queue(), ^{ + switch (status) { + case CONN_STATUS_OKAY: + [self updateOverlayText:nil]; + break; + + case CONN_STATUS_POOR: + if (self->_streamConfig.bitRate > 5000) { + [self updateOverlayText:@"Slow connection to PC\nReduce your bitrate"]; + } + else { + [self updateOverlayText:@"Poor connection to PC"]; + } + break; + } + }); +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];