@tivio/sdk-react 9.2.0-alpha.3 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md.bak CHANGED
@@ -4,315 +4,6 @@
4
4
  above Tivio Studio. You can comfortably manage all you videos, settings such as application's screens and rows and also monetization
5
5
  settings in the administration of Tivio Studio while having the freedom to build your own application.
6
6
 
7
- ## Changelog
8
- * 9.2.0-alpha.0
9
- * minor: add renderWebPlayer method for rendering outside of React
10
- * minor: "expose createTivio"
11
-
12
- * 9.1.7
13
- * patch: update remote controller component API
14
-
15
- * 9.1.6
16
- * minor: add remote controller
17
-
18
- * 9.1.5
19
- * patch: expose purchase loyalty points through types
20
- * patch: enable setUser check
21
-
22
- * 9.1.4
23
- * patch: disable setUser check
24
- * patch: rollback "add renderWebPlayer method for rendering outside of React"
25
- * patch: rollback "expose createTivio"
26
-
27
- * 9.1.3
28
- * patch: add renderWebPlayer method for rendering outside of React
29
- * patch: expose createTivio
30
-
31
- * 9.1.4
32
- * patch: disable setUser check
33
-
34
- * 9.1.3
35
- * minor: add renderWebPlayer method for rendering outside of React
36
- * minor: expose createTivio
37
-
38
- * 9.1.2
39
- * patch: update PurchaseEndpointPayload type (cityName, externalId, geoPoint)
40
-
41
- * 9.1.1
42
- * patch: fix changelog
43
-
44
- * 9.1.0
45
- * patch: add gateway to Purchase type
46
- * minor: add QerkoPaymentWebhookByApiKeyRequest to exported types
47
-
48
- * 9.0.0
49
- * patch: remove i18next and react-i18next from externals and dependencies
50
- * patch: do not send react-spring to core-react-dom bundle, remove react-spring from dependencies
51
- * patch: clean-up externals in webpack config
52
- * patch: send only required dependencies to the bundle
53
- * major: change purchase statuses lifecycle
54
- * minor: add originalPurchaseId to PurchaseEndpointPayload
55
-
56
- * 8.0.0
57
- * major: deprecated usePurchasesWithVideos hook removed
58
- * patch: add id to user type
59
- * patch: add @types/react to peerDependencies
60
-
61
- * 7.1.0
62
- * minor: export useTvChannelHook
63
- * patch: bump "react-i18next", "i18next" versions.
64
-
65
- * 7.0.1
66
- * patch: fix dependency to @tivio/common
67
-
68
- * 7.0.0
69
- * major: delete deprecated useWatchWithoutAdsOffer hook
70
- * major: consolidate duplicated source types
71
- * patch: add new properties to PlayerInterface
72
- * patch: expose getSeekingMatrixPreviewByTime in Video interface
73
- * major: delete deprecated useBetOffer hook
74
- * major: rework of source types
75
- * major: make useChannelSource deprecated
76
-
77
- * 6.0.1
78
- * patch: fix dependency to @tivio/common
79
-
80
- * 6.0.0
81
- * major: delete usePlayerEvent hook
82
- * major: replace uri attributes in types with url
83
- * major: delete uri attributes from types
84
- * minor: add purchase expiration to PurchaseEndpointPayload
85
- * minor: add optional videoId parameter to useOrganizationSubscription hook
86
-
87
- * 5.0.2
88
- * patch: export hook useChannelSource
89
-
90
- * 5.0.1
91
- * patch: move changelog
92
-
93
- * 5.0.0
94
- * major: upgrade to React 18, change react and react-dom peer dependencies to 17.x || 18.x
95
- * major: fix typing for useReferralInfo, now correctly showing that `null` can be returned
96
- * major: fix typing for `WebRowProps.onTileClick`, now correctly showing that `null` can be accepted
97
- * minor: add analytics
98
- * minor: add getSourceUrl function to video and tv channel types
99
- * minor: add uri property to tv channel type
100
- * minor: add useChannelSource to hooks
101
-
102
- * 4.5.0
103
- * minor: extend PurchaseEndpointPayload type with purchase previousStatus and newStatus fields
104
-
105
- * 4.4.1
106
- * patch: added waitForTags param in useSearch hook for videos
107
-
108
- * 4.4.0
109
- * minor: PrimaryButton component props type set to any for now
110
- * patch: isPurchasableAsVoucher added to PurchasableMonetization
111
- * patch: voucherPurchase flag added to purchase overlays
112
- * patch: item added to MonetizationsSelectOverlayData
113
- * minor: added hungarian language to `LangCode` enum
114
-
115
- * 4.3.0:
116
- * minor: add GetPurchaseInfoResponse and PurchaseEndpointPayload to exported types
117
- * minor: support for disabling purchase of specified subscriptions (new param in useOrganizationSubscriptions hook)
118
- * minor: more specific PurchasableMonetization type usage instead of Monetization
119
- * minor: monetization property deleted from Video type
120
- * minor: monetization now has originalPrice and promotion properties available
121
- * patch: remove not used OrganizationSubscriptionsContext, **this change requires bundle 3.20.0 or newer**
122
-
123
- * 4.2.0:
124
- * minor: fix useSearch loading type
125
- * patch: added italian language to `LangCode` enum
126
-
127
- * 4.1.0
128
- * patch: added italian language to `LangCode` enum
129
- * minor: fixed spanish language code in `LangCode` enum (`sp` -> `es`)
130
- * minor: other misc type changes
131
-
132
- * 4.0.1
133
- * patch: added setBundleVersion setter to bundle type
134
- * patch: added setStorageManager setter to bundle type
135
- * patch: `Purchase.isPurchased` is deprecated
136
- * patch: fill `useSearch` field `hasNextPage` with proper value
137
-
138
- * 4.0.0
139
- * minor: Types cleanup
140
- * MAJOR: Remove deprecated and unused stuff
141
- * auth
142
- * changePassword
143
- * changeUserPhoto
144
- * removeUserPhoto
145
- * getPurchasedVodsWithInitializedVideos
146
- * initializeUser
147
- * createFreePurchase
148
- * components
149
- * videoAdBanner
150
- * getters
151
- * getExportedConfig
152
- * getChannelById
153
- * getSectionById
154
- * getWidgetById
155
- * hooks
156
- * useLastVideoByWidgetId
157
- * useScreen
158
- * useFreePurchase
159
- * useWidget
160
- * useChannel
161
- * useSection
162
- * useVideosInSection
163
- * useSectionsInChannel
164
- * useChannelsInWidget
165
- * subscriptions
166
- * subscribeToWidget
167
- * subscribeToChannel
168
- * subscribeToSection
169
- * subscribeToVideosInSection
170
- * subscribeToSectionsInChannel
171
- * subscribeToChannelsInWidget
172
- * subscribeToScreen
173
- ---
174
- _Versions <= v3.7.0 requires core-react-dom bundle < v3.0.0 (because sdk-react used some sdk API deleted in core-react-dom@4.0.0)_
175
-
176
- * 3.7.0
177
- * minor: purchase contains created and updated
178
-
179
- * 3.6.3
180
- * patch: improve README.md
181
-
182
- * 3.6.2
183
- * patch: Fix types
184
-
185
- * 3.6.1
186
- * patch: Fix README
187
-
188
- * 3.6.0
189
- * minor: Update types
190
-
191
- * 3.5.2
192
- * patch: All types are available again.
193
-
194
- * 3.5.1
195
- * patch: remove incorrect dependency (@tivio/types)
196
-
197
- * 3.5.0
198
- * minor: Types change - Video.price and Video.detailedPrice can be null
199
- * minor: Types change - Video.cover is marked as deprecated
200
-
201
- * 3.4.0
202
- * minor: more precise type for errors in usePurchaseRecovery and usePurchaseRecovery
203
- * patch: jsdocs for usePurchaseRecovery and usePurchaseRecovery
204
- * minor: inviteCodeReset in useApplyInviteCode
205
- * minor: Reset forgotten password
206
- * minor: Consolidating monetization logic
207
- * 3.3.2
208
- * patch: Adding new optional parameters (where, orderBy) to useTaggedVideos hook
209
- * 3.3.1
210
- * patch: Fixed types of `setUser`
211
- * 3.3.0
212
- * minor: Add getPlayerCapabilities to getters.
213
- * patch: Added option to log out via `setUser(null)`, requires @tivio/core-react-dom@2.17.9
214
- * 3.2.5
215
- * patch: added recovery flag to QerkoPaymentInfo type
216
- * patch: bundle.types changes - internal.components.WebVideoScreen
217
- * patch: types changes - add new onBack prop to WebPlayerProps
218
- * patch: Refactor useVideo hook, now uses hook from core-react
219
- * 3.2.4
220
- * minor: added useApplyInviteCode
221
- * minor: better errors from useVoucher
222
- * 3.2.3
223
- * minor: added usePurchaseRecovery hook
224
- * patch: deprecated `useLastVideoByWidgetId`
225
- * 3.2.2
226
- * minor: useRowsInScreen, useItemsInRow, useTaggedVideos - hasNextPage and loading added to pagination
227
- * minor: useRowsInScreen, useItemsInRow, useTaggedVideos - implementation moved to remote bundle
228
- * patch: Fixed Tivio startup on Tizen 6
229
- * minor: Added `forceCloudFnResolver` option
230
- * 3.2.1
231
- * patch: fix of @tivio/common version
232
- * 3.2.0
233
- * minor: Added `capabilitiesOptions` for finer configuration of device capabilities
234
- * minor: tag names are returned in correct language (the one from tivio config); language value should be one from enum "LangCode"
235
- * 3.1.3
236
- * patch: Hotfix made sure disabled Tivio does not break React Native
237
- * 3.1.2
238
- * patch: Allow `conf` prop of `TivioProvider` to be `null` or `undefined` in order to turn off Tivio
239
- * 3.1.1
240
- * patch: fixed `setUser()` crash when bundle fails to load
241
- * 3.1.0
242
- * patch: `useAdSegment()` now returns null if no monetization is configured, ad segments are not managed in that situation
243
- * minor: enriched `AdSegment` type from `useAdSegment()`
244
- * minor: Added `setUser()` function for login and logout
245
- * 3.0.0
246
- * minor: Added hook `useWatchWithoutAdsOffer` to trigger purchase dialog to "watch without ads", if available
247
- * patch: fix peerDependency declaration for react, react-dom
248
- * major: TivioProvider requires deviceCapabilities
249
- * major: TivioProvider requires currency
250
- * minor: add voucher support (see usePurchaseSubscription and useTransactionPayment hooks)
251
- * minor: device limit support
252
- * minor: drm (Widevine, PlayReady) support
253
- * minor: watermarking support
254
- * minor: add useSearch hook
255
- * patch: price on video is 0 when purchased
256
- * 2.4.2
257
- * patch: added back changelog
258
- * 2.4.1
259
- * patch: improved doc about player wrapper
260
- * 2.4.0
261
- * patch: improved Player wrapper types
262
- * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
263
- * 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)
264
- * patch: added support for browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
265
- * 2.3.4
266
- * patch: fix of usePurchaseSubscription not reactive
267
- * 2.3.3
268
- * patch: fix of useUser not updating
269
- * 2.3.2
270
- * patch: next app doesn't fail anymore due to "self is not defined"
271
- * 2.3.1
272
- * patch: fix of @tivio/common dependency
273
- * 2.3.0
274
- * minor: add useTaggedVideos that allows to fetch videos with given tags
275
- * minor: add option to fetch tags (on hook useItemsInRow), useVideo always fetching videos tags
276
- * 2.2.1
277
- * patch: disable Sentry when no config is supplied to `TivioProvider`
278
- * 2.2.0
279
- * patch: reduced bundle size
280
- * 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 }`
281
- * 2.1.5
282
- * patch fix of `useVideosInSection` hook (fetching video's monetizations)
283
- * 2.1.4
284
- * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react-dom@2.1.9)
285
- * 2.1.3
286
- * patch: fix changelog
287
- * 2.1.2
288
- * patch: Fixed exported types
289
- * 2.1.1
290
- * patch: TivioWidget now correctly reports `false` via `onEnabled` callback when in invalid internal state
291
- * 2.1.0
292
- * patch: fix of useItemsInRow hook
293
- * patch: fix of useScreen hook
294
- * add: useRowsInScreen hook
295
- * 2.0.3
296
- * patch: fix of useItemsInRow hook
297
- * 2.0.2
298
- * patch: screen and row IDs fixed
299
- * `TivioBundle.subscriptions.subscribeToItemsInRow` now accepts user-defined ID via studio.tiv.io
300
- * `TivioBundle.subscriptions.subscribeToScreen` now accepts user-defined ID via studio.tiv.io
301
- * `Screen` and `Row` types returned by `useScreen()` return their user-defined IDs (`.id`) correctly
302
- * 2.0.1
303
- * no changes
304
- * 2.0.0
305
- * major: video.channelId can now be `string | null` used to be `string`
306
- * minor: added data API and hooks for screens (screens, rows of screen and row items)
307
- * hooks: `useScreen()`, `useItemsInRow()`
308
- * api: `TivioBundle.subscriptions.subscribeToScreen`, `TivioBundle.subscriptions.subscribeToItemsInRow`
309
- * 1.3.6
310
- * ?
311
- * 1.3.5
312
- * minor: added WebPlayer props (canReplay, showMarkers, customShortcuts, enableKeyboardShortcuts, source.poster)
313
- * 1.3.4
314
- * ...
315
-
316
7
  ## Installation
317
8
 
318
9
  Install @tivio/sdk-react along with its peer dependencies
@@ -503,9 +194,266 @@ function CustomPlayer() {
503
194
  }
504
195
  ```
505
196
 
506
- ## Data hooks
197
+ ## JavaScript Methods for Rendering Players
198
+
199
+ ### renderWebPlayer
200
+
201
+ The `renderWebPlayer` method allows you to render a Tivio player outside of React components. This is useful for scenarios where you need to integrate the player into non-React environments.
202
+
203
+ The method is asynchronous and returns a VideoController instance that provides comprehensive control over playback.
204
+
205
+ ```typescript
206
+ import { renderWebPlayer } from '@tivio/sdk-react'
207
+
208
+ // Example usage
209
+ const videoController = await renderWebPlayer(
210
+ document.getElementById('video-player'),
211
+ {
212
+ id: 'player-main',
213
+ source: 'videos/ID',
214
+ }
215
+ )
216
+
217
+ // Control playback
218
+ videoController.play()
219
+ videoController.pause()
220
+ videoController.togglePause()
221
+
222
+ // Seeking
223
+ videoController.seekToAbsolutePosition(30000) // Seek to 30 seconds
224
+ videoController.seekBy(5000) // Seek forward by 5 seconds
225
+ videoController.seekToPercent(50) // Seek to 50% of video
226
+ videoController.seekToLive() // Seek to live position (for live streams)
227
+
228
+ // Volume control
229
+ videoController.changeVolume(0.8) // Set volume to 80%
230
+ videoController.volumeUp() // Increase volume by 5%
231
+ videoController.volumeDown() // Decrease volume by 5%
232
+ videoController.mute()
233
+ videoController.unmute()
234
+ videoController.toggleMute()
235
+
236
+ // Get current source
237
+ console.log('Current source:', videoController.currentSource)
238
+
239
+ // Change source
240
+ videoController.setSource('videos/newVideoId') // Change to a different video
241
+ videoController.setSource('tvChannels/channelId') // Change to a TV channel
242
+ videoController.setSource(null) // Stop playback
243
+
244
+ // Event handling
245
+ videoController.addEventListener('video_unit_ended', () => {
246
+ console.log('Video playback ended')
247
+ })
248
+
249
+ videoController.addEventListener('timeupdate', (currentTime) => {
250
+ console.log('Current time:', currentTime)
251
+ })
252
+
253
+ // Cleanup
254
+ videoController.destroy()
255
+ ```
256
+
257
+ #### VideoController Methods
258
+
259
+ The VideoController returned by `renderWebPlayer` provides the following methods:
260
+
261
+ **Playback Control:**
262
+ - `play()` - Resume playback from paused state
263
+ - `pause()` - Pause the current playback
264
+ - `togglePause()` - Toggle between play and pause states
265
+ - `replay()` - Replay the current video from the beginning
266
+ - `retry()` - Retry playback if it failed to start
267
+
268
+ **Seeking:**
269
+ - `seekToAbsolutePosition(ms: number)` - Seek to absolute position in milliseconds
270
+ - `seekBy(ms: number)` - Seek relative to current position
271
+ - `seekToPercent(percentage: number)` - Seek to percentage of video duration
272
+ - `seekToLive()` - Seek to live position (for live streams)
273
+
274
+ **Volume Control:**
275
+ - `changeVolume(value: number)` - Set volume (0-1)
276
+ - `volumeUp()` - Increase volume by 5%
277
+ - `volumeDown()` - Decrease volume by 5%
278
+ - `mute()` - Mute audio
279
+ - `unmute()` - Unmute audio
280
+ - `toggleMute()` - Toggle mute state
281
+
282
+ **Source Management:**
283
+ - `setSource(source: WebPlayerProps['source'])` - Change the current source to a new one (updates player props)
284
+ - `currentSource` - Currently playing source or null if no source is loaded
285
+
286
+ #### Source Types
287
+
288
+ The Tivio player supports different types of sources:
289
+
290
+ **VOD_EXTERNAL** - External video-on-demand content from third-party URLs
291
+ - Used for playing videos that are hosted outside of Tivio's infrastructure
292
+ - Supports various streaming protocols (HLS, DASH, MP4)
293
+ - Example usage:
294
+ ```typescript
295
+ const externalSource = {
296
+ type: SourceType.VOD_EXTERNAL,
297
+ url: 'https://example.com/video.m3u8',
298
+ sourcePlayMode: SourcePlayMode.ON_DEMAND,
299
+ poster: 'https://example.com/poster.jpg',
300
+ name: 'External Video',
301
+ autoplay: false,
302
+ continuePositionMs: 10000, // Start at 10 seconds (optional)
303
+ }
304
+ ```
305
+
306
+ #### Source Play Modes
307
+
308
+ The `sourcePlayMode` property determines how the content is played:
309
+
310
+ - **ON_DEMAND** - Standard video playback with full seeking capabilities
311
+ - **LIVE** - Live stream mode with no seeking
312
+ - **HYBRID** - Combines LIVE with seeking
313
+
314
+ #### Using setSource with VideoController
315
+
316
+ The `setSource` method allows you to dynamically change what's playing:
317
+
318
+ ```typescript
319
+ // Change to a different video
320
+ videoController.setSource('videos/newVideoId')
321
+
322
+ // Change to an external video
323
+ videoController.setSource({
324
+ type: SourceType.VOD_EXTERNAL,
325
+ url: 'https://example.com/video.mpd',
326
+ sourcePlayMode: SourcePlayMode.ON_DEMAND,
327
+ name: 'External Video'
328
+ })
329
+
330
+ // Change to a TV channel
331
+ videoController.setSource('tvChannels/channelId')
332
+
333
+ // Stop playback
334
+ videoController.setSource(null)
335
+ ```
507
336
 
508
- ### useUser hook
337
+ The `setSource` method is particularly useful for:
338
+ - Play next
339
+ - Implementing playlists
340
+ - Dynamic content loading
341
+
342
+ **Event Handling:**
343
+ - `addEventListener(event: string, callback: (value: T) => void)` - Add event listener
344
+ - `removeEventListener(event: string, callback: (value: T) => void)` - Remove event listener
345
+
346
+ **Utility:**
347
+ - `destroy()` - Destroy player and clean up resources
348
+
349
+ #### Playback Events
350
+
351
+ The VideoController emits various events that you can listen to:
352
+
353
+ ```typescript
354
+ // Video state changes
355
+ videoController.addEventListener('statechange', (state) => {
356
+ console.log('Player state:', state) // 'playing', 'paused', 'idle'
357
+ })
358
+
359
+ // Time updates
360
+ videoController.addEventListener('timeupdate', (currentTime) => {
361
+ console.log('Current time:', currentTime)
362
+ })
363
+
364
+ // Video ended
365
+ videoController.addEventListener('video_unit_ended', () => {
366
+ console.log('Video playback ended')
367
+ })
368
+
369
+ // Duration changes
370
+ videoController.addEventListener('durationchange', (duration) => {
371
+ console.log('Video duration:', duration)
372
+ })
373
+
374
+ // Volume changes
375
+ videoController.addEventListener('volumechange', ({ muted, volume }: { muted: boolean, volume: number }) => {
376
+ console.log('Volume changed:', { muted, volume })
377
+ })
378
+
379
+ // Buffering state
380
+ videoController.addEventListener('bufferingchange', (isBuffering) => {
381
+ console.log('Buffering:', isBuffering)
382
+ })
383
+
384
+ // Errors
385
+ videoController.addEventListener('error', (error) => {
386
+ console.error('Playback error:', error)
387
+ })
388
+ ```
389
+
390
+ ## WebPlayerProps
391
+
392
+ The `WebPlayerProps` interface defines the properties that can be passed to the Tivio WebPlayer component. Here's a comprehensive overview of available properties:
393
+
394
+ ### Required Properties
395
+
396
+ - **`id`** (string): Unique identifier for the player instance. This is required and must be unique across your application.
397
+
398
+ ### Source Properties
399
+
400
+ - **`source`** (optional): The video or channel source to play. Can be:
401
+ - `VideoPath` (string): Path to a video (e.g., "videos/VIDEO_ID")
402
+ - `ChannelPath` (string): Path to a TV channel (e.g., "tvChannels/CHANNEL_ID")
403
+ - `SourceParams` (object): Complex source parameters
404
+ - `null`: No source (player will be idle)
405
+
406
+ ### Callback Properties
407
+
408
+ - **`onEnded`** (optional): Callback function called when video playback ends
409
+ - **`onProgress`** (optional): Callback function for video progress events
410
+
411
+ ### Layout Properties
412
+
413
+ - **`className`** (optional): CSS class name for the player container
414
+ - **`isSameSizeAsParent`** (optional): If `true`, the player will inherit the width and height of its parent element
415
+
416
+ ### Playback Control Properties
417
+
418
+ - **`autoplay`** (optional, default: `false`): Whether to start playback automatically. Note that autoplay may be blocked by browsers before user interaction
419
+ - **`canReplay`** (optional, default: `true`): Whether to show replay functionality
420
+ - **`doNotSaveWatchPosition`** (optional): If `true`, the player won't save the watch position
421
+ - **`disablePlayNext`** (optional): If `true`, the player won't automatically play the next video when current video ends
422
+
423
+ ### Visual Properties
424
+
425
+ - **`showMarkers`** (optional, default: `false`): Whether to show video markers
426
+ - **`markerColor`** (optional): Color for video markers (CSS color value)
427
+ - **`showTvStreamType`** (optional): Whether to show TV stream type indicator
428
+ - **`showCookiesSettings`** (optional): Whether to show cookies settings
429
+ - **`showOsd`** (optional, default: `true`): Whether to show the On-Screen Display (OSD)
430
+ - **`showBufferingSpinner`** (optional, default: `true`): Whether to show buffering spinner
431
+
432
+ ### Audio Properties
433
+
434
+ - **`isMutedByDefault`** (optional): If `true`, the player starts muted but can be unmuted
435
+
436
+ ### Keyboard Shortcuts Properties
437
+
438
+ - **`enableKeyboardShortcuts`** (optional, default: `true`): Whether to enable keyboard shortcuts
439
+ - **`customShortcuts`** (optional): Custom keyboard shortcuts configuration:
440
+ ```typescript
441
+ {
442
+ toggleFullscreen: number[], // Array of key codes
443
+ togglePause: number[],
444
+ toggleMute: number[],
445
+ jumpForward: number[],
446
+ jumpBack: number[],
447
+ volumeUp: number[],
448
+ volumeDown: number[]
449
+ }
450
+ ```
451
+
452
+ ### Ad Block Properties
453
+
454
+ - **`checkAdBlock`** (optional, default: `false`): Whether to check for ad blockers and show warnings
455
+
456
+ ## Data hooks
509
457
  Gets information about current user.
510
458
 
511
459
  ```ts