Skip to content

Commit

Permalink
Issue jellyfin-archive#50 Issue jellyfin-archive#36 Converted the exi…
Browse files Browse the repository at this point in the history
…sting auto tests to mocha and misc improvements/fixes.

Fixed some bugs:
    - typo in ChromecastUtilities "CANCELED"
    - session building, in particulate the media array was not being built correctly

Improvements:
    - Improved many of the tests to be more specific and encourage following desktop chrome behavior more closely
    - Update the readme with more accurate information/documentation/and info about Mocha tests
    - Improved the utils functions (callOrder and waitForAllCalls)
    - Added pre-checks to match chrome behavior.  (Checks for existing session and valid sessionId)
    - followed the _update pattern completely in chrome.cast
  • Loading branch information
Lindsay-Needs-Sleep committed Oct 1, 2019
1 parent 6408db0 commit f16b27e
Show file tree
Hide file tree
Showing 17 changed files with 20,143 additions and 1,010 deletions.
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Thanks!

- [ ] I've updated the documentation as necessary
- [ ] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct [keyword to close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/))
- [ ] I've run `npm run test` and no errors were found (run `npm style` to auto-fix errors it can)
- [ ] I've run the `test-framework` tests for Android (See Readme)
- [ ] I've run `npm test` and no errors were found (run `npm style` to auto-fix errors it can)
- [ ] I've run the tests (See Readme)
- [ ] I added automated test coverage as appropriate for this change
56 changes: 33 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ cordova plugin add https://github.com/jellyfin/cordova-plugin-chromecast.git

# Usage

This project attempts to implement the [official Google Cast API for Chrome](https://developers.google.com/cast/docs/reference/chrome/) within the Cordova webview.
This project attempts to implement the [official Google Cast API for Chrome](https://developers.google.com/cast/docs/reference/chrome#chrome.cast) within the Cordova webview.
This means that you should be able to write almost identical code in cordova as you would if you were developing for desktop Chrome.

We have not implemented every function in the [API](https://developers.google.com/cast/docs/reference/chrome/) but most of the core functions are there. If you find a function is missing we welcome [pull requests](#contributing)! Alternatively, you can file an [issue](https://github.com/jellyfin/cordova-plugin-chromecast/issues), please include a code sample of the expected functionality if possible!
We have not implemented every function in the [API](https://developers.google.com/cast/docs/reference/chrome#chrome.cast) but most of the core functions are there. If you find a function is missing we welcome [pull requests](#contributing)! Alternatively, you can file an [issue](https://github.com/jellyfin/cordova-plugin-chromecast/issues), please include a code sample of the expected functionality if possible!

The only significant difference between the [cast API](https://developers.google.com/cast/docs/reference/chrome/) and this plugin is the initialization.
The only significant difference between the [cast API](https://developers.google.com/cast/docs/reference/chrome#chrome.cast) and this plugin is the initialization.

In **Chrome desktop** you would do:
```js
Expand All @@ -33,7 +33,7 @@ document.addEventListener("deviceready", function () {
```

## Specific to this plugin
We have added some additional methods beyond the [Chromecast API]((https://developers.google.com/cast/docs/reference/chrome/)).
We have added some additional methods beyond the [Chromecast API]((https://developers.google.com/cast/docs/reference/chrome#chrome.cast)).
They can all be found in the `chrome.cast.cordova` object.

To make your own **custom route selector** use this:
Expand Down Expand Up @@ -70,35 +70,45 @@ isNearbyDevice {boolean} - Is it a device only accessible via guest mode?
```


## Formatting
# Plugin Development

* Run `npm run style` (from the plugin directory)
* If you get `Error: Cannot find module '<project root>\node_modules\eslint\bin\eslint'`
* Run `npm install`
* If it finds any formatting errors you can try and automatically fix them with:
* `node node_modules/eslint/bin/eslint <file-path> --fix`
* Otherwise, please manually fix the error before committing
## Setup

Follow these direction to set up for plugin development:

* You will need an existing cordova project or [create a new cordova project](https://cordova.apache.org/#getstarted).
* With **admin permission** run: `cordova plugin add --link <relative path to the plugin's root dir>`

### About the `--link` flag
The `--link` flag allows you to modify the native code (java/swift/obj-c) directly in the relative platform folder if desired.
* This means you can work directly from Android Studio/Xcode!
* Note: Be careful about adding and deleting files. These changes will be exclusive to the platform folder and will not be transferred back to your plugin folder.
* Note: The link only works for native files. Other files such as js/css/html/etc must **not** be modified in the platform folder, these changes will be lost.
* To update the js/css/html/etc files you must run:
* `cordova plugin remove <plugin-name>`
* With **admin permission**: `cordova plugin add --link <relative path to the plugin's root dir>`

## Testing

**1)**
### Code Format

Run `npm test` to ensure your code fits the styling. It will also pick some errors.
Run `npm test` to ensure your code fits the styling. It will also find some errors.

**2)**
* If errors are found, you can try running `npm run style`, this will attempt to automatically fix the errors.

This plugin has [cordova-plugin-test-framework](https://github.com/apache/cordova-plugin-test-framework) tests.
### Tests

To run these tests you can follow [these instructions](https://github.com/miloproductionsinc/cordova-testing).
How to run the tests:
* With **admin permission** run `cordova plugin add --link <relative path to the plugin's root dir>/tests`
* Change `config.xml`'s content tag to `<content src="plugins/cordova-plugin-chromecast-tests/www/tests.html" />`
* You must a valid chromecast on your network to run the tests.
* Run the app, let auto tests do its thing, and then follow the directions for manual tests.

NOTE: You must run these tests from a project with the package name `com.miloproductionsinc.plugin_tests` otherwise `SPEC_00310` will fail. (It uses a custom receiver which are only allowed receive from one package name.)

* You can temporarily rename the project you are testing from:
* config.xml > `<widget id="com.miloproductionsinc.plugin_tests"`
* Or clone this project https://github.com/miloproductionsinc/cordova-testing
[Why we chose a non-standard test framework](https://github.com/jellyfin/cordova-plugin-chromecast/issues/50)


## Contributing

* Make sure all tests pass
* Preferably, write a test for your contribution if applicable (for a bug fix, new feature, etc)
* Make sure all tests pass ([Code Format](#code-format) and [Tests](#tests))
* Write a test for your contribution if applicable (for a bug fix, new feature, etc)
* Update documentation as necessary
15 changes: 12 additions & 3 deletions src/android/ChromecastUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private ChromecastUtilities() {
static String getMediaIdleReason(MediaStatus mediaStatus) {
switch (mediaStatus.getIdleReason()) {
case MediaStatus.IDLE_REASON_CANCELED:
return "CANCELED";
return "CANCELLED";
case MediaStatus.IDLE_REASON_ERROR:
return "ERROR";
case MediaStatus.IDLE_REASON_FINISHED:
Expand Down Expand Up @@ -215,7 +215,7 @@ static JSONObject createSessionObject(CastSession session) {
out.put("appId", session.getApplicationMetadata().getApplicationId());
out.put("appImages", createAppImagesObject(session));
out.put("displayName", session.getApplicationMetadata().getName());
out.put("media", createMediaObject(session));
out.put("media", createMediaArray(session));
out.put("receiver", createReceiverObject(session));
out.put("sessionId", session.getSessionId());

Expand Down Expand Up @@ -262,6 +262,15 @@ private static JSONObject createReceiverObject(CastSession session) {
return out;
}

static JSONArray createMediaArray(CastSession session) {
JSONArray out = new JSONArray();
JSONObject mediaInfoObj = createMediaObject(session);
if (mediaInfoObj != null) {
out.put(mediaInfoObj);
}
return out;
}

static JSONObject createMediaObject(CastSession session) {
JSONObject out = new JSONObject();

Expand Down Expand Up @@ -304,9 +313,9 @@ static JSONObject createMediaObject(CastSession session) {
}
out.put("activeTrackIds", activeTracks);
}

} catch (JSONException e) {
} catch (NullPointerException e) {
return null;
}

return out;
Expand Down
Loading

0 comments on commit f16b27e

Please sign in to comment.