Skip to content

Commit

Permalink
object to json fix, license mark required, remove unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chaimPaneth committed Sep 2, 2021
1 parent 427ed3e commit 02ff790
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 54 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ declare module "react-native-jw-media-player" {
};
}
interface Config {
license: string,
advertising?: Advertising;
adClient?: string;
autostart?: boolean;
Expand Down
57 changes: 8 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const JWPlayerAdClients = {
export default class JWPlayer extends Component {
static propTypes = {
config: PropTypes.shape({
license: PropTypes.string,
license: PropTypes.string.isRequired,
backgroundAudioEnabled: PropTypes.bool,
pipEnabled: PropTypes.bool,
viewOnly: PropTypes.bool,
Expand Down Expand Up @@ -227,26 +227,10 @@ export default class JWPlayer extends Component {
}

setControls(show) {
if (RNJWPlayerManager)
if (RNJWPlayerManager && Platform.OS === "android")
RNJWPlayerManager.setControls(this.getRNJWPlayerBridgeHandle(), show);
}

loadPlaylistItem(playlistItem) {
if (RNJWPlayerManager)
RNJWPlayerManager.loadPlaylistItem(
this.getRNJWPlayerBridgeHandle(),
playlistItem
);
}

loadPlaylist(playlist) {
if (RNJWPlayerManager)
RNJWPlayerManager.loadPlaylist(
this.getRNJWPlayerBridgeHandle(),
playlist
);
}

seekTo(time) {
if (RNJWPlayerManager)
RNJWPlayerManager.seekTo(this.getRNJWPlayerBridgeHandle(), time);
Expand Down Expand Up @@ -279,43 +263,18 @@ export default class JWPlayer extends Component {
RNJWPlayerManager.togglePIP(this.getRNJWPlayerBridgeHandle());
}

showAirPlayButton(x, y, width = 44, hight = 44, autoHide = true) {
if (RNJWPlayerManager && Platform.OS === 'ios')
RNJWPlayerManager.showAirPlayButton(this.getRNJWPlayerBridgeHandle(), x, y, width, hight, autoHide);
}

hideAirPlayButton() {
if (RNJWPlayerManager && Platform.OS === 'ios')
RNJWPlayerManager.hideAirPlayButton(this.getRNJWPlayerBridgeHandle());
}

showCastButton(x, y, width = 24, hight = 24, autoHide = true, customButton = false) {
if (RNJWPlayerManager) {
if (Platform.OS === 'ios') {
RNJWPlayerManager.showCastButton(this.getRNJWPlayerBridgeHandle(), x, y, width, hight, autoHide, customButton);
} else {
RNJWPlayerManager.showCastButton(this.getRNJWPlayerBridgeHandle(), x, y, width, hight, autoHide);
}
}
}

hideCastButton() {
if (RNJWPlayerManager)
RNJWPlayerManager.hideCastButton(this.getRNJWPlayerBridgeHandle());
}

setUpCastController() {
if (RNJWPlayerManager)
if (RNJWPlayerManager && Platform.OS === "ios")
RNJWPlayerManager.setUpCastController(this.getRNJWPlayerBridgeHandle());
}

presentCastDialog() {
if (RNJWPlayerManager)
if (RNJWPlayerManager && Platform.OS === "ios")
RNJWPlayerManager.presentCastDialog(this.getRNJWPlayerBridgeHandle());
}

async connectedDevice() {
if (RNJWPlayerManager) {
if (RNJWPlayerManager && Platform.OS === "ios") {
try {
var connectedDevice = await RNJWPlayerManager.connectedDevice(
this.getRNJWPlayerBridgeHandle()
Expand All @@ -329,7 +288,7 @@ export default class JWPlayer extends Component {
}

async availableDevices() {
if (RNJWPlayerManager) {
if (RNJWPlayerManager && Platform.OS === "ios") {
try {
var availableDevices = await RNJWPlayerManager.availableDevices(
this.getRNJWPlayerBridgeHandle()
Expand All @@ -343,7 +302,7 @@ export default class JWPlayer extends Component {
}

async castState() {
if (RNJWPlayerManager) {
if (RNJWPlayerManager && Platform.OS === "ios") {
try {
var castState = await RNJWPlayerManager.castState(
this.getRNJWPlayerBridgeHandle()
Expand Down Expand Up @@ -401,7 +360,7 @@ export default class JWPlayer extends Component {
file !== thisConfig.file ||
image !== thisConfig.image ||
desc !== thisConfig.desc ||
title !== thisConfigs.title ||
title !== thisConfig.title ||
mediaId !== thisConfig.mediaId ||
autostart !== thisConfig.autostart ||
controls !== thisConfig.controls ||
Expand Down
41 changes: 37 additions & 4 deletions ios/RNJWPlayer/RNJWPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ -(void)setStyling:styling

id progress = timeSlider[@"progress"];
if (progress != nil && (progress != (id)[NSNull null])) {
[timeSliderStyleBuilder maximumTrackColor:[self colorWithHexString:progress]];
[timeSliderStyleBuilder minimumTrackColor:[self colorWithHexString:progress]];
}

id rail = timeSlider[@"rail"];
if (rail != nil && (rail != (id)[NSNull null])) {
[timeSliderStyleBuilder minimumTrackColor:[self colorWithHexString:rail]];
[timeSliderStyleBuilder maximumTrackColor:[self colorWithHexString:rail]];
}

id thumb = timeSlider[@"thumb"];
Expand Down Expand Up @@ -1059,8 +1059,22 @@ - (void)jwplayerContentDidComplete:(id<JWPlayer>)player
- (void)jwplayer:(id<JWPlayer>)player didLoadPlaylistItem:(JWPlayerItem *)item at:(NSUInteger)index
{
if (self.onPlaylistItem) {
NSDictionary* itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
item.mediaId, @"mediaId",
item.posterImage, @"image",
item.title, @"title",
item.description, @"desc",
item.vmapURL, @"adVmap",
item.recommendations, @"recommendations",
item.startTime, @"startTime",
item.autostart, @"autostart",
item.videoSources, @"sources",
item.adSchedule, @"adSchedule",
item.mediaTracks, @"tracks",
nil];

NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:item options:NSJSONWritingPrettyPrinted error: &error];
NSData *data = [NSJSONSerialization dataWithJSONObject:itemDict options:NSJSONWritingPrettyPrinted error: &error];

self.onPlaylistItem(@{@"playlistItem": [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding], @"index": [NSNumber numberWithInteger:index]});
}
Expand All @@ -1069,8 +1083,27 @@ - (void)jwplayer:(id<JWPlayer>)player didLoadPlaylistItem:(JWPlayerItem *)item a
- (void)jwplayer:(id<JWPlayer>)player didLoadPlaylist:(NSArray<JWPlayerItem *> *)playlist
{
if (self.onPlaylist) {
NSMutableArray* playlistArray = [[NSMutableArray alloc] init];

for (JWPlayerItem* item in playlist) {
NSDictionary* itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
item.mediaId, @"mediaId",
item.posterImage, @"image",
item.title, @"title",
item.description, @"desc",
item.vmapURL, @"adVmap",
item.recommendations, @"recommendations",
item.startTime, @"startTime",
item.autostart, @"autostart",
item.videoSources, @"sources",
item.adSchedule, @"adSchedule",
item.mediaTracks, @"tracks",
nil];
[playlistArray addObject:itemDict];
}

NSError *error;
NSData* data = [NSJSONSerialization dataWithJSONObject:playlist options:NSJSONWritingPrettyPrinted error: &error];
NSData* data = [NSJSONSerialization dataWithJSONObject:playlistArray options:NSJSONWritingPrettyPrinted error: &error];

self.onPlaylist(@{@"playlist": [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-jw-media-player",
"version": "0.2.0-beta.1",
"version": "0.2.0-beta.2",
"description": "React-native Android/iOS plugin for JWPlayer SDK (https://www.jwplayer.com/)",
"main": "index.js",
"types": "./index.d.ts",
Expand Down

0 comments on commit 02ff790

Please sign in to comment.