@tivio/sdk-react 3.1.4-alpha2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -2,20 +2,17 @@
2
2
 
3
3
  ## Changelog
4
4
 
5
- * UNRELEASED
5
+ * v3.2.0
6
6
  * minor: Added `capabilitiesOptions` for finer configuration of device capabilities
7
+ * minor: tag names are returned in correct language (the one from tivio config); language value should be one from enum "Language"
7
8
  * v3.1.3
8
9
  * patch: Hotfix made sure disabled Tivio does not break React Native
9
- * internal: Fixed conf.bundleUrlOverride error handling
10
10
  * v3.1.2
11
11
  * patch: Allow `conf` prop of `TivioProvider` to be `null` or `undefined` in order to turn off Tivio
12
- * internal: Added `runFeatureSupportCheck` to `TivioProvider`
13
12
  * v3.1.1
14
13
  * patch: fixed `setUser()` crash when bundle fails to load
15
14
  * v3.1.0
16
- * internal: refactored `useAd`, `useAdSegment`
17
15
  * patch: `useAdSegment()` now returns null if no monetization is configured, ad segments are not managed in that situation
18
- * internal: fixed refactored `setUser()`
19
16
  * minor: enriched `AdSegment` type from `useAdSegment()`
20
17
  * minor: Added `setUser()` function for login and logout
21
18
  * v3.0.0
package/README.md.bak ADDED
@@ -0,0 +1,517 @@
1
+ # @tivio/sdk-react
2
+
3
+ ## Changelog
4
+
5
+ * v3.2.0
6
+ * minor: Added `capabilitiesOptions` for finer configuration of device capabilities
7
+ * minor: tag names are returned in correct language (the one from tivio config); language value should be one from enum "Language"
8
+ * v3.1.3
9
+ * patch: Hotfix made sure disabled Tivio does not break React Native
10
+ * internal: Fixed conf.bundleUrlOverride error handling
11
+ * v3.1.2
12
+ * patch: Allow `conf` prop of `TivioProvider` to be `null` or `undefined` in order to turn off Tivio
13
+ * internal: Added `runFeatureSupportCheck` to `TivioProvider`
14
+ * v3.1.1
15
+ * patch: fixed `setUser()` crash when bundle fails to load
16
+ * v3.1.0
17
+ * internal: refactored `useAd`, `useAdSegment`
18
+ * patch: `useAdSegment()` now returns null if no monetization is configured, ad segments are not managed in that situation
19
+ * internal: fixed refactored `setUser()`
20
+ * minor: enriched `AdSegment` type from `useAdSegment()`
21
+ * minor: Added `setUser()` function for login and logout
22
+ * v3.0.0
23
+ * minor: Added hook `useWatchWithoutAdsOffer` to trigger purchase dialog to "watch without ads", if available
24
+ * patch: fix peerDependency declaration for react, react-dom
25
+ * major: TivioProvider requires deviceCapabilities
26
+ * major: TivioProvider requires currency
27
+ * minor: add voucher support (see usePurchaseSubscription and useTransactionPayment hooks)
28
+ * minor: device limit support
29
+ * minor: drm (Widevine, PlayReady) support
30
+ * minor: watermarking support
31
+ * minor: add useSearch hook
32
+ * patch: price on video is 0 when purchased
33
+ * v2.4.2
34
+ * patch: added back changelog
35
+ * v2.4.1
36
+ * patch: improved doc about player wrapper
37
+ * v2.4.0
38
+ * patch: improved Player wrapper types
39
+ * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
40
+ * 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)
41
+ * patch: added support for browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
42
+ * v2.3.4
43
+ * patch: fix of usePurchaseSubscription not reactive
44
+ * v2.3.3
45
+ * patch: fix of useUser not updating
46
+ * v2.3.2
47
+ * patch: next app doesn't fail anymore due to "self is not defined"
48
+ * v2.3.1
49
+ * patch: fix of @tivio/common dependency
50
+ * v2.3.0
51
+ * minor: add useTaggedVideos that allows to fetch videos with given tags
52
+ * minor: add option to fetch tags (on hook useItemsInRow), useVideo always fetching videos tags
53
+ * v2.2.1
54
+ * patch: disable Sentry when no config is supplied to `TivioProvider`
55
+ * v2.2.0
56
+ * patch: reduced bundle size
57
+ * minor: disable Sentry when no config is supplied to `TivioProvider` or when Tivio is disabled `{ enable: false }`, or when Sentry is disabled via config `{ enableSentry: false }`
58
+ * v2.1.5
59
+ * patch fix of `useVideosInSection` hook (fetching video's monetizations)
60
+ * v2.1.4
61
+ * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react-dom@2.1.9)
62
+ * v2.1.3
63
+ * patch: fix changelog
64
+ * v2.1.2
65
+ * patch: Fixed exported types
66
+ * v2.1.1
67
+ * patch: TivioWidget now correctly reports `false` via `onEnabled` callback when in invalid internal state
68
+ * v2.1.0
69
+ * patch: fix of useItemsInRow hook
70
+ * patch: fix of useScreen hook
71
+ * add: useRowsInScreen hook
72
+ * v2.0.3
73
+ * patch: fix of useItemsInRow hook
74
+ * v2.0.2
75
+ * patch: screen and row IDs fixed
76
+ * `TivioBundle.subscriptions.subscribeToItemsInRow` now accepts user-defined ID via studio.tiv.io
77
+ * `TivioBundle.subscriptions.subscribeToScreen` now accepts user-defined ID via studio.tiv.io
78
+ * `Screen` and `Row` types returned by `useScreen()` return their user-defined IDs (`.id`) correctly
79
+ * v2.0.1
80
+ * no changes
81
+ * v2.0.0
82
+ * major: video.channelId can now be `string | null` used to be `string`
83
+ * minor: added data API and hooks for screens (screens, rows of screen and row items)
84
+ * hooks: `useScreen()`, `useItemsInRow()`
85
+ * api: `TivioBundle.subscriptions.subscribeToScreen`, `TivioBundle.subscriptions.subscribeToItemsInRow`
86
+ * v1.3.6
87
+ * ?
88
+ * v1.3.5
89
+ * minor: added WebPlayer props (canReplay, showMarkers, customShortcuts, enableKeyboardShortcuts, source.poster)
90
+ * v1.3.4
91
+ * ...
92
+
93
+
94
+ ## Installation
95
+
96
+ Install @tivio/sdk-react along with its peer dependencies
97
+ ```sh
98
+ npm i react@17 react-dom@17 @tivio/sdk-react
99
+ # or
100
+ yarn add react@17 react-dom@17 @tivio/sdk-react
101
+ ```
102
+
103
+ ## Initialization
104
+
105
+ Put Tivio Provider at the top level of your application:
106
+
107
+ ``` javascript
108
+ import { TivioProvider } from '@tivio/sdk-react'
109
+
110
+ const config = {
111
+ secret: 'XXXXXXXXXX',
112
+ }
113
+
114
+ function App({children}) {
115
+ return (
116
+ <TivioProvider conf={config}>
117
+ {children}
118
+ </TivioProvider>
119
+ )
120
+ }
121
+ ```
122
+
123
+ ## Authentication
124
+
125
+ A logged-in user can access more features, such as making purchases. In order to authenticate a user with Tivio, use the `setUser()` method.
126
+
127
+ Verification of the user against 3rd party auth servers is implemented per customer.
128
+
129
+ ```typescript
130
+ import { setUser } from '@tivio/sdk-react'
131
+
132
+ // Log in
133
+
134
+ // Payload is specific per customer
135
+ // A common use-case is sending an auth token inside the payload, which Tivio can use to verify the user
136
+ await setUser('userId', { token: 'xxx'})
137
+
138
+ // Log out
139
+ await setUser('userId', null)
140
+ ```
141
+
142
+ ## Tivio widget
143
+
144
+ Tivio widget is the main Tivio component which shows the widget and provides access to its channels, sections and videos.
145
+ Usage is very simple (be sure to set `id` to the widget ID you have configured in [Tivio Studio](https://studio.tiv.io/)):
146
+
147
+ ``` javascript
148
+ import { TivioWidget } from '@tivio/sdk-react'
149
+
150
+ function Screen() {
151
+ return (
152
+ <TivioWidget id="theWidgetId" />
153
+ )
154
+ }
155
+ ```
156
+
157
+ ### Usage with smart TV navigation (focus control)
158
+
159
+ ``` javascript
160
+ import { TivioWidget, TivioWidgetRef } from '@tivio/sdk-react'
161
+
162
+ function Screen() {
163
+ const ref = useRef<TivioWidgetRef>(null)
164
+
165
+ return (
166
+ <TivioWidget id="theWidgetId" ref={ref} onBlur={() => {/* widget lost focus */}}/>
167
+ <div>
168
+ <button onClick={() => ref.current?.focus({ x: 100 })}>Focus</button>
169
+ <button onClick={() => ref.current?.unfocus()}>Unfocus</button>
170
+ </div>
171
+ )
172
+ }
173
+ ```
174
+
175
+ ## Player wrapper
176
+
177
+ 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.
178
+
179
+ ### Wrap your player methods with Tivio player wrapper
180
+
181
+ ``` javascript
182
+ import { useTivioReadyData } from '@tivio/sdk-react'
183
+
184
+ function CustomPlayer() {
185
+ const tivioData = useTivioReadyData()
186
+
187
+ useEffect(() => {
188
+ if (tivioData) {
189
+ // If your app uses multiple player instances, use different Tivio player wrapper for each
190
+ // distinguished by playerWrapperId
191
+ const playerWrapper = tivio.getPlayerWrapper({ playerWrapperId: 'PLAYER_1' })
192
+
193
+ // Pass your player methods to Tivio player wrapper
194
+ playerWrapper.register({
195
+ play: () => {
196
+ // Un-pause your player
197
+ },
198
+ pause: () => {
199
+ // Pause your player
200
+ },
201
+ seekTo: (ms: number) => {
202
+ // Seek to position in milliseconds using your player
203
+ },
204
+ setSource: (videoSource: InputSource) => {
205
+ // Send this video source to your player to load it
206
+ },
207
+ })
208
+ }
209
+ }, [tivioData])
210
+ }
211
+ ```
212
+
213
+ ### Start using Tivio player wrapper methods to control playback
214
+
215
+ ``` javascript
216
+ // Channel source metadata, such as channel name, epg start and epg end are necessary
217
+ // for TV ad segment detection and application of ad strategies
218
+ const source = new ChannelSource(
219
+ 'https://channel_prima_hd.m3u8',
220
+ {
221
+ // here put any additional metadata, for your use.
222
+ // This object will not be touched by Tivio
223
+ },
224
+ // channel name
225
+ // can also be prima hd, prima_hd, prima, Prima, PRIMA, etc.
226
+ // we will normalize it to snake case and add '_hd' if necessary
227
+ 'Prima HD',
228
+ // program name
229
+ 'Dr. House',
230
+ // description (optional)
231
+ 'Episode about Dr. House being awesome',
232
+ // EPG start
233
+ new Date('2021-12-10T12:00:00'),
234
+ // EPG end
235
+ new Date('2021-12-10T13:40:00'),
236
+ )
237
+
238
+ // Send source to player
239
+ playerWrapper.onSourceChanged(source)
240
+
241
+ // Un-pause player
242
+ playerWrapper.play()
243
+
244
+ // Pause player
245
+ playerWrapper.pause()
246
+ }
247
+ ```
248
+
249
+ ### Start reporting player events to Tivio
250
+
251
+ ``` javascript
252
+ // Report that source is playing
253
+ playerWrapper.onStateChanged('playing')
254
+
255
+ // Report that source is paused
256
+ playerWrapper.onStateChanged('paused')
257
+
258
+ // Report that source stopped playing
259
+ playerWrapper.onPlaybackEnded()
260
+ playerWrapper.onStateChanged('idle')
261
+
262
+ // Report video progress
263
+ playerWrapper.onTimeChanged(ms)
264
+ }
265
+ ```
266
+
267
+ ### Start reporting playback-related errors to Tivio
268
+
269
+ ``` javascript
270
+ // Report that video failed to load (e.g. due to a wrong URI)
271
+ playerWrapper.onLoadError(new Error('video failed to load'))
272
+
273
+ // Report that video failed during playback (e.g. due to bad connection, corrupted chunks of stream video etc.)
274
+ // This type of error may be auto-recoverable
275
+ playerWrapper.onError(new Error('playback error'))
276
+ }
277
+ ```
278
+
279
+ ## Tivio DOM events
280
+
281
+ `TivioWidget` triggers these events on `window.document`.
282
+
283
+ 1. To instruct the parent app to navigate to and focus a specific TivioWidget (e.g. after going back from a Tivio screen)
284
+
285
+ ```typescript
286
+ document.addEventListener("tivio_request_goto", e => {
287
+ e.detail.widgetId; // string - Tivio widget ID to go navigate to in UI
288
+ });
289
+ ```
290
+ 2. To notify the parent app about context switch, i.e. where is the user located or what is he focusing
291
+
292
+ ```typescript
293
+ document.addEventListener("tivio_context_switch", e => {
294
+ e.detail.context; // 'tivio' | 'parent' - where is the user located? - in Tivio or in parent app
295
+
296
+ // For context Tivio there are additional fields
297
+ e.detail.context; // 'tivio'
298
+ e.detail.contextLocation; // 'route' | 'overlay' | 'widget' - where in Tivio is the user located?
299
+ // - on a Tivio route, in parent app but looking at a full screen Tivio overlay,
300
+ // or in parent app and focus is on a Tivio widget
301
+
302
+ // For context Tivio contextLocation 'widget' there is an additional field of widget ID
303
+ e.detail.widgetId; // string - which Tivio widget is focused right now
304
+ });
305
+ ```
306
+ 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.
307
+
308
+ ```typescript
309
+ document.addEventListener("tivio_key_input_handling_change", e => {
310
+ e.detail.inputHandler; // 'tivio' | 'parent' - who should be handling RC input? - Tivio or parent app
311
+ });
312
+ ```
313
+
314
+ ## Data hooks
315
+
316
+ If you don't want to use TivioWidget, you can implement your own UI using React data hooks.
317
+
318
+ ### useWidget hook
319
+
320
+ Gets Widget object and subscribes to its changes.
321
+
322
+ ``` javascript
323
+ /**
324
+ * Use widget
325
+ * @param widgetId - widget id
326
+ */
327
+ useWidget: (widgetId: string) => {
328
+ error: string | null;
329
+ data: Widget | null;
330
+ }
331
+ ```
332
+
333
+ ### useChannel hook
334
+
335
+ Gets Channel object and subscribes to its changes.
336
+
337
+ ``` javascript
338
+ /**
339
+ * Use channel
340
+ * @param channelId - channel id
341
+ */
342
+ useChannel: (channelId: string) => {
343
+ error: string | null;
344
+ data: Channel | null;
345
+ }
346
+ ```
347
+
348
+ ### useSection hook
349
+
350
+ Gets Section object and subscribes to its changes.
351
+
352
+ ``` javascript
353
+ /**
354
+ * Use section
355
+ * @param sectionId - section id
356
+ */
357
+ useSection: (sectionId: string) => {
358
+ error: string | null;
359
+ data: Section | null;
360
+ }
361
+ ```
362
+
363
+ ### useVideo hook
364
+
365
+ Gets Video object and subscribes to its changes.
366
+
367
+ ``` javascript
368
+ /**
369
+ * Use video
370
+ * @param videoId - video id
371
+ */
372
+ useVideo: (videoId: string) => {
373
+ error: string | null;
374
+ data: Video | null;
375
+ }
376
+ ```
377
+
378
+ ### useChannelsInWidget hook
379
+
380
+ Gets array of Channel objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
381
+ for pagination (returned in `data` object).
382
+
383
+ ``` javascript
384
+ /**
385
+ * Use channels in widget
386
+ * @param widgetId - widget id
387
+ * @param [limit] - channels count, defaults to 10
388
+ */
389
+ useChannelsInWidget: (widgetId: string, limit?: number) => {
390
+ error: string | null;
391
+ data: PaginationData<Channel> | null;
392
+ }
393
+ ```
394
+
395
+ ### useSectionsInChannel hook
396
+
397
+ Gets array of Section objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
398
+ for pagination (returned in `data` object).
399
+
400
+ ``` javascript
401
+ /**
402
+ * Use section in channel
403
+ * @param channelId - channel id
404
+ * @param [limit] - sections count, defaults to 10
405
+ */
406
+ useSectionsInChannel: (channelId: string, limit?: number) => {
407
+ error: string | null;
408
+ data: PaginationData<Section> | null;
409
+ }
410
+ ```
411
+
412
+ ### useVideosInSection hook
413
+
414
+ Gets array of Video objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
415
+ for pagination (returned in `data` object).
416
+
417
+ ``` javascript
418
+ /**
419
+ * Use videos in section
420
+ * @param sectionId - section id
421
+ * @param [limit] - videos count, defaults to 10
422
+ */
423
+ useVideosInSection: (sectionId: string, limit?: number) => {
424
+ error: string | null;
425
+ data: PaginationData<Video> | null;
426
+ }
427
+ ```
428
+
429
+ ### useScreen hook
430
+ Gets Screen object and subscribes to its changes.
431
+
432
+ ```ts
433
+ /**
434
+ * Hook to fetch an app screen
435
+ * @param screenId - screen ID configured via studio.tiv.io
436
+ */
437
+ useScreen: (screenId: string) => {
438
+ error: Error | null
439
+ data: Screen | null
440
+ }
441
+
442
+ // Example:
443
+ // Screens with their screenIds are configured via studio.tiv.io
444
+ const screenId = '890sdfvxoi'
445
+ const { error, data } = useScreen(screenId)
446
+
447
+ if (data) {
448
+ const screenName = data.name
449
+ const screenRows = data.rows
450
+ // ...
451
+ }
452
+ ```
453
+
454
+ ### useItemsInRow hook
455
+
456
+ Gets array of Video or Tag objects for a specified row. It is possible to use
457
+ `hasNextPage` and `fetchMore` for pagination (returned in `data` object).
458
+
459
+ *(Note: Does not subscribe to changes in video objects, in order to refresh data it is necessary to reload the app.)*
460
+
461
+ ```ts
462
+ /**
463
+ * Hook to fetch row items for rows received from `useScreen()`
464
+ * @param id - row ID configured via studio.tiv.io
465
+ * @param options.limit - items limit
466
+ * @param options.noLimit - disable/enable pagination (will fetch all items)
467
+ * @param options.fecthTags - disable/enable tags fetching
468
+ */
469
+ useItemsInRow: (id: string, options: {limit?: number, noLimit?: boolean, fecthTags?: boolean}) => {
470
+ error: Error | null
471
+ data: PaginationData<Video | Tag> | null
472
+ isLoading: boolean
473
+ }
474
+
475
+ // Example:
476
+ // Rows and their row ID can be loaded using useScreen() hook
477
+ const Row = ({ id }: { id: string}) => {
478
+ const rowData = useItemsInRow(id, 10)
479
+
480
+ return <div>
481
+ <div>Row id: {id}</div>
482
+ Count: ({rowData.data?.items.length})
483
+ <div>
484
+ {rowData.isLoading && <div>Loading...</div>}
485
+ {rowData.data?.items.map(item => (
486
+ <div>
487
+ <div>{item.name}</div>
488
+ <img src={item.cover} alt={item.name} />
489
+ </div>
490
+ ))}
491
+ </div>
492
+ <button onClick={() => rowData.data?.fetchMore()}>more</button>
493
+ </div>
494
+ }
495
+ ```
496
+
497
+ ### useTaggedItems hook
498
+
499
+ Allows to fetch videos with given tags.
500
+
501
+ ```ts
502
+ /**
503
+ * Hook to fetch row items for rows received from `useScreen()`
504
+ * @param id - row ID configured via studio.tiv.io
505
+ * @param options.limit - items limit
506
+ * @param options.noLimit - disable/enable pagination (will fetch all items)
507
+ * @param options.fecthTags - disable/enable tags fetching
508
+ */
509
+ useTaggedItems: (tagIds: string[], {limit?: number, noLimit?: boolean, fecthTags?: boolean}) => {
510
+ error: Error | null
511
+ data: PaginationData<Video> | null
512
+ }
513
+
514
+
515
+ # Deprecations
516
+ - Video.url will be removed in version 3.0.0, use Video.uri attribute instead
517
+ - Video.cover will be removed in version 3.0.0, use Video.assets attribute instead