Skip to content
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

Fix waiting for player to be ready #434

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/pr_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:
build:
strategy:
matrix:
xcode_version: [ '15.2' ]
runs-on: macos-14
xcode_version: [ '15.4.0' ]
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Select Xcode ${{ matrix.xcode_version }}
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode_version }} # Check versions: https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md
xcode-version: ${{ matrix.xcode_version }}

- name: Setup Node
uses: actions/setup-node@v4
Expand Down Expand Up @@ -50,10 +50,10 @@ jobs:
pod update

- name: Start iOS simulator
uses: futureware-tech/simulator-action@v3
uses: futureware-tech/simulator-action@v4
with:
model: 'iPhone 14'
os_version: '>=16.0'
model: 'iPhone 15'
os_version: '>=14.0'

- name: Run e2e tests
working-directory: e2e
Expand Down
55 changes: 55 additions & 0 deletions e2e/patches/cavy+4.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/node_modules/cavy/src/Reporter.js b/node_modules/cavy/src/Reporter.js
index 1cdeb38..f7e9e35 100644
--- a/node_modules/cavy/src/Reporter.js
+++ b/node_modules/cavy/src/Reporter.js
@@ -9,7 +9,15 @@ export default class Reporter {
// Internal: Creates a websocket connection to the cavy-cli server.
onStart() {
const url = 'ws://127.0.0.1:8082/';
+ console.debug('Creating websocket');
this.ws = new WebSocket(url);
+ this.ws.onerror = console.error
+ this.ws.onopen = () => {
+ console.debug('Successfully opened websocket');
+ }
+ this.ws.onclose = () => {
+ console.debug('Closing websocket');
+ }
}

// Internal: Send a single test result to cavy-cli over the websocket connection.
@@ -34,7 +42,6 @@ export default class Reporter {
console.log(message);
}
}
-
// Private: Determines whether data can be sent over the websocket.
websocketReady() {
// WebSocket.readyState 1 means the web socket connection is OPEN.
diff --git a/node_modules/cavy/src/Tester.js b/node_modules/cavy/src/Tester.js
index c61e31a..8d222ae 100644
--- a/node_modules/cavy/src/Tester.js
+++ b/node_modules/cavy/src/Tester.js
@@ -57,20 +57,8 @@ export default class Tester extends Component {
key: Math.random()
};
this.testHookStore = props.store;
- // Default to sending a test report to cavy-cli if no custom reporter is
- // supplied.
- if (props.reporter instanceof Function) {
- const message = 'Deprecation warning: support for custom function' +
- 'reporters will soon be deprecated. Cavy supports custom ' +
- 'class based reporters. For more info, see the ' +
- 'documentation here: ' +
- 'https://cavy.app/docs/guides/writing-custom-reporters';
- console.warn(message);
- this.reporter = props.reporter;
- } else {
- reporterClass = props.reporter || Reporter;
- this.reporter = new reporterClass;
- }
+ reporterClass = props.reporter || Reporter;
+ this.reporter = new reporterClass;
}

componentDidMount() {
34 changes: 28 additions & 6 deletions e2e/src/components/TestableTHEOplayerView.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
import { useCavy } from 'cavy';
import { THEOplayer, THEOplayerView, THEOplayerViewProps } from 'react-native-theoplayer';
import React, { useCallback } from 'react';
import { PromiseController } from '../utils/PromiseController';

let playerController = new PromiseController<THEOplayer>();
let testPlayer: THEOplayer | undefined = undefined;

export const getTestPlayer = async (): Promise<THEOplayer> => {
return playerController.promise_;
/**
* Wait until the player is ready.
*
* @param timeout Delay after rejecting the player.
* @param poll Delay before trying again.
*/
export const getTestPlayer = async (timeout = 5000, poll = 200): Promise<THEOplayer> => {
return new Promise((resolve, reject) => {
const start = Date.now();
const checkPlayer = () => {
setTimeout(() => {
if (testPlayer) {
// Player is ready.
resolve(testPlayer);
} else if (Date.now() - start > timeout) {
// Too late.
reject('Player not ready');
} else {
// Wait & try again.
checkPlayer();
}
}, poll);
};
checkPlayer();
});
};

export const TestableTHEOplayerView = (props: THEOplayerViewProps) => {
const generateTestHook = useCavy();
const onPlayerReady = useCallback((player: THEOplayer) => {
playerController.resolve_(player);
testPlayer = player;
props.onPlayerReady?.(player);
}, []);

const onPlayerDestroy = useCallback(() => {
playerController = new PromiseController<THEOplayer>();
testPlayer = undefined;
}, []);

return <THEOplayerView ref={generateTestHook('Scene.THEOplayerView')} {...props} onPlayerReady={onPlayerReady} onPlayerDestroy={onPlayerDestroy} />;
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/tests/Basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import hls from '../res/hls.json';
import mp4 from '../res/mp4.json';
import { expect, preparePlayerWithSource, waitForPlayerEventType, waitForPlayerEventTypes } from '../utils/Actions';

const SEEK_THRESHOLD = 1e-1;
const SEEK_THRESHOLD = 250;

function testBasicPlayout(spec: TestScope, title: string, source: SourceDescription) {
spec.describe(title, function () {
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import Connector from './Connector.spec';
import PresentationMode from './PresentationMode.spec';
import Version from './Version.spec';

export default [Basic, Ads, Connector, PresentationMode, Version];
export default [Version, Basic, Ads, Connector, PresentationMode];
Loading