Add on-screen connection status warning

This commit is contained in:
Cameron Gutman
2019-07-23 18:43:41 -04:00
parent af16f03703
commit ba4e55aac4
3 changed files with 55 additions and 0 deletions

View File

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

View File

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

View File

@@ -15,6 +15,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <Limelight.h>
@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];