@tivio/sdk-react 3.6.2 → 3.6.3

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # @tivio/sdk-react
2
2
 
3
+ @tivio/sdk-react provides everything which is necessary (components, data hooks etc.) to build a custom React application
4
+ above Tivio Studio. You can comfortably manage all you videos, settings such as application's screens and rows and also monetization
5
+ settings in the administration of Tivio Studio while having the freedom to build your own application.
6
+
3
7
  ## Changelog
4
8
 
9
+ * v3.6.3
10
+ * patch: improve README.md
11
+
5
12
  * v3.6.2
6
13
  * patch: Fix types
7
14
 
@@ -185,46 +192,51 @@ await setUser('userId', { token: 'xxx'})
185
192
  await setUser(null)
186
193
  ```
187
194
 
188
- ## Tivio widget
195
+ ## Player
189
196
 
190
- Tivio widget is the main Tivio component which shows the widget and provides access to its channels, sections and videos.
191
- Usage is very simple (be sure to set `id` to the widget ID you have configured in [Tivio Studio](https://studio.tiv.io/)):
197
+ You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player
198
+ with the Tivio Player Wrapper.
192
199
 
193
- ``` javascript
194
- import { TivioWidget } from '@tivio/sdk-react'
200
+ ### Tivio Player component
195
201
 
196
- function Screen() {
197
- return (
198
- <TivioWidget id="theWidgetId" />
199
- )
200
- }
201
- ```
202
+ ```javascript
203
+ import { useTivioData } from '@tivio/sdk-react'
202
204
 
203
- ### Usage with smart TV navigation (focus control)
205
+ const PlayerExample = () => {
206
+ const bundle = useTivioData()
204
207
 
205
- ``` javascript
206
- import { TivioWidget, TivioWidgetRef } from '@tivio/sdk-react'
207
-
208
- function Screen() {
209
- const ref = useRef<TivioWidgetRef>(null)
208
+ if (!bundle?.components?.WebPlayer) {
209
+ return <p>Loading...</p>
210
+ }
210
211
 
211
212
  return (
212
- <TivioWidget id="theWidgetId" ref={ref} onBlur={() => {/* widget lost focus */}}/>
213
- <div>
214
- <button onClick={() => ref.current?.focus({ x: 100 })}>Focus</button>
215
- <button onClick={() => ref.current?.unfocus()}>Unfocus</button>
216
- </div>
213
+ <>
214
+ <div
215
+ style={{
216
+ height: 720,
217
+ width: 1280,
218
+ }}
219
+ >
220
+ <bundle.components.WebPlayer
221
+ id="player1"
222
+ className="web-player"
223
+ source="/videos/xxxxxxxxxxxxxxxxxxxx" // dynamically change this based on video you want to play
224
+ />
225
+ </div>
226
+ </>
217
227
  )
218
228
  }
219
229
  ```
220
230
 
221
- ## Player wrapper
231
+ ### Player wrapper
222
232
 
223
- 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.
233
+ Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start
234
+ using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods
235
+ instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
224
236
 
225
- ### Wrap your player methods with Tivio player wrapper
237
+ #### Wrap your player methods with Tivio player wrapper
226
238
 
227
- ``` javascript
239
+ ```javascript
228
240
  import { useTivioReadyData } from '@tivio/sdk-react'
229
241
 
230
242
  function CustomPlayer() {
@@ -256,9 +268,9 @@ function CustomPlayer() {
256
268
  }
257
269
  ```
258
270
 
259
- ### Start using Tivio player wrapper methods to control playback
271
+ #### Start using Tivio player wrapper methods to control playback
260
272
 
261
- ``` javascript
273
+ ```javascript
262
274
  // Channel source metadata, such as channel name, epg start and epg end are necessary
263
275
  // for TV ad segment detection and application of ad strategies
264
276
  const source = new ChannelSource(
@@ -292,9 +304,9 @@ function CustomPlayer() {
292
304
  }
293
305
  ```
294
306
 
295
- ### Start reporting player events to Tivio
307
+ #### Start reporting player events to Tivio
296
308
 
297
- ``` javascript
309
+ ```javascript
298
310
  // Report that source is playing
299
311
  playerWrapper.onStateChanged('playing')
300
312
 
@@ -310,9 +322,9 @@ function CustomPlayer() {
310
322
  }
311
323
  ```
312
324
 
313
- ### Start reporting playback-related errors to Tivio
325
+ #### Start reporting playback-related errors to Tivio
314
326
 
315
- ``` javascript
327
+ ```javascript
316
328
  // Report that video failed to load (e.g. due to a wrong URI)
317
329
  playerWrapper.onLoadError(new Error('video failed to load'))
318
330
 
@@ -322,87 +334,46 @@ function CustomPlayer() {
322
334
  }
323
335
  ```
324
336
 
325
- ## Tivio DOM events
326
-
327
- `TivioWidget` triggers these events on `window.document`.
328
-
329
- 1. To instruct the parent app to navigate to and focus a specific TivioWidget (e.g. after going back from a Tivio screen)
330
-
331
- ```typescript
332
- document.addEventListener("tivio_request_goto", e => {
333
- e.detail.widgetId; // string - Tivio widget ID to go navigate to in UI
334
- });
335
- ```
336
- 2. To notify the parent app about context switch, i.e. where is the user located or what is he focusing
337
-
338
- ```typescript
339
- document.addEventListener("tivio_context_switch", e => {
340
- e.detail.context; // 'tivio' | 'parent' - where is the user located? - in Tivio or in parent app
341
-
342
- // For context Tivio there are additional fields
343
- e.detail.context; // 'tivio'
344
- e.detail.contextLocation; // 'route' | 'overlay' | 'widget' - where in Tivio is the user located?
345
- // - on a Tivio route, in parent app but looking at a full screen Tivio overlay,
346
- // or in parent app and focus is on a Tivio widget
347
-
348
- // For context Tivio contextLocation 'widget' there is an additional field of widget ID
349
- e.detail.widgetId; // string - which Tivio widget is focused right now
350
- });
351
- ```
352
- 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.
353
-
354
- ```typescript
355
- document.addEventListener("tivio_key_input_handling_change", e => {
356
- e.detail.inputHandler; // 'tivio' | 'parent' - who should be handling RC input? - Tivio or parent app
357
- });
358
- ```
359
-
360
337
  ## Data hooks
361
338
 
362
- If you don't want to use TivioWidget, you can implement your own UI using React data hooks.
339
+ ### useUser hook
340
+ Gets information about current user.
363
341
 
364
- ### useWidget hook
365
-
366
- Gets Widget object and subscribes to its changes.
367
-
368
- ``` javascript
369
- /**
370
- * Use widget
371
- * @param widgetId - widget id
372
- */
373
- useWidget: (widgetId: string) => {
374
- error: string | null;
375
- data: Widget | null;
342
+ ```ts
343
+ useUser: () => {
344
+ user: User | null
345
+ error: string | null
346
+ isInitialized: boolean
376
347
  }
377
348
  ```
378
349
 
379
- ### useChannel hook
380
-
381
- Gets Channel object and subscribes to its changes.
350
+ ### useRowsInScreen hook
351
+ Gets array of Rows objects of specific screen and subscribes to its changes.
382
352
 
383
- ``` javascript
353
+ ```ts
384
354
  /**
385
- * Use channel
386
- * @param channelId - channel id
355
+ * Use rows in screen
356
+ * @param screenId - screen id (from studio.tiv.io)
357
+ * @param options - subscription options
387
358
  */
388
- useChannel: (channelId: string) => {
389
- error: string | null;
390
- data: Channel | null;
359
+ useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
360
+ pagination: PaginationInterface<Row> | null
361
+ error: Error | null
391
362
  }
392
363
  ```
393
364
 
394
- ### useSection hook
395
-
396
- Gets Section object and subscribes to its changes.
365
+ ### useItemsInRow hook
366
+ Gets array of row items objects of specific row and subscribes to its changes.
397
367
 
398
- ``` javascript
368
+ ```ts
399
369
  /**
400
- * Use section
401
- * @param sectionId - section id
370
+ * Use row items
371
+ * @param rowId - row ID
372
+ * @param options - subscription options
402
373
  */
403
- useSection: (sectionId: string) => {
404
- error: string | null;
405
- data: Section | null;
374
+ useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
375
+ pagination: PaginationInterface<ItemsInRow> | null
376
+ error: Error | null
406
377
  }
407
378
  ```
408
379
 
@@ -410,7 +381,7 @@ useSection: (sectionId: string) => {
410
381
 
411
382
  Gets Video object and subscribes to its changes.
412
383
 
413
- ``` javascript
384
+ ```ts
414
385
  /**
415
386
  * Use video
416
387
  * @param videoId - video id
@@ -421,139 +392,18 @@ useVideo: (videoId: string) => {
421
392
  }
422
393
  ```
423
394
 
424
- ### useChannelsInWidget hook
425
-
426
- Gets array of Channel objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
427
- for pagination (returned in `data` object).
428
-
429
- ``` javascript
430
- /**
431
- * Use channels in widget
432
- * @param widgetId - widget id
433
- * @param [limit] - channels count, defaults to 10
434
- */
435
- useChannelsInWidget: (widgetId: string, limit?: number) => {
436
- error: string | null;
437
- data: PaginationData<Channel> | null;
438
- }
439
- ```
440
-
441
- ### useSectionsInChannel hook
442
-
443
- Gets array of Section objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
444
- for pagination (returned in `data` object).
445
-
446
- ``` javascript
447
- /**
448
- * Use section in channel
449
- * @param channelId - channel id
450
- * @param [limit] - sections count, defaults to 10
451
- */
452
- useSectionsInChannel: (channelId: string, limit?: number) => {
453
- error: string | null;
454
- data: PaginationData<Section> | null;
455
- }
456
- ```
457
-
458
- ### useVideosInSection hook
459
-
460
- Gets array of Video objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
461
- for pagination (returned in `data` object).
462
-
463
- ``` javascript
464
- /**
465
- * Use videos in section
466
- * @param sectionId - section id
467
- * @param [limit] - videos count, defaults to 10
468
- */
469
- useVideosInSection: (sectionId: string, limit?: number) => {
470
- error: string | null;
471
- data: PaginationData<Video> | null;
472
- }
473
- ```
474
-
475
- ### useScreen hook
476
- Gets Screen object and subscribes to its changes.
477
-
478
- ```ts
479
- /**
480
- * Hook to fetch an app screen
481
- * @param screenId - screen ID configured via studio.tiv.io
482
- */
483
- useScreen: (screenId: string) => {
484
- error: Error | null
485
- data: Screen | null
486
- }
487
-
488
- // Example:
489
- // Screens with their screenIds are configured via studio.tiv.io
490
- const screenId = '890sdfvxoi'
491
- const { error, data } = useScreen(screenId)
492
-
493
- if (data) {
494
- const screenName = data.name
495
- const screenRows = data.rows
496
- // ...
497
- }
498
- ```
499
-
500
- ### useItemsInRow hook
501
-
502
- Gets array of Video or Tag objects for a specified row. It is possible to use
503
- `hasNextPage` and `fetchMore` for pagination (returned in `data` object).
504
-
505
- *(Note: Does not subscribe to changes in video objects, in order to refresh data it is necessary to reload the app.)*
506
-
507
- ```ts
508
- /**
509
- * Hook to fetch row items for rows received from `useScreen()`
510
- * @param id - row ID configured via studio.tiv.io
511
- * @param options.limit - items limit
512
- * @param options.noLimit - disable/enable pagination (will fetch all items)
513
- * @param options.fecthTags - disable/enable tags fetching
514
- */
515
- useItemsInRow: (id: string, options: {limit?: number, noLimit?: boolean, fecthTags?: boolean}) => {
516
- error: Error | null
517
- data: PaginationData<Video | Tag> | null
518
- isLoading: boolean
519
- }
520
-
521
- // Example:
522
- // Rows and their row ID can be loaded using useScreen() hook
523
- const Row = ({ id }: { id: string}) => {
524
- const rowData = useItemsInRow(id, 10)
525
-
526
- return <div>
527
- <div>Row id: {id}</div>
528
- Count: ({rowData.data?.items.length})
529
- <div>
530
- {rowData.isLoading && <div>Loading...</div>}
531
- {rowData.data?.items.map(item => (
532
- <div>
533
- <div>{item.name}</div>
534
- <img src={item.cover} alt={item.name} />
535
- </div>
536
- ))}
537
- </div>
538
- <button onClick={() => rowData.data?.fetchMore()}>more</button>
539
- </div>
540
- }
541
- ```
542
-
543
- ### useTaggedItems hook
544
-
545
- Allows to fetch videos with given tags.
395
+ ### useTaggedVideos hook
396
+ Gets videos with given tag IDs.
546
397
 
547
398
  ```ts
548
399
  /**
549
- * Hook to fetch row items for rows received from `useScreen()`
550
- * @param id - row ID configured via studio.tiv.io
551
- * @param options.limit - items limit
552
- * @param options.noLimit - disable/enable pagination (will fetch all items)
553
- * @param options.fecthTags - disable/enable tags fetching
400
+ * Use tagged videos
401
+ * @param tagIds - tag ids
402
+ * @param options - subscription options
403
+ * @public
554
404
  */
555
- useTaggedItems: (tagIds: string[], {limit?: number, noLimit?: boolean, fecthTags?: boolean}) => {
405
+ useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
406
+ pagination: PaginationInterface<Video> | null
556
407
  error: Error | null
557
- data: PaginationData<Video> | null
558
408
  }
559
409
  ```