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

Feat/hls player resolution state #1248

Merged
merged 30 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e1839a3
fix(prebuilt): :bug: showing indicator on browser recording initialis…
stanwolverine Oct 12, 2023
439f50e
feat(prebuilt): :sparkles: added lower remote peer hand ui option in …
stanwolverine Oct 12, 2023
d7bdc3e
Merge branch 'feat/lower-remote-hand-prebuilt' into feat/error-dialog…
stanwolverine Oct 12, 2023
61c2753
initial changes
stanwolverine Oct 12, 2023
42fc289
Merge branch 'develop' into feat/error-dialogue-ui
stanwolverine Oct 13, 2023
9a7c850
refactoring and using `useStartRecording` hook
stanwolverine Oct 13, 2023
84aad78
Merge branch 'develop' into feat/error-dialogue-ui
stanwolverine Oct 18, 2023
57ddedc
refactor(sdk): :recycle: removed `emitRequiredKeysError` calls on ios…
stanwolverine Oct 18, 2023
54c964d
refactor(sdk): :recycle: removed `emitRequiredKeysError` calls on and…
stanwolverine Oct 18, 2023
2378fa0
refactor(sdk): :recycle: removed `ON_ERROR` emit code from HMSRNSDK c…
stanwolverine Oct 20, 2023
0b355c4
feat(prebuilt): added notification for exception and api rejections
stanwolverine Oct 20, 2023
6281e66
refactor(sdk): :recycle: removed `ON_ERROR` emit code from `join` method
stanwolverine Oct 20, 2023
2f936a4
add notification on ON_ERROR event when user is inside meeting
stanwolverine Oct 20, 2023
e38cbfb
removed temp code
stanwolverine Oct 20, 2023
a8c9b40
released sample app version 2.3.88 (339) ⚛️
stanwolverine Oct 20, 2023
ff6a0ba
refactor(prebuilt): :recycle: extracted LeaveRoom and EndRoom modals …
stanwolverine Oct 20, 2023
0831736
feat(prebuilt): :sparkles: added "Leave" button on `HMSExceptionNotif…
stanwolverine Oct 20, 2023
c9b98c7
released sample app version 2.3.89 (340) ⚛️
stanwolverine Oct 20, 2023
a5dfdba
Merge branch 'develop' into feat/error-dialogue-ui
stanwolverine Oct 24, 2023
9b9a9b4
feat(prebuilt): :sparkles: added option to handle android back button…
stanwolverine Oct 24, 2023
cd6ea86
feat(example-app): :sparkles: usage of `handleBackButton` prop in `HM…
stanwolverine Oct 24, 2023
886d5be
feat(prebuilt): :sparkles: added option to handle auto enter pip mode
stanwolverine Oct 25, 2023
3a08d36
feat(example-app): :sparkles: usage of `autoEnterPipMode` prop in `HM…
stanwolverine Oct 25, 2023
7f59bb4
Merge branch 'feat/error-dialogue-ui' into feat/added-autoenterpipmod…
stanwolverine Oct 25, 2023
641259e
Merge branch 'develop' into feat/added-autoenterpipmode-config-option
stanwolverine Oct 25, 2023
46bbc71
released sample app version 2.3.92 (343) ⚛️
stanwolverine Oct 25, 2023
28cadb1
Merge branch 'develop' into feat/handle-back-button-press
stanwolverine Oct 25, 2023
1495d61
Merge branch 'feat/handle-back-button-press' into feat/added-autoente…
stanwolverine Oct 25, 2023
64180a4
feat(sdk): :sparkles: added "hls player resolution" state in zustand …
stanwolverine Oct 26, 2023
d4ea1cf
Merge branch 'develop' into feat/hls-player-resolution-state
stanwolverine Oct 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ class HMSHLSPlayer(context: ReactContext) : FrameLayout(context) {
}

val data = Arguments.createMap()
data.putString("state", "onVideoSizeChanged")
data.putDouble("aspectRatio", (width / height))
sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_STATE_CHANGE_EVENT, data)
data.putDouble("width", width)
data.putDouble("height", height)
sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_RESOLUTION_CHANGE_EVENT, data)
}
}
},
Expand Down Expand Up @@ -285,6 +285,7 @@ object HMSHLSPlayerConstants {
const val ON_PLAYBACK_CUE_EVENT = "ON_PLAYBACK_CUE_EVENT"
const val ON_PLAYBACK_FAILURE_EVENT = "ON_PLAYBACK_FAILURE_EVENT"
const val ON_PLAYBACK_STATE_CHANGE_EVENT = "ON_PLAYBACK_STATE_CHANGE_EVENT"
const val ON_PLAYBACK_RESOLUTION_CHANGE_EVENT = "ON_PLAYBACK_RESOLUTION_CHANGE_EVENT"

// HLS Playback Stats Events
const val HMS_HLS_STATS_EVENT = "hmsHlsStatsEvent"
Expand Down
31 changes: 20 additions & 11 deletions packages/react-native-hms/ios/HMSHLSPlayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,31 @@ class HMSHLSPlayer: UIView {
sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_FAILURE_EVENT, data)
}

fileprivate func onPlaybackStateChanged(state: HMSHLSPlaybackState? = nil, videoSizeChanged: Bool = false, aspectRatio: Double? = nil) {
fileprivate func onPlaybackStateChanged(state: HMSHLSPlaybackState) {
guard onHmsHlsPlaybackEvent != nil else { return }

var data = [String: Any]()

data["state"] = videoSizeChanged ? "onVideoSizeChanged" : state?.description
data["state"] = state.description

if let aspectRatio = aspectRatio {
data["aspectRatio"] = aspectRatio
sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_STATE_CHANGE_EVENT, data)
}

fileprivate func onResolutionChanged(videoSize: CGSize) {
if videoSize.width >= videoSize.height {
hmsHLSPlayerViewController?.videoGravity = .resizeAspect
} else {
hmsHLSPlayerViewController?.videoGravity = .resizeAspectFill
}

sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_STATE_CHANGE_EVENT, data)
guard onHmsHlsPlaybackEvent != nil else { return }

var data = [String: Any]()

data["width"] = videoSize.width
data["height"] = videoSize.height

sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_RESOLUTION_CHANGE_EVENT, data)
}
}

Expand All @@ -343,12 +356,7 @@ class HLSPlaybackEventController: HMSHLSPlayerDelegate {
}

func onResolutionChanged(videoSize: CGSize) {
if videoSize.width >= videoSize.height {
hmsHlsPlayerDelegate?.hmsHLSPlayerViewController?.videoGravity = .resizeAspect
} else {
hmsHlsPlayerDelegate?.hmsHLSPlayerViewController?.videoGravity = .resizeAspectFill
}
hmsHlsPlayerDelegate?.onPlaybackStateChanged(videoSizeChanged: true, aspectRatio: videoSize.width/videoSize.height)
hmsHlsPlayerDelegate?.onResolutionChanged(videoSize: videoSize)
}
}

Expand All @@ -357,6 +365,7 @@ enum HMSHLSPlayerConstants {
static let ON_PLAYBACK_CUE_EVENT = "ON_PLAYBACK_CUE_EVENT"
static let ON_PLAYBACK_FAILURE_EVENT = "ON_PLAYBACK_FAILURE_EVENT"
static let ON_PLAYBACK_STATE_CHANGE_EVENT = "ON_PLAYBACK_STATE_CHANGE_EVENT"
static let ON_PLAYBACK_RESOLUTION_CHANGE_EVENT = "ON_PLAYBACK_RESOLUTION_CHANGE_EVENT"

// HLS Playback Stats Events
static let ON_STATS_EVENT_UPDATE = "ON_STATS_EVENT_UPDATE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
setHMSHLSPlayerCue,
setHMSHLSPlayerPlaybackError,
setHMSHLSPlayerPlaybackState,
setHMSHLSPlayerResolution,
setHMSHLSPlayerStats,
setHMSHLSPlayerStatsError,
} from './hooks';
Expand Down Expand Up @@ -198,13 +199,18 @@ const _HMSHLSPlayer: React.ForwardRefRenderFunction<
event === HMSHLSPlayerPlaybackEventTypes.ON_PLAYBACK_FAILURE_EVENT
) {
setHMSHLSPlayerPlaybackError(data.error);
} else if (
event === HMSHLSPlayerPlaybackEventTypes.ON_PLAYBACK_RESOLUTION_CHANGE_EVENT
) {
setHMSHLSPlayerResolution({...data});

const aspectRatio = data.width / data.height;

if (typeof aspectRatio === 'number' && !isNaN(aspectRatio)) {
setAspectRatio(aspectRatio);
}
} else {
setHMSHLSPlayerPlaybackState(data.state);
if (data.state === 'onVideoSizeChanged') {
if (typeof data.aspectRatio === 'number') {
setAspectRatio(data.aspectRatio);
}
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const useHMSHLSPlayerPlaybackState = () => {
return useHMSStore((state) => state.playbackState);
};

export const useHMSHLSPlayerResolution = () => {
return useHMSStore((state) => state.resolution);
};

export const useHMSHLSPlayerStats = () => {
return useHMSHLSPlayerStatsStore(
(state) => ({
Expand Down Expand Up @@ -89,6 +93,9 @@ export const useHMSHLSPlayerCue = (
export const setHMSHLSPlayerPlaybackState =
useHMSStore.getState().setPlaybackState;

export const setHMSHLSPlayerResolution =
useHMSStore.getState().setResolution;

export const setHMSHLSPlayerCue = useHMSStore.getState().setCue;

export const setHMSHLSPlayerPlaybackError =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export {
useHMSHLSPlayerStats,
useHMSHLSPlayerStat,
useHMSHLSPlayerStatsError,
useHMSHLSPlayerResolution,
} from './hooks';
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ export const createHMSHLSPlayerPlaybackSlice: StateCreator<

error: undefined,
setPlaybackError: (error: HMSHLSPlayerPlaybackError) => set({ error }),

resolution: undefined,
setResolution: (resolution) => set({ resolution }),
});
5 changes: 5 additions & 0 deletions packages/react-native-hms/src/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
HMSHLSPlayerPlaybackState,
HMSHLSPlayerPlaybackCueEventData,
HMSHLSPlayerPlaybackFailureEventData,
HMSHLSPlayerPlaybackResolutionChangeEventData,
HMSHLSPlayerStatsErrorEventData,
HMSHLSPlayerStatsUpdateEventData,
} from '../types';
Expand All @@ -25,12 +26,16 @@ export type HMSHLSPlayerPlaybackError =
| HMSHLSPlayerPlaybackFailureEventData['error']
| undefined;

export type HMSHLSPlayerResolution = HMSHLSPlayerPlaybackResolutionChangeEventData | undefined;

export interface HMSHLSPlayerPlaybackSlice {
cue: HMSHLSPlayerCue;
playbackState: HMSHLSPlayerPlaybackState;
resolution: HMSHLSPlayerResolution;
error: HMSHLSPlayerPlaybackError;
setCue(cue: HMSHLSPlayerPlaybackCue): void;
setPlaybackState(playbackState: HMSHLSPlayerPlaybackState): void;
setResolution(resolution: HMSHLSPlayerResolution): void;
setPlaybackError(error: HMSHLSPlayerPlaybackError): void;
}

Expand Down
16 changes: 13 additions & 3 deletions packages/react-native-hms/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum HMSHLSPlayerPlaybackEventTypes {
ON_PLAYBACK_CUE_EVENT = 'ON_PLAYBACK_CUE_EVENT',
ON_PLAYBACK_FAILURE_EVENT = 'ON_PLAYBACK_FAILURE_EVENT',
ON_PLAYBACK_STATE_CHANGE_EVENT = 'ON_PLAYBACK_STATE_CHANGE_EVENT',
ON_PLAYBACK_RESOLUTION_CHANGE_EVENT = 'ON_PLAYBACK_RESOLUTION_CHANGE_EVENT',
}

export type HMSHLSPlayerPlaybackCueEventData = {
Expand All @@ -34,12 +35,15 @@ export enum HMSHLSPlayerPlaybackState {
PLAYING = 'playing',
STOPPED = 'stopped',
UNKNOWN = 'unknown',
onVideoSizeChanged = 'onVideoSizeChanged',
}

export type HMSHLSPlayerPlaybackStateChangeEventData = {
state: HMSHLSPlayerPlaybackState;
aspectRatio: number | undefined;
};

export type HMSHLSPlayerPlaybackResolutionChangeEventData = {
width: number;
height: number;
};

type HMSHLSPlayerPlaybackCueEvent = HMSHLSPlayerEvent<
Expand All @@ -57,10 +61,16 @@ type HMSHLSPlayerPlaybackStateChangeEvent = HMSHLSPlayerEvent<
HMSHLSPlayerPlaybackStateChangeEventData
>;

type HMSHLSPLayerPlaybackResolutionChangeEvent = HMSHLSPlayerEvent<
HMSHLSPlayerPlaybackEventTypes.ON_PLAYBACK_RESOLUTION_CHANGE_EVENT,
HMSHLSPlayerPlaybackResolutionChangeEventData
>;

export type HMSHLSPlayerPlaybackEvent =
| HMSHLSPlayerPlaybackCueEvent
| HMSHLSPlayerPlaybackFailureEvent
| HMSHLSPlayerPlaybackStateChangeEvent;
| HMSHLSPlayerPlaybackStateChangeEvent
| HMSHLSPLayerPlaybackResolutionChangeEvent;

// #endregion HMS HLSPlayer Playback Events

Expand Down