@tivio/sdk-react 3.6.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md.bak CHANGED
@@ -1,7 +1,53 @@
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
+ * v4.0.0
10
+ * minor: Types cleanup
11
+ * MAJOR: Remove deprecated and unused stuff
12
+ * auth
13
+ * changePassword
14
+ * changeUserPhoto
15
+ * removeUserPhoto
16
+ * getPurchasedVodsWithInitializedVideos
17
+ * initializeUser
18
+ * createFreePurchase
19
+ * components
20
+ * VideoAdBanner
21
+ * getters
22
+ * getExportedConfig
23
+ * getChannelById
24
+ * getSectionById
25
+ * getWidgetById
26
+ * hooks
27
+ * useLastVideoByWidgetId
28
+ * useScreen
29
+ * useFreePurchase
30
+ * useWidget
31
+ * useChannel
32
+ * useSection
33
+ * useVideosInSection
34
+ * useSectionsInChannel
35
+ * useChannelsInWidget
36
+ * subscriptions
37
+ * subscribeToWidget
38
+ * subscribeToChannel
39
+ * subscribeToSection
40
+ * subscribeToVideosInSection
41
+ * subscribeToSectionsInChannel
42
+ * subscribeToChannelsInWidget
43
+ * subscribeToScreen
44
+
45
+ * v3.7.0
46
+ * minor: purchase contains created and updated
47
+
48
+ * v3.6.3
49
+ * patch: improve README.md
50
+
5
51
  * v3.6.2
6
52
  * patch: Fix types
7
53
 
@@ -185,46 +231,51 @@ await setUser('userId', { token: 'xxx'})
185
231
  await setUser(null)
186
232
  ```
187
233
 
188
- ## Tivio widget
234
+ ## Player
189
235
 
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/)):
236
+ You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player
237
+ with the Tivio Player Wrapper.
192
238
 
193
- ``` javascript
194
- import { TivioWidget } from '@tivio/sdk-react'
239
+ ### Tivio Player component
195
240
 
196
- function Screen() {
197
- return (
198
- <TivioWidget id="theWidgetId" />
199
- )
200
- }
201
- ```
241
+ ```javascript
242
+ import { useTivioData } from '@tivio/sdk-react'
202
243
 
203
- ### Usage with smart TV navigation (focus control)
244
+ const PlayerExample = () => {
245
+ const bundle = useTivioData()
204
246
 
205
- ``` javascript
206
- import { TivioWidget, TivioWidgetRef } from '@tivio/sdk-react'
207
-
208
- function Screen() {
209
- const ref = useRef<TivioWidgetRef>(null)
247
+ if (!bundle?.components?.WebPlayer) {
248
+ return <p>Loading...</p>
249
+ }
210
250
 
211
251
  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>
252
+ <>
253
+ <div
254
+ style={{
255
+ height: 720,
256
+ width: 1280,
257
+ }}
258
+ >
259
+ <bundle.components.WebPlayer
260
+ id="player1"
261
+ className="web-player"
262
+ source="/videos/xxxxxxxxxxxxxxxxxxxx" // dynamically change this based on video you want to play
263
+ />
264
+ </div>
265
+ </>
217
266
  )
218
267
  }
219
268
  ```
220
269
 
221
- ## Player wrapper
270
+ ### Player wrapper
222
271
 
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.
272
+ Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start
273
+ using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods
274
+ instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
224
275
 
225
- ### Wrap your player methods with Tivio player wrapper
276
+ #### Wrap your player methods with Tivio player wrapper
226
277
 
227
- ``` javascript
278
+ ```javascript
228
279
  import { useTivioReadyData } from '@tivio/sdk-react'
229
280
 
230
281
  function CustomPlayer() {
@@ -256,9 +307,9 @@ function CustomPlayer() {
256
307
  }
257
308
  ```
258
309
 
259
- ### Start using Tivio player wrapper methods to control playback
310
+ #### Start using Tivio player wrapper methods to control playback
260
311
 
261
- ``` javascript
312
+ ```javascript
262
313
  // Channel source metadata, such as channel name, epg start and epg end are necessary
263
314
  // for TV ad segment detection and application of ad strategies
264
315
  const source = new ChannelSource(
@@ -292,9 +343,9 @@ function CustomPlayer() {
292
343
  }
293
344
  ```
294
345
 
295
- ### Start reporting player events to Tivio
346
+ #### Start reporting player events to Tivio
296
347
 
297
- ``` javascript
348
+ ```javascript
298
349
  // Report that source is playing
299
350
  playerWrapper.onStateChanged('playing')
300
351
 
@@ -310,9 +361,9 @@ function CustomPlayer() {
310
361
  }
311
362
  ```
312
363
 
313
- ### Start reporting playback-related errors to Tivio
364
+ #### Start reporting playback-related errors to Tivio
314
365
 
315
- ``` javascript
366
+ ```javascript
316
367
  // Report that video failed to load (e.g. due to a wrong URI)
317
368
  playerWrapper.onLoadError(new Error('video failed to load'))
318
369
 
@@ -322,87 +373,46 @@ function CustomPlayer() {
322
373
  }
323
374
  ```
324
375
 
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
376
  ## Data hooks
361
377
 
362
- If you don't want to use TivioWidget, you can implement your own UI using React data hooks.
378
+ ### useUser hook
379
+ Gets information about current user.
363
380
 
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;
381
+ ```ts
382
+ useUser: () => {
383
+ user: User | null
384
+ error: string | null
385
+ isInitialized: boolean
376
386
  }
377
387
  ```
378
388
 
379
- ### useChannel hook
380
-
381
- Gets Channel object and subscribes to its changes.
389
+ ### useRowsInScreen hook
390
+ Gets array of Rows objects of specific screen and subscribes to its changes.
382
391
 
383
- ``` javascript
392
+ ```ts
384
393
  /**
385
- * Use channel
386
- * @param channelId - channel id
394
+ * Use rows in screen
395
+ * @param screenId - screen id (from studio.tiv.io)
396
+ * @param options - subscription options
387
397
  */
388
- useChannel: (channelId: string) => {
389
- error: string | null;
390
- data: Channel | null;
398
+ useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
399
+ pagination: PaginationInterface<Row> | null
400
+ error: Error | null
391
401
  }
392
402
  ```
393
403
 
394
- ### useSection hook
395
-
396
- Gets Section object and subscribes to its changes.
404
+ ### useItemsInRow hook
405
+ Gets array of row items objects of specific row and subscribes to its changes.
397
406
 
398
- ``` javascript
407
+ ```ts
399
408
  /**
400
- * Use section
401
- * @param sectionId - section id
409
+ * Use row items
410
+ * @param rowId - row ID
411
+ * @param options - subscription options
402
412
  */
403
- useSection: (sectionId: string) => {
404
- error: string | null;
405
- data: Section | null;
413
+ useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
414
+ pagination: PaginationInterface<ItemsInRow> | null
415
+ error: Error | null
406
416
  }
407
417
  ```
408
418
 
@@ -410,7 +420,7 @@ useSection: (sectionId: string) => {
410
420
 
411
421
  Gets Video object and subscribes to its changes.
412
422
 
413
- ``` javascript
423
+ ```ts
414
424
  /**
415
425
  * Use video
416
426
  * @param videoId - video id
@@ -421,139 +431,18 @@ useVideo: (videoId: string) => {
421
431
  }
422
432
  ```
423
433
 
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.
434
+ ### useTaggedVideos hook
435
+ Gets videos with given tag IDs.
546
436
 
547
437
  ```ts
548
438
  /**
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
439
+ * Use tagged videos
440
+ * @param tagIds - tag ids
441
+ * @param options - subscription options
442
+ * @public
554
443
  */
555
- useTaggedItems: (tagIds: string[], {limit?: number, noLimit?: boolean, fecthTags?: boolean}) => {
444
+ useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
445
+ pagination: PaginationInterface<Video> | null
556
446
  error: Error | null
557
- data: PaginationData<Video> | null
558
447
  }
559
448
  ```