@tivio/sdk-react 2.4.0-alpha → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # @tivio/sdk-react
2
2
 
3
3
  ## Changelog
4
- * v2.4.0-alpha
5
- * feat: add useCancelSubscription hook
4
+ * Unreleased
5
+ * v2.4.2
6
+ * patch: added back changelog
7
+ * v2.4.1
8
+ * patch: improved doc about player wrapper
9
+ * v2.4.0
10
+ * patch: improved Player wrapper types
11
+ * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
12
+ * patch: added support for remote code on browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
13
+ * patch: added support for browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
6
14
  * v2.3.4
7
15
  * patch: fix of usePurchaseSubscription not reactive
8
16
  * v2.3.3
@@ -22,7 +30,7 @@
22
30
  * v2.1.5
23
31
  * patch fix of `useVideosInSection` hook (fetching video's monetizations)
24
32
  * v2.1.4
25
- * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react@2.1.9)
33
+ * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react-dom@2.1.9)
26
34
  * v2.1.3
27
35
  * patch: fix changelog
28
36
  * v2.1.2
@@ -54,16 +62,14 @@
54
62
  * v1.3.4
55
63
  * ...
56
64
 
57
- ## Installation
58
65
 
59
- Check/install peer dependencies
60
- ``` sh
61
- npm install --save mobx@6.0.4 styled-components@5.2.1 firebase@8.2.3 react@17.0.2 react-dom@17.0.2
62
- ```
66
+ ## Installation
63
67
 
64
- Install SDK itself
65
- ``` sh
66
- npm install --save @tivio/sdk-react
68
+ Install @tivio/sdk-react along with its peer dependencies
69
+ ```sh
70
+ npm i react@17 react-dom@17 @tivio/sdk-react
71
+ # or
72
+ yarn add react@17 react-dom@17 @tivio/sdk-react
67
73
  ```
68
74
 
69
75
  ## Initialization
@@ -73,13 +79,13 @@ Put Tivio Provider at the top level of your application:
73
79
  ``` javascript
74
80
  import { TivioProvider } from '@tivio/sdk-react'
75
81
 
76
- const tivioConf = {
82
+ const config = {
77
83
  secret: 'XXXXXXXXXX',
78
84
  }
79
85
 
80
86
  function App({children}) {
81
87
  return (
82
- <TivioProvider conf={tivioConf}>
88
+ <TivioProvider conf={config}>
83
89
  {children}
84
90
  </TivioProvider>
85
91
  )
@@ -91,7 +97,7 @@ function App({children}) {
91
97
  ``` javascript
92
98
  import { TivioProvider, setUser } from '@tivio/sdk-react'
93
99
 
94
- const tivioConf = {
100
+ const config = {
95
101
  secret: 'XXXXXXXXXX',
96
102
  }
97
103
 
@@ -99,7 +105,7 @@ setUser('user-id', { some: 'payload' })
99
105
 
100
106
  function App({children}) {
101
107
  return (
102
- <TivioProvider conf={tivioConf}>
108
+ <TivioProvider conf={config}>
103
109
  {children}
104
110
  </TivioProvider>
105
111
  )
@@ -108,7 +114,7 @@ function App({children}) {
108
114
  ## Tivio widget
109
115
 
110
116
  Tivio widget is the main Tivio component which shows the widget and provides access to its channels, sections and videos.
111
- Usage is very simple (be sure to set `id` to the widget ID you have configured in Tivio Studio):
117
+ Usage is very simple (be sure to set `id` to the widget ID you have configured in [Tivio Studio](https://studio.tiv.io/)):
112
118
 
113
119
  ``` javascript
114
120
  import { TivioWidget } from '@tivio/sdk-react'
@@ -137,48 +143,146 @@ function Screen() {
137
143
  )
138
144
  }
139
145
  ```
146
+
140
147
  ## Player wrapper
141
148
 
142
- Player wrapper is the way how you can enhance your video player with Tivio features (e.g. inserting of ads).
149
+ Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
150
+
151
+ ### Wrap your player methods with Tivio player wrapper
143
152
 
144
153
  ``` javascript
145
- import { useTivioData } from '@tivio/sdk-react'
154
+ import { useTivioReadyData } from '@tivio/sdk-react'
146
155
 
147
156
  function CustomPlayer() {
148
- const tivio = useTivioData()
149
- const [isPlaying, setIsPlaying] = useState()
157
+ const tivioData = useTivioReadyData()
150
158
 
151
159
  useEffect(() => {
152
- (async () => {
153
- if (tivio.getPlayerWrapper) {
154
- const playerWrapper = await tivio.getPlayerWrapper(
155
- { playerWrapperId: 'default' }
156
- )
157
-
158
- playerWrapper.register({
159
- play: () => {
160
- setIsPlaying(true)
161
- // start playback using your player here
162
- },
163
- pause: () => {
164
- setIsPlaying(false)
165
- // pause playback using your player here
166
- },
167
- seekTo: (ms: number) => {
168
- // seek using your player here
169
- },
170
- setSource: (videoSource: InputSource) => {
171
- // play videoSource using your player here
172
- },
173
- })
174
- }
175
- })()
176
- }, [])
177
-
178
- return (<div>Example is {isPlaying ? null : 'not '}playing.</div>)
160
+ if (tivioData) {
161
+ // If your app uses multiple player instances, use different Tivio player wrapper for each
162
+ // distinguished by playerWrapperId
163
+ const playerWrapper = tivio.getPlayerWrapper({ playerWrapperId: 'PLAYER_1' })
164
+
165
+ // Pass your player methods to Tivio player wrapper
166
+ playerWrapper.register({
167
+ play: () => {
168
+ // Un-pause your player
169
+ },
170
+ pause: () => {
171
+ // Pause your player
172
+ },
173
+ seekTo: (ms: number) => {
174
+ // Seek to position in milliseconds using your player
175
+ },
176
+ setSource: (videoSource: InputSource) => {
177
+ // Send this video source to your player to load it
178
+ },
179
+ })
180
+ }
181
+ }, [tivioData])
182
+ }
183
+ ```
184
+
185
+ ### Start using Tivio player wrapper methods to control playback
186
+
187
+ ``` javascript
188
+ // Channel source metadata, such as channel name, epg start and epg end are necessary
189
+ // for TV ad segment detection and application of ad strategies
190
+ const source = new ChannelSource(
191
+ 'https://channel_prima_hd.m3u8',
192
+ {
193
+ // here put any additional metadata, for your use.
194
+ // This object will not be touched by Tivio
195
+ },
196
+ // channel name
197
+ // can also be prima hd, prima_hd, prima, Prima, PRIMA, etc.
198
+ // we will normalize it to snake case and add '_hd' if necessary
199
+ 'Prima HD',
200
+ // program name
201
+ 'Dr. House',
202
+ // description (optional)
203
+ 'Episode about Dr. House being awesome',
204
+ // EPG start
205
+ new Date('2021-12-10T12:00:00'),
206
+ // EPG end
207
+ new Date('2021-12-10T13:40:00'),
208
+ )
209
+
210
+ // Send source to player
211
+ playerWrapper.onSourceChanged(source)
212
+
213
+ // Un-pause player
214
+ playerWrapper.play()
215
+
216
+ // Pause player
217
+ playerWrapper.pause()
179
218
  }
180
219
  ```
181
220
 
221
+ ### Start reporting player events to Tivio
222
+
223
+ ``` javascript
224
+ // Report that source is playing
225
+ playerWrapper.onStateChanged('playing')
226
+
227
+ // Report that source is paused
228
+ playerWrapper.onStateChanged('paused')
229
+
230
+ // Report that source stopped playing
231
+ playerWrapper.onPlaybackEnded()
232
+ playerWrapper.onStateChanged('idle')
233
+
234
+ // Report video progress
235
+ playerWrapper.onTimeChanged(ms)
236
+ }
237
+ ```
238
+
239
+ ### Start reporting playback-related errors to Tivio
240
+
241
+ ``` javascript
242
+ // Report that video failed to load (e.g. due to a wrong URI)
243
+ playerWrapper.onLoadError(new Error('video failed to load'))
244
+
245
+ // Report that video failed during playback (e.g. due to bad connection, corrupted chunks of stream video etc.)
246
+ // This type of error may be auto-recoverable
247
+ playerWrapper.onError(new Error('playback error'))
248
+ }
249
+ ```
250
+
251
+ ## Tivio DOM events
252
+
253
+ `TivioWidget` triggers these events on `window.document`.
254
+
255
+ 1. To instruct the parent app to navigate to and focus a specific TivioWidget (e.g. after going back from a Tivio screen)
256
+
257
+ ```typescript
258
+ document.addEventListener("tivio_request_goto", e => {
259
+ e.detail.widgetId; // string - Tivio widget ID to go navigate to in UI
260
+ });
261
+ ```
262
+ 2. To notify the parent app about context switch, i.e. where is the user located or what is he focusing
263
+
264
+ ```typescript
265
+ document.addEventListener("tivio_context_switch", e => {
266
+ e.detail.context; // 'tivio' | 'parent' - where is the user located? - in Tivio or in parent app
267
+
268
+ // For context Tivio there are additional fields
269
+ e.detail.context; // 'tivio'
270
+ e.detail.contextLocation; // 'route' | 'overlay' | 'widget' - where in Tivio is the user located?
271
+ // - on a Tivio route, in parent app but looking at a full screen Tivio overlay,
272
+ // or in parent app and focus is on a Tivio widget
273
+
274
+ // For context Tivio contextLocation 'widget' there is an additional field of widget ID
275
+ e.detail.widgetId; // string - which Tivio widget is focused right now
276
+ });
277
+ ```
278
+ 3. To notify the parent app about whether it should be handling key input from RC (TV remote) or not. When inputHandler is 'tivio', the parent app should stop reacting to key input, when inputHandler is 'parent' the parent app should start reacting again.
279
+
280
+ ```typescript
281
+ document.addEventListener("tivio_key_input_handling_change", e => {
282
+ e.detail.inputHandler; // 'tivio' | 'parent' - who should be handling RC input? - Tivio or parent app
283
+ });
284
+ ```
285
+
182
286
  ## Data hooks
183
287
 
184
288
  If you don't want to use TivioWidget, you can implement your own UI using React data hooks.
@@ -1,3 +1,8 @@
1
1
  import React from 'react';
2
- declare const ContextProvider: React.FC;
2
+ import { RemoteBundleState } from '../services/bundleLoader';
3
+ interface Props {
4
+ bundleState: RemoteBundleState;
5
+ children: any;
6
+ }
7
+ declare const ContextProvider: React.FC<Props>;
3
8
  export { ContextProvider, };
@@ -3,11 +3,17 @@
3
3
  * nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4
4
  */
5
5
  import React, { FunctionComponentElement } from 'react';
6
+ import type { PlayerWrapper } from '../types/customPlayer.types';
6
7
  export declare type PlayerProviderProps = {
7
8
  children: React.ReactNode;
8
9
  playerWrapperId?: string;
9
10
  };
10
- export declare type Player = any;
11
- export declare const PlayerContext: React.Context<any>;
11
+ /**
12
+ * value
13
+ * - undefined - you are trying to access this context but are not inside <PlayerContext /> that is a bug
14
+ * - null - we are waiting for remote code
15
+ * - Player - player is ready
16
+ */
17
+ export declare const PlayerContext: React.Context<PlayerWrapper | null | undefined>;
12
18
  export declare const PlayerProvider: ({ children, playerWrapperId, }: PlayerProviderProps) => FunctionComponentElement<PlayerProviderProps>;
13
19
  export declare function withPlayerContext(id: string): <P>(WrappedComponent: React.ComponentType<P>) => (props: P) => JSX.Element;
@@ -1,8 +1,5 @@
1
1
  export * from './ChannelsContext';
2
- export * from './OrganizationSubscriptionsContext';
3
- export * from './PurchasesWithVideosContext';
4
2
  export * from './ScreensContext';
5
3
  export * from './SectionsContext';
6
- export * from './UserContext';
7
4
  export * from './VideosContext';
8
5
  export * from './RowItemsContext';
@@ -2,6 +2,7 @@ export * from './useUser';
2
2
  export * from './useTaggedVideos';
3
3
  export * from './useScreens';
4
4
  export * from './useScreen';
5
+ export * from './useSearch';
5
6
  export * from './useItemsInRow';
6
7
  export * from './useCancelSubscription';
7
8
  export * from './useTransactionPayment';
@@ -13,3 +14,5 @@ export * from './usePurchasesWithVideos';
13
14
  export * from './useFreePurchase';
14
15
  export * from './useRowsInScreen';
15
16
  export * from './useTivio';
17
+ export * from './useOverlay';
18
+ export * from './useWatchWithoutAds';
@@ -1,4 +1,3 @@
1
- declare const useOrganizationSubscriptions: () => {
1
+ export declare const useOrganizationSubscriptions: () => {
2
2
  subscriptions: import("@tivio/common").Monetization[];
3
3
  };
4
- export { useOrganizationSubscriptions, };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Displays overlay to purchase "watch without ads mode" if available.
3
+ * This overlay can be hidden by pressing BACK button on RC.
4
+ */
5
+ export declare const useOverlayToPurchaseWatchWithoutAds: () => {
6
+ showOverlay: () => void;
7
+ };
8
+ interface Callbacks {
9
+ onShow: () => void;
10
+ onHide: () => void;
11
+ }
12
+ export declare const useRegisterOverlayCallbacks: (callbacks: Callbacks) => void;
13
+ export {};
@@ -0,0 +1,8 @@
1
+ import { ALGOLIA_INDEX_NAME, UseSearch } from '@tivio/common';
2
+ /**
3
+ * Full text search that returns entities based on search query.
4
+ * @param indexName - index that search would be performed on ('videos', 'tags', etc.)
5
+ * @param options - pagination options
6
+ */
7
+ export declare const useSearch: UseSearch;
8
+ export { ALGOLIA_INDEX_NAME };
@@ -1,5 +1,4 @@
1
- declare const useUser: () => {
1
+ export declare const useUser: () => {
2
2
  user: import("@tivio/common/dist/types/externalTypes/user").User | null;
3
3
  error: string | null;
4
4
  };
5
- export { useUser, };
@@ -0,0 +1,5 @@
1
+ export declare const useCanPurchaseWatchWithoutAds: () => boolean;
2
+ export declare const useWatchWithoutAds: () => {
3
+ canPurchaseWatchWithoutAds: boolean;
4
+ showOverlay: () => void;
5
+ };