Skip to content

Commit

Permalink
Merge pull request #431 from THEOplayer/feature/sdk_versions
Browse files Browse the repository at this point in the history
Feature/sdk versions
  • Loading branch information
wvanhaevre authored Nov 5, 2024
2 parents f5fe505 + b3e90cd commit 827519f
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ _site/
Gemfile.lock
vendor
.bundle
src/manifest.json
e2e/cavy_results.md
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed an issue on Android where on some Android SDK versions controlling playback with the notification buttons would not work.
- Fixed an issue on Web and Android where a text track with attribute `DEFAULT` was not set as the player's `selectedTextTrack` property.

### Added

- Added `sdkVersions` to react-native-theoplayer, which contains the current RN SDK version and the version of the underlying native THEOplayer SDK.

## [8.3.0] - 24-09-30

### Added
Expand Down
7 changes: 7 additions & 0 deletions android/src/main/java/com/theoplayer/player/PlayerModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.theoplayer.android.api.player.RenderingTarget
import com.theoplayer.android.api.player.track.mediatrack.MediaTrack
import com.theoplayer.android.api.player.track.mediatrack.quality.VideoQuality
import com.theoplayer.android.api.player.track.texttrack.TextTrackMode
import com.theoplayer.android.api.THEOplayerGlobal
import com.theoplayer.audio.BackgroundAudioConfigAdapter
import com.theoplayer.presentation.PipConfigAdapter
import com.theoplayer.track.TextTrackStyleAdapter
Expand All @@ -25,6 +26,12 @@ class PlayerModule(context: ReactApplicationContext) : ReactContextBaseJavaModul
return TAG
}

// The native version string of the Android THEOplayer SDK.
@ReactMethod
fun version(promise: Promise) {
promise.resolve(THEOplayerGlobal.getVersion())
}

@ReactMethod
fun setABRConfig(tag: Int, config: ReadableMap?) {
viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
Expand Down
13 changes: 13 additions & 0 deletions e2e/src/tests/Version.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TestScope } from 'cavy';
import { sdkVersions } from 'react-native-theoplayer';
import { expect } from '../utils/Actions';

export default function (spec: TestScope) {
spec.describe('Query SDK version info', function () {
spec.it('returns correct React Native and native SDK versions.', async function () {
const versions = await sdkVersions();
expect(versions.rn.length).toBeTruthy();
expect(versions.native?.length).toBeTruthy();
});
});
}
3 changes: 2 additions & 1 deletion e2e/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import Ads from './Ads.spec';
import Basic from './Basic.spec';
import Connector from './Connector.spec';
import PresentationMode from './PresentationMode.spec';
import Version from './Version.spec';

export default [Basic, Ads, Connector, PresentationMode];
export default [Basic, Ads, Connector, PresentationMode, Version];
8 changes: 6 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
TimeLabel,
UiContainer,
} from '@theoplayer/react-native-ui';
import { PlayerConfiguration, PlayerEventType, THEOplayer, THEOplayerView } from 'react-native-theoplayer';
import { PlayerConfiguration, PlayerEventType, THEOplayer, THEOplayerView, sdkVersions } from 'react-native-theoplayer';

import { Platform, SafeAreaView, StyleSheet, View, ViewStyle } from 'react-native';
import { getStatusBarHeight } from 'react-native-status-bar-height';
Expand Down Expand Up @@ -78,11 +78,15 @@ export default function App() {
player.addEventListener(PlayerEventType.SEEKING, console.log);
player.addEventListener(PlayerEventType.SEEKED, console.log);
player.addEventListener(PlayerEventType.ENDED, console.log);

sdkVersions().then((versions) => console.log(`[theoplayer] ${JSON.stringify(versions, null, 4)}`));

player.source = SOURCES[0].source;

player.backgroundAudioConfiguration = { enabled: true };
player.pipConfiguration = { startsAutomatically: true };
console.log('THEOplayer is ready:', player.version);

console.log('THEOplayer is ready');
};

const needsBorder = Platform.OS === 'ios';
Expand Down
3 changes: 3 additions & 0 deletions ios/THEOplayerRCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ @interface RCT_EXTERN_MODULE(THEOplayerRCTViewManager, RCTViewManager)
// ----------------------------------------------------------------------------
@interface RCT_EXTERN_REMAP_MODULE(THEORCTPlayerModule, THEOplayerRCTPlayerAPI, NSObject)

RCT_EXTERN_METHOD(version:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(setPaused:(nonnull NSNumber *)node
paused:(BOOL)paused)

Expand Down
6 changes: 6 additions & 0 deletions ios/THEOplayerRCTPlayerAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
static func requiresMainQueueSetup() -> Bool {
return false
}

@objc(version:rejecter:)
func version(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
let versionString = THEOplayer.version
resolve(versionString)
}

@objc(setPaused:paused:)
func setPaused(_ node: NSNumber, paused: Bool) -> Void {
Expand Down
6 changes: 6 additions & 0 deletions manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const manifest = {
version: process.env.npm_package_version,
buildDate: new Date().toISOString(),
};

console.log(JSON.stringify(manifest));
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"prettier:fix": "prettier --write \"(src|example|e2e)/**/*.{js,jsx,ts,tsx}\"",
"lint": "eslint \"**/*.{ts,tsx}\"",
"lint:fix": "npm run lint -- --fix",
"prepare": "bob build && husky",
"manifest": "node manifest.js > src/manifest.json",
"prepare": "npm run manifest && bob build && husky",
"pods": "cd example && pod-install --quiet",
"docs": "typedoc --treatWarningsAsErrors"
},
Expand Down
1 change: 1 addition & 0 deletions src/api/barrel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './THEOplayerView';
export * from './playback/barrel';
export * from './player/barrel';
export * from './presentation/barrel';
export * from './version/barrel';
2 changes: 2 additions & 0 deletions src/api/player/THEOplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ export interface THEOplayer extends EventDispatcher<PlayerEventMap> {

/**
* The player version.
*
* @deprecated use {@link sdkVersions} instead.
*/
readonly version: PlayerVersion;

Expand Down
1 change: 1 addition & 0 deletions src/api/version/barrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SdkVersions';
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { THEOplayerView } from './internal/THEOplayerView';
export { ContentProtectionRegistry } from './internal/drm/ContentProtectionRegistry';
export { MediaCache } from './internal/cache/MediaCache';
export { PlaybackSettings } from './internal/playback/PlaybackSettings';
export { sdkVersions } from './internal/version/Version';
12 changes: 12 additions & 0 deletions src/internal/version/Version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NativeModules } from 'react-native';
import type { SdkVersions } from 'react-native-theoplayer';
import * as manifest from '../../manifest.json';

export const sdkVersions = async (): Promise<SdkVersions> => {
const rnVersionString = manifest.version ?? '';
const nativeVersionString = await NativeModules.THEORCTPlayerModule.version();
return {
rn: rnVersionString,
native: nativeVersionString,
};
};
11 changes: 11 additions & 0 deletions src/internal/version/Version.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SdkVersions } from 'react-native-theoplayer';
import { version as nativeVersionString } from 'theoplayer';
import manifest from '../../manifest.json';

export const sdkVersions = async (): Promise<SdkVersions> => {
const rnVersionString = manifest.version ?? '';
return {
rn: rnVersionString,
native: nativeVersionString,
};
};

0 comments on commit 827519f

Please sign in to comment.