Realtime Event

Client로 로그인 후, 가입되어 있는 채널에서 발생한 이벤트(채널 정보 변경, 새로운 멤버, 메시지 수신 등)를 핸들링 할 수 있습니다.

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 === 'messageDeleted') {
		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 channels changed");
	}

	if (data.type === 'channelRemoved') {
		console.log("one of my 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);

모두에게 공개된 public 및 super_public 타입 채널에서 발생하는 이벤트는 다음과 같이 핸들링 할 수 있습니다.

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("public 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