jwplayer / jwplayer-react-native

MIT License
32 stars 9 forks source link

[BUG] Playlist change event object emitted as string instead of PlaylistItem type #92

Open cheynewallace opened 1 month ago

cheynewallace commented 1 month ago

Describe the bug When handling playlist item change events the event.nativeEvent.playlistItem should be of PlaylistItem interface, but instead it is coming through as a string which means you cannot access it's properties such as title, description etc without JSON parsing.

To Reproduce

const handleOnPlaylistItemChange = (event: BaseEvent<PlaylistItemEventProps>) => {
    console.log("Playlist Item Type", typeof event.nativeEvent?.playlistItem);
};

<JWPlayer ref={playerRef} onPlaylistItem={handleOnPlaylistItemChange}/>

In the above example, I get the output: Playlist Item Type string

Expected behavior It should be an object of type PlaylistItem according to: https://github.com/jwplayer/jwplayer-react-native/blob/master/index.d.ts#L500

Device(s) affected All devices

Additional context As a hacky workaround work around

let eventPlaylistItem = null;
if (typeof event.nativeEvent?.playlistItem === "string") {
    eventPlaylistItem = JSON.parse(event.nativeEvent?.playlistItem);
} else {
    eventPlaylistItem = event.nativeEvent?.playlistItem;
}