@tivio/sdk-react 3.0.0-alpha4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # @tivio/sdk-react
2
2
 
3
3
  ## Changelog
4
- * v3.0.0-alpha2
4
+ * UNRELEASED
5
+ *
6
+ * v3.0.0
7
+ * minor: Added hook useWatchWithoutAdsOffer to trigger purchase dialog to "watch without ads", if available
8
+ * patch: fix peerDependency declaration for react, react-dom
5
9
  * major: TivioProvider requires deviceCapabilities
6
10
  * major: TivioProvider requires currency
7
11
  * minor: add voucher support (see usePurchaseSubscription and useTransactionPayment hooks)
@@ -10,6 +14,15 @@
10
14
  * minor: watermarking support
11
15
  * minor: add useSearch hook
12
16
  * patch: price on video is 0 when purchased
17
+ * v2.4.2
18
+ * patch: added back changelog
19
+ * v2.4.1
20
+ * patch: improved doc about player wrapper
21
+ * v2.4.0
22
+ * patch: improved Player wrapper types
23
+ * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
24
+ * 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)
25
+ * patch: added support for browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
13
26
  * v2.3.4
14
27
  * patch: fix of usePurchaseSubscription not reactive
15
28
  * v2.3.3
@@ -29,7 +42,7 @@
29
42
  * v2.1.5
30
43
  * patch fix of `useVideosInSection` hook (fetching video's monetizations)
31
44
  * v2.1.4
32
- * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react@2.1.9)
45
+ * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react-dom@2.1.9)
33
46
  * v2.1.3
34
47
  * patch: fix changelog
35
48
  * v2.1.2
@@ -61,16 +74,14 @@
61
74
  * v1.3.4
62
75
  * ...
63
76
 
64
- ## Installation
65
77
 
66
- Check/install peer dependencies
67
- ``` sh
68
- npm install --save mobx@6.0.4 styled-components@5.2.1 firebase@8.2.3 react@17.0.2 react-dom@17.0.2
69
- ```
78
+ ## Installation
70
79
 
71
- Install SDK itself
72
- ``` sh
73
- npm install --save @tivio/sdk-react
80
+ Install @tivio/sdk-react along with its peer dependencies
81
+ ```sh
82
+ npm i react@17 react-dom@17 @tivio/sdk-react
83
+ # or
84
+ yarn add react@17 react-dom@17 @tivio/sdk-react
74
85
  ```
75
86
 
76
87
  ## Initialization
@@ -80,13 +91,13 @@ Put Tivio Provider at the top level of your application:
80
91
  ``` javascript
81
92
  import { TivioProvider } from '@tivio/sdk-react'
82
93
 
83
- const tivioConf = {
94
+ const config = {
84
95
  secret: 'XXXXXXXXXX',
85
96
  }
86
97
 
87
98
  function App({children}) {
88
99
  return (
89
- <TivioProvider conf={tivioConf}>
100
+ <TivioProvider conf={config}>
90
101
  {children}
91
102
  </TivioProvider>
92
103
  )
@@ -95,27 +106,12 @@ function App({children}) {
95
106
 
96
107
  ### Usage with authorization
97
108
 
98
- ``` javascript
99
- import { TivioProvider, setUser } from '@tivio/sdk-react'
100
-
101
- const tivioConf = {
102
- secret: 'XXXXXXXXXX',
103
- }
109
+ // TODO
104
110
 
105
- setUser('user-id', { some: 'payload' })
106
-
107
- function App({children}) {
108
- return (
109
- <TivioProvider conf={tivioConf}>
110
- {children}
111
- </TivioProvider>
112
- )
113
- }
114
- ```
115
111
  ## Tivio widget
116
112
 
117
113
  Tivio widget is the main Tivio component which shows the widget and provides access to its channels, sections and videos.
118
- Usage is very simple (be sure to set `id` to the widget ID you have configured in Tivio Studio):
114
+ Usage is very simple (be sure to set `id` to the widget ID you have configured in [Tivio Studio](https://studio.tiv.io/)):
119
115
 
120
116
  ``` javascript
121
117
  import { TivioWidget } from '@tivio/sdk-react'
@@ -144,48 +140,146 @@ function Screen() {
144
140
  )
145
141
  }
146
142
  ```
143
+
147
144
  ## Player wrapper
148
145
 
149
- Player wrapper is the way how you can enhance your video player with Tivio features (e.g. inserting of ads).
146
+ 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.
147
+
148
+ ### Wrap your player methods with Tivio player wrapper
150
149
 
151
150
  ``` javascript
152
- import { useTivioData } from '@tivio/sdk-react'
151
+ import { useTivioReadyData } from '@tivio/sdk-react'
153
152
 
154
153
  function CustomPlayer() {
155
- const tivio = useTivioData()
156
- const [isPlaying, setIsPlaying] = useState()
154
+ const tivioData = useTivioReadyData()
157
155
 
158
156
  useEffect(() => {
159
- (async () => {
160
- if (tivio.getPlayerWrapper) {
161
- const playerWrapper = await tivio.getPlayerWrapper(
162
- { playerWrapperId: 'default' }
163
- )
164
-
165
- playerWrapper.register({
166
- play: () => {
167
- setIsPlaying(true)
168
- // start playback using your player here
169
- },
170
- pause: () => {
171
- setIsPlaying(false)
172
- // pause playback using your player here
173
- },
174
- seekTo: (ms: number) => {
175
- // seek using your player here
176
- },
177
- setSource: (videoSource: InputSource) => {
178
- // play videoSource using your player here
179
- },
180
- })
181
- }
182
- })()
183
- }, [])
184
-
185
- return (<div>Example is {isPlaying ? null : 'not '}playing.</div>)
157
+ if (tivioData) {
158
+ // If your app uses multiple player instances, use different Tivio player wrapper for each
159
+ // distinguished by playerWrapperId
160
+ const playerWrapper = tivio.getPlayerWrapper({ playerWrapperId: 'PLAYER_1' })
161
+
162
+ // Pass your player methods to Tivio player wrapper
163
+ playerWrapper.register({
164
+ play: () => {
165
+ // Un-pause your player
166
+ },
167
+ pause: () => {
168
+ // Pause your player
169
+ },
170
+ seekTo: (ms: number) => {
171
+ // Seek to position in milliseconds using your player
172
+ },
173
+ setSource: (videoSource: InputSource) => {
174
+ // Send this video source to your player to load it
175
+ },
176
+ })
177
+ }
178
+ }, [tivioData])
179
+ }
180
+ ```
181
+
182
+ ### Start using Tivio player wrapper methods to control playback
183
+
184
+ ``` javascript
185
+ // Channel source metadata, such as channel name, epg start and epg end are necessary
186
+ // for TV ad segment detection and application of ad strategies
187
+ const source = new ChannelSource(
188
+ 'https://channel_prima_hd.m3u8',
189
+ {
190
+ // here put any additional metadata, for your use.
191
+ // This object will not be touched by Tivio
192
+ },
193
+ // channel name
194
+ // can also be prima hd, prima_hd, prima, Prima, PRIMA, etc.
195
+ // we will normalize it to snake case and add '_hd' if necessary
196
+ 'Prima HD',
197
+ // program name
198
+ 'Dr. House',
199
+ // description (optional)
200
+ 'Episode about Dr. House being awesome',
201
+ // EPG start
202
+ new Date('2021-12-10T12:00:00'),
203
+ // EPG end
204
+ new Date('2021-12-10T13:40:00'),
205
+ )
206
+
207
+ // Send source to player
208
+ playerWrapper.onSourceChanged(source)
209
+
210
+ // Un-pause player
211
+ playerWrapper.play()
212
+
213
+ // Pause player
214
+ playerWrapper.pause()
186
215
  }
187
216
  ```
188
217
 
218
+ ### Start reporting player events to Tivio
219
+
220
+ ``` javascript
221
+ // Report that source is playing
222
+ playerWrapper.onStateChanged('playing')
223
+
224
+ // Report that source is paused
225
+ playerWrapper.onStateChanged('paused')
226
+
227
+ // Report that source stopped playing
228
+ playerWrapper.onPlaybackEnded()
229
+ playerWrapper.onStateChanged('idle')
230
+
231
+ // Report video progress
232
+ playerWrapper.onTimeChanged(ms)
233
+ }
234
+ ```
235
+
236
+ ### Start reporting playback-related errors to Tivio
237
+
238
+ ``` javascript
239
+ // Report that video failed to load (e.g. due to a wrong URI)
240
+ playerWrapper.onLoadError(new Error('video failed to load'))
241
+
242
+ // Report that video failed during playback (e.g. due to bad connection, corrupted chunks of stream video etc.)
243
+ // This type of error may be auto-recoverable
244
+ playerWrapper.onError(new Error('playback error'))
245
+ }
246
+ ```
247
+
248
+ ## Tivio DOM events
249
+
250
+ `TivioWidget` triggers these events on `window.document`.
251
+
252
+ 1. To instruct the parent app to navigate to and focus a specific TivioWidget (e.g. after going back from a Tivio screen)
253
+
254
+ ```typescript
255
+ document.addEventListener("tivio_request_goto", e => {
256
+ e.detail.widgetId; // string - Tivio widget ID to go navigate to in UI
257
+ });
258
+ ```
259
+ 2. To notify the parent app about context switch, i.e. where is the user located or what is he focusing
260
+
261
+ ```typescript
262
+ document.addEventListener("tivio_context_switch", e => {
263
+ e.detail.context; // 'tivio' | 'parent' - where is the user located? - in Tivio or in parent app
264
+
265
+ // For context Tivio there are additional fields
266
+ e.detail.context; // 'tivio'
267
+ e.detail.contextLocation; // 'route' | 'overlay' | 'widget' - where in Tivio is the user located?
268
+ // - on a Tivio route, in parent app but looking at a full screen Tivio overlay,
269
+ // or in parent app and focus is on a Tivio widget
270
+
271
+ // For context Tivio contextLocation 'widget' there is an additional field of widget ID
272
+ e.detail.widgetId; // string - which Tivio widget is focused right now
273
+ });
274
+ ```
275
+ 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.
276
+
277
+ ```typescript
278
+ document.addEventListener("tivio_key_input_handling_change", e => {
279
+ e.detail.inputHandler; // 'tivio' | 'parent' - who should be handling RC input? - Tivio or parent app
280
+ });
281
+ ```
282
+
189
283
  ## Data hooks
190
284
 
191
285
  If you don't want to use TivioWidget, you can implement your own UI using React data hooks.
@@ -3,11 +3,17 @@
3
3
  * nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4
4
  */
5
5
  import React, { FunctionComponentElement } from 'react';
6
+ import type { PlayerWrapper } from '../types/customPlayer.types';
6
7
  export declare type PlayerProviderProps = {
7
8
  children: React.ReactNode;
8
9
  playerWrapperId?: string;
9
10
  };
10
- export declare type Player = any;
11
- export declare const PlayerContext: React.Context<any>;
11
+ /**
12
+ * value
13
+ * - undefined - you are trying to access this context but are not inside <PlayerContext /> that is a bug
14
+ * - null - we are waiting for remote code
15
+ * - Player - player is ready
16
+ */
17
+ export declare const PlayerContext: React.Context<PlayerWrapper | null | undefined>;
12
18
  export declare const PlayerProvider: ({ children, playerWrapperId, }: PlayerProviderProps) => FunctionComponentElement<PlayerProviderProps>;
13
19
  export declare function withPlayerContext(id: string): <P>(WrappedComponent: React.ComponentType<P>) => (props: P) => JSX.Element;
@@ -15,3 +15,5 @@ export * from './useFreePurchase';
15
15
  export * from './useRowsInScreen';
16
16
  export * from './useVoucher';
17
17
  export * from './useTivio';
18
+ export * from './useLastVideoByWidgetId';
19
+ export * from './useWatchWithoutAdsOffer';
@@ -1,11 +1,11 @@
1
- import { PaginationInterface, SubscribeToItemsInRowOptions, Tag, Video } from '@tivio/common';
1
+ import { ItemsInRow, PaginationInterface, SubscribeToItemsInRowOptions } from '@tivio/common';
2
2
  /**
3
3
  * Use row items
4
4
  * @param rowId - row ID
5
5
  * @param options - subscription options
6
6
  */
7
7
  declare const useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
8
- pagination: PaginationInterface<Video | Tag> | null;
8
+ pagination: PaginationInterface<ItemsInRow> | null;
9
9
  error: Error | null;
10
10
  };
11
11
  export { useItemsInRow, };
@@ -0,0 +1,2 @@
1
+ import { Video } from '@tivio/common';
2
+ export declare function useLastVideoByWidgetId(widgetId: string): Video | null;
@@ -3,6 +3,7 @@ declare type Voucher = {
3
3
  isUsed: boolean;
4
4
  isExpired: boolean;
5
5
  status: 'NEW' | 'USED';
6
+ voucherInfo: any;
6
7
  };
7
8
  declare const useVoucher: (voucherId: string) => {
8
9
  activate: (() => void) | null;
@@ -0,0 +1,4 @@
1
+ export declare const useWatchWithoutAdsOffer: () => {
2
+ canPurchaseWatchWithoutAds: boolean;
3
+ showPurchaseDialog: () => void;
4
+ };