Push Notification (FCM)
현재 브라우저 Web Push Notification 기능을 제공하고 있지 않습니다.
사용자가 Push Notification을 받을 지 여부를 설정할 수 있습니다.
(JS SDK v0.2.12 이상부터 제공되는 기능입니다)
// Enable push notification
await client.enablePushNotification();
// Disable push notification
await client.disablePushNotification();
react-native와 같은 hybrid app에서 사용하는 FCM 토큰은 다음과 같이 등록할 수 있습니다:
// registerFcmToken 함수는 TalkPlus JS SDK v0.2.4부터 추가된 기능입니다.
// 최신 SDK 버전을 사용하고 있는지 먼저 확인 부탁드립니다
await client.registerFcmToken({fcmToken: '<YOUR_FCM_TOKEN>'});
FCM remote message를 읽기 위해서는 다음과 같이 추가 처리가 필요합니다: (v0.2.8 이상에서만 지원됩니다)
const notification = await client.getNotification(fcmRemoteMessageData);
if (notification.type === 'message') {
console.log(notification.data);
/*
{
type: 'message',
data: {
channel: {<channel object>},
message: {<message object>},
},
}
*/
}
if (['channelAdded', 'channelChanged', 'channelRemoved'].includes(notification.type)) {
console.log(notification.data);
/*
{
type: 'channelAdded', // or 'channelChanged', 'channelRemoved'
data: {
channel: {<channel object>},
},
}
*/
}
if (['memberAdded', 'memberLeft'].includes(notification.type)) {
console.log(notification.data);
/*
{
type: 'memberAdded', // or 'memberLeft'
data: {
channel: {<channel object>},
users: [{<user object>}],
},
}
*/
}
Last modified 1yr ago