-
-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent destruction of session, so that an app restart can reconnect (chromecast). #1469
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public final class Chromecast implements IChromecast { | |
/** | ||
* Object to control the media. | ||
*/ | ||
private ChromecastSession media; | ||
private ChromecastSession chromecastSession; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the variable name to be more "descriptive" as to what this variable actually was. For the longest time I got a little confused and thought this was the actual media, not the session. |
||
/** | ||
* Holds the reference to the current client initiated scan. | ||
*/ | ||
|
@@ -53,7 +53,7 @@ public final class Chromecast implements IChromecast { | |
|
||
public void initializePlugin(Activity activity) { | ||
try { | ||
this.connection = new ChromecastConnection(activity, new ChromecastConnection.Listener() { | ||
connection = new ChromecastConnection(activity, new ChromecastConnection.Listener() { | ||
@Override | ||
public void onSessionRejoin(JSONObject jsonSession) { | ||
sendEvent("SESSION_LISTENER", new JSONArray().put(jsonSession)); | ||
|
@@ -93,7 +93,7 @@ public void onMessageReceived(CastDevice device, String namespace, String messag | |
sendEvent("RECEIVER_MESSAGE", new JSONArray().put(namespace).put(message)); | ||
} | ||
}); | ||
this.media = connection.getChromecastSession(); | ||
chromecastSession = connection.getChromecastSession(); | ||
} catch (RuntimeException e) { | ||
noChromecastError = "Could not initialize chromecast: " + e.getMessage(); | ||
e.printStackTrace(); | ||
|
@@ -153,13 +153,7 @@ public boolean execute(String action, JSONArray args, JavascriptCallback cbConte | |
} else { | ||
return false; | ||
} | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} catch (IllegalArgumentException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} catch (InvocationTargetException e) { | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
|
@@ -173,7 +167,7 @@ public boolean execute(String action, JSONArray args, JavascriptCallback cbConte | |
* @return true for cordova | ||
*/ | ||
public boolean setup(JavascriptCallback javascriptCallback) { | ||
this.eventCallback = javascriptCallback; | ||
eventCallback = javascriptCallback; | ||
// Ensure any existing scan is stopped | ||
if (connection == null) return false; | ||
connection.stopRouteScan(clientScan, () -> { | ||
|
@@ -275,7 +269,7 @@ public boolean setReceiverVolumeLevel(Integer newLevel, JavascriptCallback javas | |
* @return true for cordova | ||
*/ | ||
public boolean setReceiverVolumeLevel(Double newLevel, JavascriptCallback javascriptCallback) { | ||
this.media.setVolume(newLevel, javascriptCallback); | ||
chromecastSession.setVolume(newLevel, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -287,7 +281,7 @@ public boolean setReceiverVolumeLevel(Double newLevel, JavascriptCallback javasc | |
* @return true for cordova | ||
*/ | ||
public boolean setReceiverMuted(Boolean muted, JavascriptCallback javascriptCallback) { | ||
this.media.setMute(muted, javascriptCallback); | ||
chromecastSession.setMute(muted, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -300,7 +294,7 @@ public boolean setReceiverMuted(Boolean muted, JavascriptCallback javascriptCall | |
* @return true for cordova | ||
*/ | ||
public boolean sendMessage(String namespace, String message, final JavascriptCallback javascriptCallback) { | ||
this.media.sendMessage(namespace, message, javascriptCallback); | ||
chromecastSession.sendMessage(namespace, message, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -312,7 +306,7 @@ public boolean sendMessage(String namespace, String message, final JavascriptCal | |
* @return true for cordova | ||
*/ | ||
public boolean addMessageListener(String namespace, JavascriptCallback javascriptCallback) { | ||
this.media.addMessageListener(namespace); | ||
chromecastSession.addMessageListener(namespace); | ||
javascriptCallback.success(); | ||
return true; | ||
} | ||
|
@@ -337,7 +331,7 @@ public boolean loadMedia(String contentId, JSONObject customData, String content | |
} | ||
|
||
private boolean loadMedia(String contentId, JSONObject customData, String contentType, Integer duration, String streamType, Boolean autoPlay, Double currentTime, JSONObject metadata, JSONObject textTrackStyle, final JavascriptCallback javascriptCallback) { | ||
this.media.loadMedia(contentId, customData, contentType, duration, streamType, autoPlay, currentTime, metadata, textTrackStyle, javascriptCallback); | ||
chromecastSession.loadMedia(contentId, customData, contentType, duration, streamType, autoPlay, currentTime, metadata, textTrackStyle, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -348,7 +342,7 @@ private boolean loadMedia(String contentId, JSONObject customData, String conten | |
* @return true for cordova | ||
*/ | ||
public boolean mediaPlay(JavascriptCallback javascriptCallback) { | ||
media.mediaPlay(javascriptCallback); | ||
chromecastSession.mediaPlay(javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -359,7 +353,7 @@ public boolean mediaPlay(JavascriptCallback javascriptCallback) { | |
* @return true for cordova | ||
*/ | ||
public boolean mediaPause(JavascriptCallback javascriptCallback) { | ||
media.mediaPause(javascriptCallback); | ||
chromecastSession.mediaPause(javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -372,7 +366,7 @@ public boolean mediaPause(JavascriptCallback javascriptCallback) { | |
* @return true for cordova | ||
*/ | ||
public boolean mediaSeek(Integer seekTime, String resumeState, JavascriptCallback javascriptCallback) { | ||
media.mediaSeek(seekTime.longValue() * 1000, resumeState, javascriptCallback); | ||
chromecastSession.mediaSeek(seekTime.longValue() * 1000, resumeState, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -398,7 +392,7 @@ public boolean setMediaVolume(Integer level, Boolean muted, JavascriptCallback j | |
* @return true for cordova | ||
*/ | ||
public boolean setMediaVolume(Double level, Boolean muted, JavascriptCallback javascriptCallback) { | ||
media.mediaSetVolume(level, muted, javascriptCallback); | ||
chromecastSession.mediaSetVolume(level, muted, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -409,7 +403,7 @@ public boolean setMediaVolume(Double level, Boolean muted, JavascriptCallback ja | |
* @return true for cordova | ||
*/ | ||
public boolean mediaStop(JavascriptCallback javascriptCallback) { | ||
media.mediaStop(javascriptCallback); | ||
chromecastSession.mediaStop(javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -432,7 +426,7 @@ public boolean mediaEditTracksInfo(JSONArray activeTrackIds, JSONObject textTrac | |
Timber.tag(TAG).e("Wrong format in activeTrackIds"); | ||
} | ||
|
||
this.media.mediaEditTracksInfo(trackIds, textTrackStyle, javascriptCallback); | ||
chromecastSession.mediaEditTracksInfo(trackIds, textTrackStyle, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -444,7 +438,7 @@ public boolean mediaEditTracksInfo(JSONArray activeTrackIds, JSONObject textTrac | |
* @return true for cordova | ||
*/ | ||
public boolean queueLoad(JSONObject queueLoadRequest, final JavascriptCallback javascriptCallback) { | ||
this.media.queueLoad(queueLoadRequest, javascriptCallback); | ||
chromecastSession.queueLoad(queueLoadRequest, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -456,7 +450,7 @@ public boolean queueLoad(JSONObject queueLoadRequest, final JavascriptCallback j | |
* @return true for cordova | ||
*/ | ||
public boolean queueJumpToItem(Integer itemId, final JavascriptCallback javascriptCallback) { | ||
this.media.queueJumpToItem(itemId, javascriptCallback); | ||
chromecastSession.queueJumpToItem(itemId, javascriptCallback); | ||
return true; | ||
} | ||
|
||
|
@@ -578,11 +572,13 @@ protected void callback(boolean keep, @Nullable String err, @Nullable String res | |
}; | ||
|
||
stopRouteScan(callback); | ||
sessionStop(callback); | ||
if (media != null) { | ||
media.destroy(); | ||
// Default behavior for youtube-like apps is to leave the session running if the app is closed. | ||
// This, at least, allows the user to close the app and re-open without stopping media when trying to fix things. | ||
sessionLeave(callback); | ||
if (chromecastSession != null) { | ||
chromecastSession.destroy(); | ||
} | ||
media = null; | ||
chromecastSession = null; | ||
if (connection != null) { | ||
connection.destroy(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
# | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=512m | ||
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=1G | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a beefier debugging machine, but we can reset this down if folks want. This helped speed up my build times quite a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be interesting for you. I'd prefer to keep the lower defaults in this repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely I'll remove these changes when I can get back on my computer. |
||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app"s APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added due to the linter/editor complaining it should not have been left out.