_63const channelTopics = new Map();
_63const rtm = new RTM("appid", "uid", rtmConfig);
_63rtm.addEventListener("topic", (topicEvent) => {
_63 console.log(topicEvent, "topic");
_63 const topicsCache = channelTopics.get(topicEvent.channelName) ?? new Map();
_63 const remoteLeaved = new Map();
_63 const remoteJoined = new Map();
_63 const { publisher: user, channelName } = topicEvent;
_63 if (topicEvent.eventType === "SNAPSHOT") {
_63 topicEvent.topicInfos.forEach(({ publishers, topicName }) => {
_63 remoteJoined.set(topicName, []);
_63 remoteLeaved.set(topicName, []);
_63 const topicDetailsByCache = topicsCache.get(topicName) ?? [];
_63 topicDetailsByCache.forEach(({ publisherMeta, publisherUserId: targetUid }) => {
_63 if (!publishers.some(({ publisherUserId: eventUid }) => targetUid === eventUid)) {
_63 remoteLeaved.get(topicName)?.push({ publisherUserId: targetUid, publisherMeta });
_63 topicDetailsByCache.filter(({ publisherUserId: cacheUid }) => cacheUid !== targetUid);
_63 publishers.forEach(({ publisherMeta, publisherUserId: eventUid }) => {
_63 if (!topicDetailsByCache.some(({ publisherUserId: cacheUid }) => eventUid === cacheUid)) {
_63 remoteJoined.get(topicName)?.push({ publisherUserId: eventUid, publisherMeta });
_63 topicDetailsByCache.push({ publisherUserId: eventUid, publisherMeta });
_63 topicsCache.set(topicName, topicDetailsByCache);
_63 // Your code for handling the updated event
_63 topicEvent.topicInfos.forEach(({ topicName, publishers }) => {
_63 const topicDetailsByCache = topicsCache.get(topicName) ?? [];
_63 publishers.forEach(({ publisherMeta, publisherUserId }) => {
_63 if (user === publisherUserId) {
_63 switch (topicEvent.eventType) {
_63 case "REMOTE_JOIN": {
_63 topicDetailsByCache.push({ publisherMeta, publisherUserId });
_63 case "REMOTE_LEAVE": {
_63 topicDetailsByCache.filter(({ publisherUserId: uid }) => uid !== publisherUserId);
_63 topicsCache.set(topicName, topicDetailsByCache);
_63 channelTopics.set(channelName, topicsCache);
_63 console.log({ remoteJoined, remoteLeaved, channelTopics, channelName }, "topic diff for debug");