@tivio/sdk-react 9.5.0 → 9.7.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 +170 -3
- package/README.md.bak +170 -3
- package/dist/index.d.ts +181 -54
- package/dist/index.js +1 -1
- package/dist/sdk-react.d.ts +181 -54
- package/package.json +2 -2
package/README.md
CHANGED
@@ -799,6 +799,56 @@ The `sourcePlayMode` property determines how the content is played:
|
|
799
799
|
- **LIVE** - Live stream mode with no seeking
|
800
800
|
- **HYBRID** - Combines LIVE with seeking
|
801
801
|
|
802
|
+
#### User Authentication Callbacks
|
803
|
+
|
804
|
+
The `userAuthCallbacks` property allows you to handle user authentication flows when the player requires user login or registration. This is particularly useful for content that requires authentication (e.g., premium content).
|
805
|
+
|
806
|
+
```typescript
|
807
|
+
interface UserAuthCallbacks {
|
808
|
+
onGoToLogin: () => void
|
809
|
+
onGoToRegistration: () => void
|
810
|
+
}
|
811
|
+
```
|
812
|
+
|
813
|
+
**Example Implementation:**
|
814
|
+
|
815
|
+
```typescript
|
816
|
+
// Usage with renderWebPlayer
|
817
|
+
const videoController = await renderWebPlayer(
|
818
|
+
document.getElementById('video-player'),
|
819
|
+
{
|
820
|
+
id: 'player-main',
|
821
|
+
source: 'videos/PREMIUM_VIDEO_ID',
|
822
|
+
userAuthCallbacks: {
|
823
|
+
onGoToLogin: () => {
|
824
|
+
// Show your login modal
|
825
|
+
setShowLoginModal(true)
|
826
|
+
},
|
827
|
+
onGoToRegistration: () => {
|
828
|
+
// Show your registration modal
|
829
|
+
setShowRegistrationModal(true)
|
830
|
+
},
|
831
|
+
},
|
832
|
+
}
|
833
|
+
)
|
834
|
+
|
835
|
+
// Handle login in your modal
|
836
|
+
const handleLogin = async (email: string, password: string) => {
|
837
|
+
try {
|
838
|
+
await tivio.signInWithEmailAndPassword(email, password)
|
839
|
+
console.log('Login successful')
|
840
|
+
} catch (error) {
|
841
|
+
console.error('Login failed:', error)
|
842
|
+
throw error
|
843
|
+
}
|
844
|
+
}
|
845
|
+
```
|
846
|
+
|
847
|
+
**When are these callbacks triggered?**
|
848
|
+
|
849
|
+
- **`onGoToLogin`**: Called when the player is trying to play content behind a paywall and user clicks on the login button in the overlay
|
850
|
+
- **`onGoToRegistration`**: Called when the player is trying to play content behind a paywall and user clicks on the registration button in the overlay
|
851
|
+
|
802
852
|
#### Using setSource with VideoController
|
803
853
|
|
804
854
|
The `setSource` method allows you to dynamically change what's playing:
|
@@ -870,7 +920,7 @@ The VideoController emits various events that you can listen to:
|
|
870
920
|
#### Ad events
|
871
921
|
|
872
922
|
```typescript
|
873
|
-
videoController.addEventListener('
|
923
|
+
videoController.addEventListener('ad-started', (adMetadata: AdMetadata | null) => {
|
874
924
|
if (!adMetadata) {
|
875
925
|
console.log('Ad started playing (no metadata available)')
|
876
926
|
return
|
@@ -960,9 +1010,25 @@ videoController.addEventListener('ad_started', (adMetadata: AdMetadata | null) =
|
|
960
1010
|
// Update UI, show ad overlay, etc.
|
961
1011
|
})
|
962
1012
|
|
963
|
-
videoController.addEventListener('
|
1013
|
+
videoController.addEventListener('ad-ended', () => {
|
964
1014
|
console.log('Ad finished playing')
|
965
1015
|
})
|
1016
|
+
|
1017
|
+
// Companion ads event - fires when companion ads are available for the current ad
|
1018
|
+
videoController.addEventListener('companion-ads', (companionAds) => {
|
1019
|
+
console.log('Companion ads available:', companionAds)
|
1020
|
+
|
1021
|
+
// Access companion ad properties using IMA methods
|
1022
|
+
companionAds.forEach((companionAd, index) => {
|
1023
|
+
console.log(`Companion Ad ${index + 1}:`, {
|
1024
|
+
width: companionAd.getWidth(),
|
1025
|
+
height: companionAd.getHeight(),
|
1026
|
+
contentType: companionAd.getContentType(),
|
1027
|
+
// HTML content as string
|
1028
|
+
content: companionAd.getContent()
|
1029
|
+
})
|
1030
|
+
})
|
1031
|
+
})
|
966
1032
|
```
|
967
1033
|
|
968
1034
|
> ℹ️ **_Note:_** The CTA overlay element is visible in the WebPlayer only while an ad is playing and is automatically cleaned up on source changes.
|
@@ -1040,4 +1106,105 @@ The `WebPlayerProps` interface defines the properties that can be passed to the
|
|
1040
1106
|
|
1041
1107
|
### Visual Properties
|
1042
1108
|
|
1043
|
-
- **`showMarkers`
|
1109
|
+
- **`showMarkers`** (optional, default: `false`): Whether to show video markers
|
1110
|
+
- **`markerColor`** (optional): Color for video markers (CSS color value)
|
1111
|
+
- **`showTvStreamType`** (optional): Whether to show TV stream type indicator
|
1112
|
+
- **`showCookiesSettings`** (optional): Whether to show cookies settings
|
1113
|
+
- **`showOsd`** (optional, default: `true`): Whether to show the On-Screen Display (OSD)
|
1114
|
+
- **`showBufferingSpinner`** (optional, default: `true`): Whether to show buffering spinner
|
1115
|
+
|
1116
|
+
### Audio Properties
|
1117
|
+
|
1118
|
+
- **`isMutedByDefault`** (optional): If `true`, the player starts muted but can be unmuted
|
1119
|
+
|
1120
|
+
### Keyboard Shortcuts Properties
|
1121
|
+
|
1122
|
+
- **`enableKeyboardShortcuts`** (optional, default: `true`): Whether to enable keyboard shortcuts
|
1123
|
+
- **`customShortcuts`** (optional): Custom keyboard shortcuts configuration:
|
1124
|
+
```typescript
|
1125
|
+
{
|
1126
|
+
toggleFullscreen: number[], // Array of key codes
|
1127
|
+
togglePause: number[],
|
1128
|
+
toggleMute: number[],
|
1129
|
+
jumpForward: number[],
|
1130
|
+
jumpBack: number[],
|
1131
|
+
volumeUp: number[],
|
1132
|
+
volumeDown: number[]
|
1133
|
+
}
|
1134
|
+
```
|
1135
|
+
|
1136
|
+
### Ad Block Properties
|
1137
|
+
|
1138
|
+
- **`checkAdBlock`** (optional, default: `false`): Whether to check for ad blockers and show warnings
|
1139
|
+
|
1140
|
+
## Data hooks
|
1141
|
+
Gets information about current user.
|
1142
|
+
|
1143
|
+
```ts
|
1144
|
+
useUser: () => {
|
1145
|
+
user: User | null
|
1146
|
+
error: string | null
|
1147
|
+
isInitialized: boolean
|
1148
|
+
}
|
1149
|
+
```
|
1150
|
+
|
1151
|
+
### useRowsInScreen hook
|
1152
|
+
Gets array of Rows objects of specific screen and subscribes to its changes.
|
1153
|
+
|
1154
|
+
```ts
|
1155
|
+
/**
|
1156
|
+
* Use rows in screen
|
1157
|
+
* @param screenId - screen id (from studio.tiv.io)
|
1158
|
+
* @param options - subscription options
|
1159
|
+
*/
|
1160
|
+
useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
|
1161
|
+
pagination: PaginationInterface<Row> | null
|
1162
|
+
error: Error | null
|
1163
|
+
}
|
1164
|
+
```
|
1165
|
+
|
1166
|
+
### useItemsInRow hook
|
1167
|
+
Gets array of row items objects of specific row and subscribes to its changes.
|
1168
|
+
|
1169
|
+
```ts
|
1170
|
+
/**
|
1171
|
+
* Use row items
|
1172
|
+
* @param rowId - row ID
|
1173
|
+
* @param options - subscription options
|
1174
|
+
*/
|
1175
|
+
useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
|
1176
|
+
pagination: PaginationInterface<ItemInRow> | null
|
1177
|
+
error: Error | null
|
1178
|
+
}
|
1179
|
+
```
|
1180
|
+
|
1181
|
+
### useVideo hook
|
1182
|
+
|
1183
|
+
Gets Video object and subscribes to its changes.
|
1184
|
+
|
1185
|
+
```ts
|
1186
|
+
/**
|
1187
|
+
* Use video
|
1188
|
+
* @param videoId - video id
|
1189
|
+
*/
|
1190
|
+
useVideo: (videoId: string) => {
|
1191
|
+
error: string | null;
|
1192
|
+
data: Video | null;
|
1193
|
+
}
|
1194
|
+
```
|
1195
|
+
|
1196
|
+
### useTaggedVideos hook
|
1197
|
+
Gets videos with given tag IDs.
|
1198
|
+
|
1199
|
+
```ts
|
1200
|
+
/**
|
1201
|
+
* Use tagged videos
|
1202
|
+
* @param tagIds - tag ids
|
1203
|
+
* @param options - subscription options
|
1204
|
+
* @public
|
1205
|
+
*/
|
1206
|
+
useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
|
1207
|
+
pagination: PaginationInterface<Video> | null
|
1208
|
+
error: Error | null
|
1209
|
+
}
|
1210
|
+
```
|
package/README.md.bak
CHANGED
@@ -799,6 +799,56 @@ The `sourcePlayMode` property determines how the content is played:
|
|
799
799
|
- **LIVE** - Live stream mode with no seeking
|
800
800
|
- **HYBRID** - Combines LIVE with seeking
|
801
801
|
|
802
|
+
#### User Authentication Callbacks
|
803
|
+
|
804
|
+
The `userAuthCallbacks` property allows you to handle user authentication flows when the player requires user login or registration. This is particularly useful for content that requires authentication (e.g., premium content).
|
805
|
+
|
806
|
+
```typescript
|
807
|
+
interface UserAuthCallbacks {
|
808
|
+
onGoToLogin: () => void
|
809
|
+
onGoToRegistration: () => void
|
810
|
+
}
|
811
|
+
```
|
812
|
+
|
813
|
+
**Example Implementation:**
|
814
|
+
|
815
|
+
```typescript
|
816
|
+
// Usage with renderWebPlayer
|
817
|
+
const videoController = await renderWebPlayer(
|
818
|
+
document.getElementById('video-player'),
|
819
|
+
{
|
820
|
+
id: 'player-main',
|
821
|
+
source: 'videos/PREMIUM_VIDEO_ID',
|
822
|
+
userAuthCallbacks: {
|
823
|
+
onGoToLogin: () => {
|
824
|
+
// Show your login modal
|
825
|
+
setShowLoginModal(true)
|
826
|
+
},
|
827
|
+
onGoToRegistration: () => {
|
828
|
+
// Show your registration modal
|
829
|
+
setShowRegistrationModal(true)
|
830
|
+
},
|
831
|
+
},
|
832
|
+
}
|
833
|
+
)
|
834
|
+
|
835
|
+
// Handle login in your modal
|
836
|
+
const handleLogin = async (email: string, password: string) => {
|
837
|
+
try {
|
838
|
+
await tivio.signInWithEmailAndPassword(email, password)
|
839
|
+
console.log('Login successful')
|
840
|
+
} catch (error) {
|
841
|
+
console.error('Login failed:', error)
|
842
|
+
throw error
|
843
|
+
}
|
844
|
+
}
|
845
|
+
```
|
846
|
+
|
847
|
+
**When are these callbacks triggered?**
|
848
|
+
|
849
|
+
- **`onGoToLogin`**: Called when the player is trying to play content behind a paywall and user clicks on the login button in the overlay
|
850
|
+
- **`onGoToRegistration`**: Called when the player is trying to play content behind a paywall and user clicks on the registration button in the overlay
|
851
|
+
|
802
852
|
#### Using setSource with VideoController
|
803
853
|
|
804
854
|
The `setSource` method allows you to dynamically change what's playing:
|
@@ -870,7 +920,7 @@ The VideoController emits various events that you can listen to:
|
|
870
920
|
#### Ad events
|
871
921
|
|
872
922
|
```typescript
|
873
|
-
videoController.addEventListener('
|
923
|
+
videoController.addEventListener('ad-started', (adMetadata: AdMetadata | null) => {
|
874
924
|
if (!adMetadata) {
|
875
925
|
console.log('Ad started playing (no metadata available)')
|
876
926
|
return
|
@@ -960,9 +1010,25 @@ videoController.addEventListener('ad_started', (adMetadata: AdMetadata | null) =
|
|
960
1010
|
// Update UI, show ad overlay, etc.
|
961
1011
|
})
|
962
1012
|
|
963
|
-
videoController.addEventListener('
|
1013
|
+
videoController.addEventListener('ad-ended', () => {
|
964
1014
|
console.log('Ad finished playing')
|
965
1015
|
})
|
1016
|
+
|
1017
|
+
// Companion ads event - fires when companion ads are available for the current ad
|
1018
|
+
videoController.addEventListener('companion-ads', (companionAds) => {
|
1019
|
+
console.log('Companion ads available:', companionAds)
|
1020
|
+
|
1021
|
+
// Access companion ad properties using IMA methods
|
1022
|
+
companionAds.forEach((companionAd, index) => {
|
1023
|
+
console.log(`Companion Ad ${index + 1}:`, {
|
1024
|
+
width: companionAd.getWidth(),
|
1025
|
+
height: companionAd.getHeight(),
|
1026
|
+
contentType: companionAd.getContentType(),
|
1027
|
+
// HTML content as string
|
1028
|
+
content: companionAd.getContent()
|
1029
|
+
})
|
1030
|
+
})
|
1031
|
+
})
|
966
1032
|
```
|
967
1033
|
|
968
1034
|
> ℹ️ **_Note:_** The CTA overlay element is visible in the WebPlayer only while an ad is playing and is automatically cleaned up on source changes.
|
@@ -1040,4 +1106,105 @@ The `WebPlayerProps` interface defines the properties that can be passed to the
|
|
1040
1106
|
|
1041
1107
|
### Visual Properties
|
1042
1108
|
|
1043
|
-
- **`showMarkers`
|
1109
|
+
- **`showMarkers`** (optional, default: `false`): Whether to show video markers
|
1110
|
+
- **`markerColor`** (optional): Color for video markers (CSS color value)
|
1111
|
+
- **`showTvStreamType`** (optional): Whether to show TV stream type indicator
|
1112
|
+
- **`showCookiesSettings`** (optional): Whether to show cookies settings
|
1113
|
+
- **`showOsd`** (optional, default: `true`): Whether to show the On-Screen Display (OSD)
|
1114
|
+
- **`showBufferingSpinner`** (optional, default: `true`): Whether to show buffering spinner
|
1115
|
+
|
1116
|
+
### Audio Properties
|
1117
|
+
|
1118
|
+
- **`isMutedByDefault`** (optional): If `true`, the player starts muted but can be unmuted
|
1119
|
+
|
1120
|
+
### Keyboard Shortcuts Properties
|
1121
|
+
|
1122
|
+
- **`enableKeyboardShortcuts`** (optional, default: `true`): Whether to enable keyboard shortcuts
|
1123
|
+
- **`customShortcuts`** (optional): Custom keyboard shortcuts configuration:
|
1124
|
+
```typescript
|
1125
|
+
{
|
1126
|
+
toggleFullscreen: number[], // Array of key codes
|
1127
|
+
togglePause: number[],
|
1128
|
+
toggleMute: number[],
|
1129
|
+
jumpForward: number[],
|
1130
|
+
jumpBack: number[],
|
1131
|
+
volumeUp: number[],
|
1132
|
+
volumeDown: number[]
|
1133
|
+
}
|
1134
|
+
```
|
1135
|
+
|
1136
|
+
### Ad Block Properties
|
1137
|
+
|
1138
|
+
- **`checkAdBlock`** (optional, default: `false`): Whether to check for ad blockers and show warnings
|
1139
|
+
|
1140
|
+
## Data hooks
|
1141
|
+
Gets information about current user.
|
1142
|
+
|
1143
|
+
```ts
|
1144
|
+
useUser: () => {
|
1145
|
+
user: User | null
|
1146
|
+
error: string | null
|
1147
|
+
isInitialized: boolean
|
1148
|
+
}
|
1149
|
+
```
|
1150
|
+
|
1151
|
+
### useRowsInScreen hook
|
1152
|
+
Gets array of Rows objects of specific screen and subscribes to its changes.
|
1153
|
+
|
1154
|
+
```ts
|
1155
|
+
/**
|
1156
|
+
* Use rows in screen
|
1157
|
+
* @param screenId - screen id (from studio.tiv.io)
|
1158
|
+
* @param options - subscription options
|
1159
|
+
*/
|
1160
|
+
useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
|
1161
|
+
pagination: PaginationInterface<Row> | null
|
1162
|
+
error: Error | null
|
1163
|
+
}
|
1164
|
+
```
|
1165
|
+
|
1166
|
+
### useItemsInRow hook
|
1167
|
+
Gets array of row items objects of specific row and subscribes to its changes.
|
1168
|
+
|
1169
|
+
```ts
|
1170
|
+
/**
|
1171
|
+
* Use row items
|
1172
|
+
* @param rowId - row ID
|
1173
|
+
* @param options - subscription options
|
1174
|
+
*/
|
1175
|
+
useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
|
1176
|
+
pagination: PaginationInterface<ItemInRow> | null
|
1177
|
+
error: Error | null
|
1178
|
+
}
|
1179
|
+
```
|
1180
|
+
|
1181
|
+
### useVideo hook
|
1182
|
+
|
1183
|
+
Gets Video object and subscribes to its changes.
|
1184
|
+
|
1185
|
+
```ts
|
1186
|
+
/**
|
1187
|
+
* Use video
|
1188
|
+
* @param videoId - video id
|
1189
|
+
*/
|
1190
|
+
useVideo: (videoId: string) => {
|
1191
|
+
error: string | null;
|
1192
|
+
data: Video | null;
|
1193
|
+
}
|
1194
|
+
```
|
1195
|
+
|
1196
|
+
### useTaggedVideos hook
|
1197
|
+
Gets videos with given tag IDs.
|
1198
|
+
|
1199
|
+
```ts
|
1200
|
+
/**
|
1201
|
+
* Use tagged videos
|
1202
|
+
* @param tagIds - tag ids
|
1203
|
+
* @param options - subscription options
|
1204
|
+
* @public
|
1205
|
+
*/
|
1206
|
+
useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
|
1207
|
+
pagination: PaginationInterface<Video> | null
|
1208
|
+
error: Error | null
|
1209
|
+
}
|
1210
|
+
```
|