@tivio/sdk-react 2.3.4 → 2.4.2-beta1

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