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