Realtime Event
Once logged in, you can handle realtime events from joined channels as follows:
const client = new TalkPlus.Client({appId: 'YOUR_APP_ID'});
await client.loginAnonymous({userId: 'your_user_id', username: 'yourName'})
client.on('event', yourListenerFunc);
function yourListenerFunc(data) {
if (data.type === 'message') {
console.log("message event");
}
if (data.type === 'message_deleted') {
console.log("message deleted event");
}
if (data.type === 'channelAdded') {
console.log("new channel added with me as member");
}
if (data.type === 'channelChanged') {
console.log("one of my joined channels changed");
}
if (data.type === 'channelRemoved') {
console.log("one of my joined channels was removed");
}
if (data.type === 'memberAdded') {
console.log("new channel member");
}
if (data.type === 'memberLeft') {
console.log("channel member left");
}
if (data.type === 'memberMuted') {
console.log("channel member muted");
}
if (data.type === 'memberUnmuted') {
console.log("channel member unmuted");
}
if (data.type === 'memberBanned') {
console.log("channel member banned");
}
if (data.type === 'memberUnbanned') {
console.log("channel member unbanned");
}
}
// remove event listener
client.off('event', yourListenerFunc);
You can also listen to events from public channels (public and super_public) as follows:
const client = new TalkPlus.Client({appId: 'YOUR_APP_ID'});
await client.loginAnonymous({userId: 'your_user_id', username: 'yourName'})
client.publicChannelsEventListener.on('event', yourPublicChannelListenerFunc);
function yourPublicChannelListenerFunc(data) {
if (data.type === 'channelAdded') {
console.log("new public channel added");
}
if (data.type === 'channelChanged') {
console.log("onepublic channel changed");
}
if (data.type === 'channelRemoved') {
console.log("public channel removed");
}
if (data.type === 'memberAdded') {
console.log("new public channel member");
}
if (data.type === 'memberLeft') {
console.log("public channel member left");
}
if (data.type === 'memberMuted') {
console.log("public channel member muted");
}
if (data.type === 'memberUnmuted') {
console.log("public channel member unmuted");
}
if (data.type === 'memberBanned') {
console.log("public channel member banned");
}
if (data.type === 'memberUnbanned') {
console.log("public channel member unbanned");
}
}
// remove event listener
client.publicChannelsEventListener.off('event', yourPublicChannelListenerFunc);
Last updated