Getting Started
0. Minimum Requirements
IE11
Edge 12
Firefox 29
Chrome 33
Safari 7.1
For handling FCM Push Notification in an SPA (such as Vue.js or React) or React Native, see this link.
1a. NPM
npm install talkplus-sdk
1b. CDN
<script src="https://asset.talkplus.io/npm/talkplus-0.5.8"></script>
1c. Download
2. Initializing
const client = new TalkPlus.Client({appId: 'YOUR_APP_ID'});
3. Promise, Async/Await and Callback
Most functions in the SDK can be called using async/await or by providing a callback function.
// Promise
this.loginAnonymous({
userId: 'user-123',
username: 'user-123',
profileImageUrl: '',
})
.then((data) => console.log(data))
.catch((err) => console.error(err));
// async/await
try {
await client.loginAnonymous({
userId: 'user-123',
username: 'user-123',
profileImageUrl: '',
});
} catch (err) {
}
// callback
client.loginAnonymous({
userId: 'user-123',
username: 'user-123',
}, function (err, data) {
console.error(err);
console.log(data);
});
4. Login / Logout Process
You need to log in (either using
loginAnonymous
orloginWithToken
) after initializing the TalkPlus SDK.Once logged in, client can receive realtime messages. Web Push Notification is not supported. However, if your app need to support FCM push notification, you can register your device FCM token using
registerFcmToken
and receive FCM push notification.TalkPlus SDK does not use cookie or other local storages so closing the browser tab ends the current session.
5. Error
The error JSON response follows the format below:
{
"error": true,
"code": "1006",
"message": "Unauthorized"
}
Last updated