playsout-web-sdk 1.0.0 → 1.0.2
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 +226 -0
- package/index.global.js +15 -15
- package/index.iife.js +15 -15
- package/package.json +1 -1
- package/web-components/imageCache.d.ts.map +1 -1
- package/web-components/index.cjs +15 -15
- package/web-components/index.js +15 -15
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Playsout Web SDK
|
|
2
|
+
|
|
3
|
+
Playsout Web SDK provides a game list widget, SDK initialization, platform login, login state access, locale switching, and user points display for HTML, React, and Vue projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install playsout-web-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Supported Locales
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
'zh' | 'en' | 'ja' | 'ko' | 'vi' | 'th' | 'id' | 'ms'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Login Platform Parameters
|
|
18
|
+
|
|
19
|
+
`appId` is not required.
|
|
20
|
+
|
|
21
|
+
The public login method is:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
Playsout.Login(params)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Supported platform values:
|
|
28
|
+
|
|
29
|
+
| Platform | `platform` |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Grab | `grab` |
|
|
32
|
+
| Eros | `eros` |
|
|
33
|
+
|
|
34
|
+
Login parameters:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
await Playsout.Login({
|
|
38
|
+
platform: 'eros',
|
|
39
|
+
platformUserId: '10',
|
|
40
|
+
platformToken: 'platform_token',
|
|
41
|
+
username: 'TestUser',
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`platform` should be lowercase. `grab` and `eros` require `platformUserId` and `platformToken`.
|
|
46
|
+
|
|
47
|
+
## HTML Usage
|
|
48
|
+
|
|
49
|
+
Use the IIFE build from a CDN or a local copy.
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<div id="game-container"></div>
|
|
53
|
+
|
|
54
|
+
<script src="https://unpkg.com/playsout-web-sdk/index.iife.js"></script>
|
|
55
|
+
<script>
|
|
56
|
+
window.Playsout.init({ locale: 'zh' }).then(function () {
|
|
57
|
+
window.Playsout.mount('#game-container', {
|
|
58
|
+
theme: 'dark',
|
|
59
|
+
locale: 'zh',
|
|
60
|
+
detailMode: 'iframe'
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
document
|
|
64
|
+
.querySelector('playsout-widget')
|
|
65
|
+
?.setAttribute('user-points', '1000');
|
|
66
|
+
});
|
|
67
|
+
</script>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Login:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
await window.Playsout.Login({
|
|
74
|
+
platform: 'eros',
|
|
75
|
+
platformUserId: '10',
|
|
76
|
+
platformToken: 'platform_token',
|
|
77
|
+
username: 'TestUser'
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Login state:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
window.Playsout.isLoggedIn;
|
|
85
|
+
window.Playsout.getToken();
|
|
86
|
+
window.Playsout.getUser();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Locale:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
window.Playsout.setLocale('en');
|
|
93
|
+
window.Playsout.getLocale();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Auth expiration:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
window.Playsout.on('authExpired', function () {
|
|
100
|
+
// Get a new platform credential, then call Playsout.Login() again.
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## React Usage
|
|
105
|
+
|
|
106
|
+
Import the Web Component once and initialize the SDK through `PlaysoutProvider`.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import 'playsout-web-sdk/web-components';
|
|
110
|
+
import { PlaysoutProvider } from 'playsout-web-sdk/react';
|
|
111
|
+
|
|
112
|
+
export function App() {
|
|
113
|
+
return (
|
|
114
|
+
<PlaysoutProvider config={{ locale: 'zh' }}>
|
|
115
|
+
<GamePage />
|
|
116
|
+
</PlaysoutProvider>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function GamePage() {
|
|
121
|
+
return (
|
|
122
|
+
<playsout-widget
|
|
123
|
+
locale="zh"
|
|
124
|
+
user-points="1000"
|
|
125
|
+
detail-mode="iframe"
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Use SDK APIs in React:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { usePlaysout } from 'playsout-web-sdk/react';
|
|
135
|
+
|
|
136
|
+
function LoginButton() {
|
|
137
|
+
const { Login, isLoggedIn, user, setLocale } = usePlaysout();
|
|
138
|
+
|
|
139
|
+
async function handleLogin() {
|
|
140
|
+
await Login({
|
|
141
|
+
platform: 'eros',
|
|
142
|
+
platformUserId: '10',
|
|
143
|
+
platformToken: 'platform_token',
|
|
144
|
+
username: 'TestUser',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return <button onClick={handleLogin}>Login</button>;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Vue Usage
|
|
153
|
+
|
|
154
|
+
Initialize the SDK with the Vue plugin.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { createApp } from 'vue';
|
|
158
|
+
import { createPlaysoutPlugin } from 'playsout-web-sdk/vue';
|
|
159
|
+
import 'playsout-web-sdk/web-components';
|
|
160
|
+
import App from './App.vue';
|
|
161
|
+
|
|
162
|
+
const app = createApp(App);
|
|
163
|
+
|
|
164
|
+
app.use(createPlaysoutPlugin({
|
|
165
|
+
config: {
|
|
166
|
+
locale: 'zh',
|
|
167
|
+
},
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
app.mount('#app');
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Use the widget:
|
|
174
|
+
|
|
175
|
+
```vue
|
|
176
|
+
<template>
|
|
177
|
+
<playsout-widget
|
|
178
|
+
locale="zh"
|
|
179
|
+
user-points="1000"
|
|
180
|
+
detail-mode="iframe"
|
|
181
|
+
/>
|
|
182
|
+
</template>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Use SDK APIs in Vue:
|
|
186
|
+
|
|
187
|
+
```vue
|
|
188
|
+
<script setup>
|
|
189
|
+
import { usePlaysout } from 'playsout-web-sdk/vue';
|
|
190
|
+
|
|
191
|
+
const { Login, isLoggedIn, user, setLocale } = usePlaysout();
|
|
192
|
+
|
|
193
|
+
async function handleLogin() {
|
|
194
|
+
await Login({
|
|
195
|
+
platform: 'eros',
|
|
196
|
+
platformUserId: '10',
|
|
197
|
+
platformToken: 'platform_token',
|
|
198
|
+
username: 'TestUser',
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
</script>
|
|
202
|
+
|
|
203
|
+
<template>
|
|
204
|
+
<button @click="handleLogin">Login</button>
|
|
205
|
+
</template>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## User Points
|
|
209
|
+
|
|
210
|
+
`user-points` is a UI display value passed by the host application.
|
|
211
|
+
|
|
212
|
+
The SDK does not fetch the user's points balance from the backend.
|
|
213
|
+
|
|
214
|
+
```html
|
|
215
|
+
<playsout-widget user-points="1000"></playsout-widget>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Token Expiration
|
|
219
|
+
|
|
220
|
+
The SDK retries protected requests after refreshing the access token.
|
|
221
|
+
|
|
222
|
+
If the refresh token is also invalid, the SDK clears local auth data, changes the login state to logged out, and emits `authExpired`. The host application should get a new platform credential and call `Login()` again.
|
|
223
|
+
|
|
224
|
+
## Image Loading
|
|
225
|
+
|
|
226
|
+
The SDK uses online image URLs directly. Persistent SDK image caching is disabled by default.
|