Skip to content

Commit

Permalink
(ios) improve error handling for loadMediaCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Lindsay-Needs-Sleep committed Jan 25, 2020
1 parent 35cd482 commit 2cb3b33
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/ios/MLPChromecastSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ -(MLPCastRequestDelegate*)createLoadMediaRequestDelegate:(CDVInvokedUrlCommand*)
};
return [self createRequestDelegate:command success:^{
} failure:^(GCKError * error) {
loadMediaCallback(error.description);
loadMediaCallback = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} abortion:^(GCKRequestAbortReason abortReason) {
if (abortReason == GCKRequestAbortReasonReplaced) {
loadMediaCallback(@"aborted loadMedia/queueLoad request reason: GCKRequestAbortReasonReplaced");
} else if (abortReason == GCKRequestAbortReasonCancelled) {
loadMediaCallback(@"aborted loadMedia/queueLoad request reason: GCKRequestAbortReasonCancelled");
}
loadMediaCallback = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsNSInteger:abortReason];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

Expand Down Expand Up @@ -406,7 +408,9 @@ - (void)remoteMediaClient:(GCKRemoteMediaClient *)client didReceiveQueueItemIDs:
if (!loadMediaCallback) {
// So set the callback to trigger the MEDIA_LOAD event
loadMediaCallback = ^(NSString* error) {
if (!error) {
if (error) {
NSLog(@"%@%@", @"Chromecast Error: ", error);
} else {
[self.sessionListener onMediaLoaded:[MLPCastUtilities createMediaObject:currentSession]];
}
};
Expand All @@ -418,8 +422,14 @@ - (void)remoteMediaClient:(GCKRemoteMediaClient *)client didReceiveQueueItemIDs:
loadMediaCallback(nil);
loadMediaCallback = nil;
} failure:^(GCKError * error) {
loadMediaCallback([GCKError enumDescriptionForCode:error.code]);
loadMediaCallback = nil;
} abortion:^(GCKRequestAbortReason abortReason) {
if (abortReason == GCKRequestAbortReasonReplaced) {
loadMediaCallback(@"aborted loadMedia/queueLoad fetch request reason: GCKRequestAbortReasonReplaced");
} else if (abortReason == GCKRequestAbortReasonCancelled) {
loadMediaCallback(@"aborted loadMedia/queueLoad fetch request reason: GCKRequestAbortReasonCancelled");
}
loadMediaCallback = nil;
}];
}
Expand Down

0 comments on commit 2cb3b33

Please sign in to comment.