@tivio/sdk-react 3.0.0-alpha4 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ //! moment.js
2
+
3
+ //! moment.js locale configuration
@@ -3,6 +3,9 @@
3
3
  * nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4
4
  */
5
5
  import { InternalConfig, RemoteBundleState, TivioBundle } from 'src/types/bundle.types';
6
+ /**
7
+ * @throws if fetch fails
8
+ */
6
9
  declare const fetchBundle: (secret: string, conf: InternalConfig) => Promise<string>;
7
10
  /**
8
11
  * Fetch & load CommonJS remote module.
@@ -1,2 +1,7 @@
1
+ import { TivioBundle } from '../types/bundle.types';
1
2
  import type { RemoteBundleState } from './bundleLoader';
3
+ export declare let tivioBundle: TivioBundle | null;
4
+ /**
5
+ * rejects when bundle is not available
6
+ */
2
7
  export declare const bundlePromise: Promise<RemoteBundleState>;
@@ -19,5 +19,6 @@ import * as reactSpring from 'react-spring';
19
19
  import * as reactVirtualized from 'react-virtualized';
20
20
  import * as styledComponents from 'styled-components';
21
21
  import * as yup from 'yup';
22
- export declare type SharedDependency = typeof react | typeof reactDom | typeof mobx | typeof styledComponents | typeof firebase | typeof materialUiCore | typeof materialUiIcons | typeof formik | typeof i18Next | typeof reactI18Next | typeof reactRouterDom | typeof reactVirtualized | typeof reactSpring | typeof yup | typeof mobxReact | null;
22
+ import * as moment from 'moment';
23
+ export declare type SharedDependency = typeof react | typeof reactDom | typeof mobx | typeof styledComponents | typeof firebase | typeof materialUiCore | typeof materialUiIcons | typeof formik | typeof i18Next | typeof reactI18Next | typeof reactRouterDom | typeof reactVirtualized | typeof reactSpring | typeof yup | typeof moment | typeof mobxReact | null;
23
24
  export declare const resolveShared: (name: string) => SharedDependency;
@@ -0,0 +1 @@
1
+ export declare const loadBundleFromDist: () => import("../../types/bundle.types").TivioBundle;
@@ -0,0 +1 @@
1
+ export declare const loadBundleFromDist: () => void;
@@ -0,0 +1,2 @@
1
+ import type { UserPayload } from '../types/bundle.types';
2
+ export declare const setUser: (userId: string, payload: UserPayload) => Promise<void>;
@@ -3,11 +3,11 @@
3
3
  * nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4
4
  */
5
5
  /**
6
- * The settings can be called before Tivio is loaded.
7
- * So this package is responsible for settings from the beginning of the life cycle.
6
+ * @deprecated TIV-994 in favour of setUser from libs/sdk-react/src/services/login.ts
8
7
  */
9
- import { InternalConfig } from '../types/bundle.types';
10
- export declare const createSettings: (conf: InternalConfig) => {
11
- onSetUser: (handler: (userId: string, userPayload: unknown) => void) => void;
12
- setUser: (userId: string, userPayload: unknown) => void;
8
+ export declare const createSettings: () => {
9
+ /**
10
+ * @deprecated TIV-994 in favour of setUser from libs/sdk-react/src/services/login.ts
11
+ */
12
+ setUser: (userId: string, userPayload: unknown) => Promise<void>;
13
13
  };
@@ -1,4 +1,4 @@
1
- import { Currency, SubscribeToTaggedVideos, UseCancelSubscription } from '@tivio/common';
1
+ import { Currency, QerkoCancellationInfo, SubscribeToTaggedVideos, UseCancelSubscription } from '@tivio/common';
2
2
  import { ComponentType } from 'react';
3
3
  import { Logger } from '../services/logger';
4
4
  import { FetchPackage } from '../services/packageLoader';
@@ -8,8 +8,10 @@ import type { AdSource, PlayerWrapper } from './customPlayer.types';
8
8
  import type { Monetization, Purchase, QerkoPaymentInfo, Screen, SubscribeToItemsInRow, SubscribeToRowsInScreen, SubscribeToScreen, TvAppProps, User, UseSearch, Video } from '@tivio/common';
9
9
  import type React from 'react';
10
10
  declare type Settings = {
11
- onSetUser: (handler: (userId: string, userPayload: unknown) => void) => void;
12
- setUser: (userId: string, userPayload: unknown) => void;
11
+ /**
12
+ * @deprecated TIV-994 in favour of setUser from libs/sdk-react/src/services/login.ts
13
+ */
14
+ setUser: (userId: string, userPayload: unknown) => Promise<void>;
13
15
  };
14
16
  interface PlayerCapability {
15
17
  codec: 'h264' | 'h265';
@@ -17,6 +19,9 @@ interface PlayerCapability {
17
19
  protocol: 'dash' | 'hls';
18
20
  }
19
21
  declare type InternalConfig = {
22
+ /**
23
+ * @private URL of remote code bundle to be fetched directly (without using resolver)
24
+ */
20
25
  bundleUrlOverride?: string;
21
26
  currency: Currency;
22
27
  deviceCapabilities: PlayerCapability[];
@@ -31,6 +36,9 @@ declare type InternalConfig = {
31
36
  LoaderComponent?: ComponentType;
32
37
  logger?: Logger | null;
33
38
  pubSub: PubSub;
39
+ /**
40
+ * @private URL of resolver. Resolver is a script used to fetch remove code bundle
41
+ */
34
42
  resolverUrl: string;
35
43
  sdkVersion: string;
36
44
  secret: string | null;
@@ -46,6 +54,11 @@ interface PubSub {
46
54
  }
47
55
  declare type Config = Pick<InternalConfig, 'bundleUrlOverride' | 'currency' | 'disableUnmounting' | 'enable' | 'enableSentry' | 'ErrorComponent' | 'language' | 'LoaderComponent' | 'logger' | 'secret' | 'verbose'> & {
48
56
  deviceCapabilities: PlayerCapability[] | 'auto';
57
+ /**
58
+ * @private
59
+ * Run HTML, CSS and JS feature support check
60
+ */
61
+ runFeatureSupportCheck?: boolean;
49
62
  };
50
63
  declare type TivioSubscriptions = {
51
64
  subscribeToUser: (cb: (error: string | null, user: User | null) => void) => void;
@@ -107,6 +120,10 @@ declare type TivioSubscriptions = {
107
120
  subscribeToItemsInRow: SubscribeToItemsInRow;
108
121
  subscribeToRowsInScreen: SubscribeToRowsInScreen;
109
122
  subscribeToTaggedVideos: SubscribeToTaggedVideos;
123
+ registerOverlayCallbacks: (callbacks: {
124
+ onShow: () => void;
125
+ onHide: () => void;
126
+ }) => void;
110
127
  };
111
128
  declare type TivioGetters = {
112
129
  isTivioLoaded: (cb: (isLoaded: boolean) => void) => boolean;
@@ -171,6 +188,7 @@ declare type TivioComponents = {
171
188
  Markers: React.ReactNode;
172
189
  PlayerDataContext: React.ReactNode;
173
190
  Provider: React.ComponentType<RemoteProviderProps>;
191
+ Recommendation: React.ReactNode;
174
192
  SkipButtonWeb: React.ReactNode;
175
193
  VideoAdBanner: React.ReactNode;
176
194
  WebPlayer: React.ComponentType<WebPlayerProps>;
@@ -188,12 +206,38 @@ declare type TivioComponents = {
188
206
  }>;
189
207
  TvApp: React.ComponentType<TvAppProps>;
190
208
  };
209
+ declare type AdSegment = {
210
+ id: string;
211
+ /**
212
+ * @deprecated alias to secondsToEnd * 1000
213
+ */
214
+ remainingMs: number;
215
+ secondsToEnd: number;
216
+ secondsToSkippable: number | null;
217
+ canSeek: boolean;
218
+ /**
219
+ * true if is skippable and skip countdown has passed
220
+ */
221
+ canSkip: boolean;
222
+ /**
223
+ * true ad if is skippable after some skipDelayMs (if it is skippable, skipDelayMs is defined)
224
+ */
225
+ isSkippable: boolean;
226
+ skip: () => any;
227
+ };
191
228
  declare type TivioHooks = {
192
229
  useAd: () => [(AdSource | null)];
230
+ useAdSegment: () => AdSegment | null;
193
231
  useCancelSubscription: UseCancelSubscription;
194
232
  useSearch: UseSearch;
195
233
  useVoucher: (voucherId: string) => any;
234
+ useLastVideoByWidgetId: (widgetId: string) => Video | null;
235
+ useWatchWithoutAdsOffer: () => {
236
+ canPurchaseWatchWithoutAds: boolean;
237
+ showPurchaseDialog: () => void;
238
+ };
196
239
  };
240
+ export declare type UserPayload = Record<string, any>;
197
241
  declare type TivioBundle = {
198
242
  components: TivioComponents;
199
243
  getters: TivioGetters;
@@ -206,15 +250,19 @@ declare type TivioBundle = {
206
250
  purchaseSubscriptionWithQerko: (monetizationId: string, voucher?: {
207
251
  expirationDate: Date;
208
252
  }) => Promise<QerkoPaymentInfo>;
253
+ cancelSubscriptionWithQerko: (subscriptionId: string) => Promise<QerkoCancellationInfo>;
209
254
  setLanguage: (language: Language) => void;
210
- setUser: (userId: string, userPayload?: unknown) => void;
255
+ setUser: (userId: string, userPayload: UserPayload | null) => Promise<void>;
211
256
  sources: TivioSources;
212
257
  subscriptions: TivioSubscriptions;
213
258
  };
259
+ declare type TivioBundleFile = {
260
+ Tivio: TivioBundle;
261
+ };
214
262
  declare type RemoteBundleState = {
215
263
  config: InternalConfig;
216
264
  error: string | null;
217
265
  settings: Settings;
218
266
  state: 'loading' | 'error' | 'ready';
219
267
  } & Nullable<TivioBundle>;
220
- export type { RemoteBundleState, Config, Settings, InternalConfig, TivioBundle, TivioHooks, TivioComponents, TivioAuth, TivioGetters, TivioSubscriptions, Events, PubSub, PlayerCapability, Currency, };
268
+ export type { RemoteBundleState, Config, Settings, InternalConfig, TivioBundle, TivioBundleFile, TivioHooks, TivioComponents, TivioAuth, TivioGetters, TivioSubscriptions, Events, PubSub, PlayerCapability, Currency, };
@@ -1,38 +1,171 @@
1
1
  import { Empty } from './common';
2
- export interface BasicSource {
2
+ export declare type ChannelSource = {
3
+ new (uri: string, originalOptions: Record<string, any>, channelName: string, programName: string, programDescription: string, from: Date, to: Date): ChannelSource;
3
4
  description: string;
4
5
  name: string;
5
6
  uri: string;
6
- type: 'AD' | 'VOD' | 'CHANNEL';
7
- }
8
- export interface ChannelSource extends BasicSource {
9
7
  from: Date;
10
8
  channelName: string;
11
9
  to: Date;
12
- type: 'CHANNEL';
13
- }
14
- export interface AdSource extends BasicSource {
10
+ type: 'channel';
11
+ watchWithoutAdsRecommendation: {
12
+ showPurchaseDialog: () => void;
13
+ } | null;
14
+ };
15
+ export declare type AdSource = {
16
+ new (uri: string, name: string, description: string, skipDelayMs: number | null, adDurationMs: number, trackingContext?: any, // internal Tivio types
17
+ adMarker?: any, // internal Tivio types
18
+ packInfo?: any, // internal Tivio types
19
+ provider?: any): AdSource;
20
+ description: string;
21
+ name: string;
22
+ uri: string;
15
23
  durationMs: number;
16
24
  skipDelayMs: number | null;
17
- type: 'AD';
18
- canSkip?: boolean;
19
- skip?: () => void;
20
- }
21
- export interface VodSource extends BasicSource {
22
- type: 'VOD';
23
- }
24
- export declare type InputSource = AdSource | ChannelSource | VodSource;
25
- export declare type PlayerInterface = {
26
- play: () => Empty;
27
- pause: () => Empty;
28
- seekTo: (positionMs: number) => Empty;
29
- setSource: (source: InputSource | null) => Empty;
30
- setVolume: (volume: number) => Empty;
25
+ type: 'ad';
26
+ /**
27
+ * true if is skippable and skip countdown has passed
28
+ */
29
+ canSkip: boolean;
30
+ /**
31
+ * true ad if is skippable after some skipDelayMs (if it is skippable, skipDelayMs is defined)
32
+ */
33
+ isSkippable: boolean;
34
+ /**
35
+ * Skip ad. Only works when canSkip is true
36
+ */
37
+ skip: () => void;
38
+ /**
39
+ * Order in ad break (ad break is a group of ads played right after each other)
40
+ */
41
+ order: number;
42
+ /**
43
+ * Total number of ads in ad break (ad break is a group of ads played right after each other)
44
+ */
45
+ totalCount: number;
46
+ secondsToEnd: number;
47
+ secondsToSkippable: number | null;
31
48
  };
49
+ export declare type VodTivioSource = {
50
+ new (uri: string, videoId: string, name: string, description: string, adMonetizationId?: string): VodTivioSource;
51
+ type: 'vod_tivio';
52
+ description: string;
53
+ name: string;
54
+ uri: string;
55
+ };
56
+ export declare type VodExternalSource = {
57
+ new (uri: string, monetizationId: string, name: string, description: string, originalOptions: Record<string, any>): VodTivioSource;
58
+ type: 'vod_external';
59
+ description: string;
60
+ name: string;
61
+ uri: string;
62
+ };
63
+ export declare type InputSource = AdSource | ChannelSource | VodTivioSource | VodExternalSource;
64
+ declare type PlayerState = 'playing' | 'paused' | 'idle';
65
+ export interface PlayerInterface {
66
+ pause: () => void;
67
+ /**
68
+ * unpause
69
+ */
70
+ play: () => void;
71
+ /**
72
+ * @param {number} ms - milliseconds relative to start of video (relative to 0 ms)
73
+ * or in case of TV programs relative to start of the program (relative to source.from ms)
74
+ */
75
+ seekTo: (ms: number) => void;
76
+ /**
77
+ * Source to be passed to player.
78
+ *
79
+ * Depending on autoplay settings it should either start playing
80
+ * immediately or just be loaded by player and stay paused.
81
+ */
82
+ setSource: (source: InputSource | null) => void;
83
+ /**
84
+ * volume in [0,1]
85
+ */
86
+ setVolume?: (volume: number) => void;
87
+ mute?: () => void;
88
+ /**
89
+ * restore volume to previous value
90
+ */
91
+ unmute?: () => void;
92
+ }
32
93
  export declare type PlayerWrapper = {
94
+ /**
95
+ * Report that playback of video has finished
96
+ */
97
+ onPlaybackEnded: () => void;
98
+ /**
99
+ * Report video progress in milliseconds
100
+ */
101
+ onTimeChanged: (ms: number) => void;
102
+ /**
103
+ * Report that video state changed
104
+ */
105
+ onStateChanged: (state: PlayerState) => void;
106
+ /**
107
+ * Send source to Tivio
108
+ */
109
+ onSourceChanged: (source: InputSource | null) => void;
110
+ /**
111
+ * Report that video failed to load (never started playing)
112
+ */
113
+ onLoadError: (error: Error) => void;
114
+ /**
115
+ * Report that video failed during playback (successfully loaded and then failed, e.g. part of stream is invalid)
116
+ */
117
+ onError: (error: Error) => void;
118
+ /**
119
+ * Unpause video
120
+ */
121
+ play: () => void;
122
+ /**
123
+ * Pause video
124
+ */
125
+ pause: () => void;
126
+ /**
127
+ * Currently playing source
128
+ */
129
+ source: InputSource | null;
33
130
  events: {
34
- addListener: <T = any>(event: string, cb: (value: T) => Empty) => Empty;
35
- removeAllListeners: () => Empty;
131
+ isSupported: (even: string) => boolean;
132
+ addListener: <T = any>(event: string, cb: (value: T) => Empty) => void;
133
+ removeListener: <T = any>(event: string, cb: (value: T) => Empty) => void;
134
+ removeAllListeners: () => void;
36
135
  };
136
+ /**
137
+ * Register a low level player that implements player methods, like play video, change volume, etc.
138
+ */
139
+ register: (playerInterface: PlayerInterface) => void;
140
+ /**
141
+ * duration of current source in ms (both setter and getter)
142
+ */
143
+ durationMs: number | null;
144
+ isPlaybackStarted: boolean;
145
+ isPaused: boolean;
146
+ isPlaying: boolean;
147
+ isIdle: boolean;
148
+ error: Error | null;
149
+ /**
150
+ * Replay the video that finished playback
151
+ */
152
+ replay: () => void;
153
+ /**
154
+ * Retry to play a video that failed to start playing (e.g. due to a network error)
155
+ */
156
+ retry: () => void;
157
+ togglePlayPause: () => void;
158
+ seekTo: (ms: number) => void;
159
+ /**
160
+ * set volume to value between 0,1
161
+ */
162
+ setVolume: (volume: number) => void;
163
+ /**
164
+ * change volume by value between -1,1
165
+ */
166
+ changeVolumeBy: (volume: number) => void;
167
+ setMuted: (muted: boolean) => void;
168
+ toggleMuted: () => void;
37
169
  };
38
170
  export declare type UsePlayerEvent = <T = any>(eventName: string) => T | null;
171
+ export {};
@@ -51,7 +51,7 @@ declare type Section = {
51
51
  channel: Channel;
52
52
  videos: Video[];
53
53
  };
54
- declare type Chapter = object;
54
+ declare type Chapter = any;
55
55
  declare type Purchase = {
56
56
  isPurchased: boolean;
57
57
  monetizationId: string;
@@ -102,7 +102,7 @@ export interface TivioWidgetRef {
102
102
  x: number;
103
103
  });
104
104
  }
105
- interface VodTivioSource {
105
+ interface VodTivioSourcePojo {
106
106
  type: 'VodTivioSource';
107
107
  description: string;
108
108
  path: string;
@@ -111,7 +111,7 @@ interface VodTivioSource {
111
111
  poster?: string;
112
112
  adMonetizationId?: string;
113
113
  }
114
- interface ChannelSource {
114
+ interface ChannelSourcePojo {
115
115
  type: 'ChannelSource';
116
116
  uri: string;
117
117
  originalOptions: any;
@@ -125,7 +125,7 @@ interface ChannelSource {
125
125
  declare type VideoPath = string;
126
126
  interface WebPlayerProps {
127
127
  id: string;
128
- source?: VodTivioSource | ChannelSource | VideoPath | null;
128
+ source?: VodTivioSourcePojo | ChannelSourcePojo | VideoPath | null;
129
129
  onEnded?: () => any;
130
130
  className?: string;
131
131
  /**
@@ -173,4 +173,4 @@ declare type TivioSources = {
173
173
  VodExternalSource: any;
174
174
  VodTivioSource: any;
175
175
  };
176
- export type { RemoteProviderProps, WebPlayerProps, Marker, BetOffer, Purchase, Chapter, Language, Widget, Channel, Section, Video, TivioSources, UserData, User, Monetization, VodTivioSource, };
176
+ export type { RemoteProviderProps, WebPlayerProps, Marker, BetOffer, Purchase, Chapter, Language, Widget, Channel, Section, Video, TivioSources, UserData, User, Monetization, VodTivioSourcePojo, ChannelSourcePojo, };
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tivio/sdk-react",
3
- "version": "3.0.0-alpha4",
3
+ "version": "3.1.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "source": "src/index.ts",
@@ -11,52 +11,47 @@
11
11
  "scripts": {
12
12
  "build": "bash ./scripts/build_prod.sh",
13
13
  "build:dev": "bash ./scripts/build_dev.sh",
14
- "start": "bash ./scripts/start.sh",
14
+ "start": "yarn ts-node ./scripts/start.ts",
15
15
  "test": "jest --config=./jest.config.js --coverage",
16
16
  "clean": "rm -rf dist",
17
17
  "prepublishOnly": "yarn && yarn run build && yarn ts-node ./scripts/prepublish.ts",
18
18
  "postpublish": "yarn ts-node ./scripts/postpublish.ts",
19
19
  "publish:alpha": "npm publish --tag alpha",
20
- "check:cycles ": "npx madge --circular src/**/*"
20
+ "check:cycles": "npx madge --circular src/**/*"
21
21
  },
22
22
  "peerDependencies": {
23
- "react": "^17.0.2",
24
- "react-dom": "^17.0.2"
23
+ "react": "^17.0.0",
24
+ "react-dom": "^17.0.0"
25
25
  },
26
26
  "dependencies": {
27
27
  "@material-ui/core": "^4.11.2",
28
28
  "@material-ui/icons": "^4.11.2",
29
29
  "@sentry/browser": "^6.1.0",
30
- "@tivio/common": "1.1.64",
30
+ "@tivio/common": "1.1.74",
31
31
  "firebase": "^8.2.3",
32
32
  "formik": "^2.2.7",
33
33
  "i18next": "^19.8.4",
34
- "mobx-react": "^7.1.0",
35
34
  "mobx": "^6.0.4",
36
- "react-dom": "^17.0.2",
35
+ "mobx-react": "^7.1.0",
37
36
  "react-i18next": "^9.0.10",
38
37
  "react-router-dom": "^5.2.0",
39
- "react-scripts": "4.0.3",
40
38
  "react-spring": "^9.2.4",
41
39
  "react-virtualized": "^9.22.3",
42
- "react": "^17.0.2",
43
40
  "styled-components": "^5.2.1",
44
41
  "yup": "^0.32.9"
45
42
  },
46
43
  "devDependencies": {
47
- "web-vitals": "^1.0.1",
48
- "madge": "^5.0.1",
49
- "@testing-library/user-event": "^12.1.10",
50
44
  "@testing-library/jest-dom": "^5.11.9",
51
45
  "@testing-library/react": "^11.2.3",
52
46
  "@testing-library/react-hooks": "^5.0.3",
47
+ "@testing-library/user-event": "^12.1.10",
53
48
  "@types/jest": "^26.0.15",
54
49
  "@types/node": "^12.0.0",
50
+ "@types/node-fetch": "^2.5.8",
55
51
  "@types/react": "^17.0.0",
56
52
  "@types/react-dom": "^17.0.0",
57
53
  "@types/react-router-dom": "^5.1.6",
58
54
  "@types/react-virtualized": "^9.21.13",
59
- "@types/node-fetch": "^2.5.8",
60
55
  "@types/styled-components": "^5.1.7",
61
56
  "@typescript-eslint/eslint-plugin": "^4.14.0",
62
57
  "@typescript-eslint/parser": "^4.14.2",
@@ -65,13 +60,18 @@
65
60
  "jest": "^27.0.1",
66
61
  "jest-cli": "^26.6.3",
67
62
  "jest-fetch-mock": "^3.0.3",
63
+ "madge": "^5.0.1",
68
64
  "node-fetch": "^2.6.1",
65
+ "react": "^17.0.2",
66
+ "react-dom": "^17.0.2",
69
67
  "stream-browserify": "^3.0.0",
70
68
  "timers-browserify": "^2.0.12",
71
69
  "ts-jest": "^26.4.4",
72
70
  "typescript": "^4.1.3",
71
+ "web-vitals": "^1.0.1",
73
72
  "webpack": "^5.15.0",
74
73
  "webpack-cli": "^4.4.0",
75
- "webpack-merge": "^5.7.3"
74
+ "webpack-merge": "^5.7.3",
75
+ "yargs": "17"
76
76
  }
77
77
  }