Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble-iphoneos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Krautz <mikkel@krautz.dk>2013-11-23 15:12:02 +0400
committerMikkel Krautz <mikkel@krautz.dk>2013-11-23 15:12:02 +0400
commitccf9ba87db194da848c2d3ada3b62e91443edc3b (patch)
tree27fb25fdf4b7a93b40b2768a627903a709e5fd2f
parent5ff9591002d99c81983ba248268ba11b864bc2f0 (diff)
MUServerViewController: force PTT to turn off when the app is backgrounded.
This change implements a mechanism in MUServerViewController that will turn off forceTransmit when the app is sent to the background. It also ensures that the table view is redrawn (such that the user's talk state is correctly reflected) before the app is backgrounded. This ensures that when the user returns to the app, there will not be split second where he can see himself shown as speaking in the user list, potentially causing a lot of confusion. Fixes #72.
-rw-r--r--Source/Classes/MUServerViewController.m51
1 files changed, 49 insertions, 2 deletions
diff --git a/Source/Classes/MUServerViewController.m b/Source/Classes/MUServerViewController.m
index a8d4ba2..28ba89e 100644
--- a/Source/Classes/MUServerViewController.m
+++ b/Source/Classes/MUServerViewController.m
@@ -128,6 +128,8 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repositionTalkButton) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
[self repositionTalkButton];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
}
}
@@ -137,9 +139,9 @@
if (_talkButton) {
[_talkButton removeFromSuperview];
_talkButton = nil;
-
- [[NSNotificationCenter defaultCenter] removeObserver:self];
}
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSInteger) indexForUser:(MKUser *)user {
@@ -283,6 +285,39 @@
else if (talkState == MKTalkStateShouting)
talkImageName = @"talking_alt";
+ // This check is here to correctly remove a user's talk state when backgrounding the app.
+ //
+ // For example, if the user of the app is holding his finger on the Push-to-Talk button
+ // and decides to background Mumble while he is transmitting (via either the home- or
+ // sleep button).
+ //
+ // This scenario brings two issues along with it:
+ //
+ // 1. We have to cut off Push-to-Talk when the app gets backgrounded - we get no TouchUpInside event
+ // from the UIButton, so we wouldn't regularly stop Push-to-Talk in this scenario.
+ //
+ // 2. Even if we set MKAudio's forceTransmit to NO, there exists a delay in the audio subsystem
+ // between setting the forceTransmit flag to NO before that change is propagated to MKServerModel
+ // delegates.
+ //
+ // The first problem is solved by registering a notification observer for when the app enters the
+ // background. This is handled by the appDidEnterBackground: method of this class.
+ //
+ // This notification observer will set the forceTransmit flag to NO, but will also force-reload
+ // the view controller's table view, causing us to enter this method soon before we're really backgrounded.
+ //
+ // That's fine, but because of problem #2, the user's talk state will most likely not be updated by the time
+ // tableView:cellForRowAtIndexPath: is called by the table view.
+ //
+ // To solve this, we query the audio subsystem directly for the answer to whether the current user
+ // should be treated as holding down Push-to-Talk, and therefore be listed with an active talk state
+ // in the table view.
+ if (user == connectedUser && [[MKAudio sharedAudio] transmitType] == MKTransmitTypeToggle) {
+ if (![[MKAudio sharedAudio] forceTransmit]) {
+ talkImageName = @"talking_off";
+ }
+ }
+
cell.imageView.image = [UIImage imageNamed:talkImageName];
cell.accessoryView = [MUUserStateAcessoryView viewForUser:user];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
@@ -574,5 +609,17 @@
}
}
+#pragma mark - Background notification
+
+- (void) appDidEnterBackground:(NSNotification *)notification {
+ // Force Push-to-Talk to stop when the app is backgrounded.
+ [[MKAudio sharedAudio] setForceTransmit:NO];
+
+ // Reload the table view to re-render the talk state for the user
+ // as not talking if they were holding down their Push-to-Talk buttons
+ // at the moment the app was sent to the background.
+ [[self tableView] reloadData];
+}
+
@end