fix something idon't no
This commit is contained in:
parent
d96884ab75
commit
23ea081757
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,23 +1,26 @@
|
|||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { globalIgnores } from 'eslint/config'
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import reactHooks from "eslint-plugin-react-hooks";
|
||||
import reactRefresh from "eslint-plugin-react-refresh";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { globalIgnores } from "eslint/config";
|
||||
|
||||
export default tseslint.config([
|
||||
globalIgnores(['dist']),
|
||||
globalIgnores(["dist"]),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
files: ["**/*.{ts,tsx}"],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs['recommended-latest'],
|
||||
reactHooks.configs["recommended-latest"],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
rules: {
|
||||
"@typescript-eslint/no-unused-vars": ["off"],
|
||||
},
|
||||
},
|
||||
])
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function initSocket() {
|
|||
|
||||
// Socket.IO events
|
||||
socket.on("connect", () => {
|
||||
console.log("✅ Socket.IO connected");
|
||||
console.log("✅ Socket.IO connectedd");
|
||||
broadcastToPorts({
|
||||
type: "socket",
|
||||
event: "connect",
|
||||
|
|
@ -60,6 +60,7 @@ function initSocket() {
|
|||
|
||||
eventsToListen.forEach((event) => {
|
||||
socket?.on(event, (data: any) => {
|
||||
console.log({ event });
|
||||
broadcastToPorts({
|
||||
type: "socket",
|
||||
event,
|
||||
|
|
@ -143,7 +144,7 @@ chrome.alarms.onAlarm.addListener((alarm) => {
|
|||
if (alarm.name === "reloadEvery4Hours") {
|
||||
console.log(
|
||||
"🔄 Reloading all tabs (every 4 hours)",
|
||||
new Date().toLocaleString()
|
||||
new Date().toLocaleString(),
|
||||
);
|
||||
|
||||
// Reload tất cả các tab đang mở
|
||||
|
|
|
|||
|
|
@ -44,11 +44,3 @@ contentService.startSyncConversations();
|
|||
|
||||
// AUTO SYNC MESAGE PREFIX (INTERNAL)
|
||||
contentService.autoSyncConversationPrefixMessages();
|
||||
|
||||
// setTimeout(async () => {
|
||||
// const a = new TeamsChatService();
|
||||
|
||||
// const conversations = await a.handleGetConversations();
|
||||
|
||||
// console.log({ conversations });
|
||||
// }, 10000);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export class ContentService {
|
|||
document,
|
||||
null,
|
||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
||||
null
|
||||
null,
|
||||
).singleNodeValue;
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ export class ContentService {
|
|||
}
|
||||
|
||||
private async _waitForMessagesToAppear(
|
||||
timeoutMs = 10000
|
||||
timeoutMs = 10000,
|
||||
): Promise<HTMLElement[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chatPaneList = document.getElementById("chat-pane-list");
|
||||
|
|
@ -114,46 +114,46 @@ export class ContentService {
|
|||
});
|
||||
}
|
||||
|
||||
private async _waitForNewMessages(
|
||||
existingItems: HTMLElement[],
|
||||
timeoutMs = 10000
|
||||
): Promise<HTMLElement[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chatPaneList = document.getElementById("chat-pane-list");
|
||||
// private async _waitForNewMessages(
|
||||
// existingItems: HTMLElement[],
|
||||
// timeoutMs = 10000
|
||||
// ): Promise<HTMLElement[]> {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const chatPaneList = document.getElementById("chat-pane-list");
|
||||
|
||||
if (!chatPaneList) {
|
||||
return reject(new Error("#chat-pane-list not found"));
|
||||
}
|
||||
// if (!chatPaneList) {
|
||||
// return reject(new Error("#chat-pane-list not found"));
|
||||
// }
|
||||
|
||||
const getChildren = () =>
|
||||
Array.from(chatPaneList.children) as HTMLElement[];
|
||||
// const getChildren = () =>
|
||||
// Array.from(chatPaneList.children) as HTMLElement[];
|
||||
|
||||
const existingSet = new Set(existingItems);
|
||||
// const existingSet = new Set(existingItems);
|
||||
|
||||
let timeoutHandle: any = null;
|
||||
// let timeoutHandle: any = null;
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
const currentChildren = getChildren();
|
||||
const newItems = currentChildren.filter((el) => !existingSet.has(el));
|
||||
// const observer = new MutationObserver(() => {
|
||||
// const currentChildren = getChildren();
|
||||
// const newItems = currentChildren.filter((el) => !existingSet.has(el));
|
||||
|
||||
if (newItems.length > 0) {
|
||||
observer.disconnect();
|
||||
if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||
resolve(newItems);
|
||||
}
|
||||
});
|
||||
// if (newItems.length > 0) {
|
||||
// observer.disconnect();
|
||||
// if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||
// resolve(newItems);
|
||||
// }
|
||||
// });
|
||||
|
||||
observer.observe(chatPaneList, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
// observer.observe(chatPaneList, {
|
||||
// childList: true,
|
||||
// subtree: true,
|
||||
// });
|
||||
|
||||
timeoutHandle = setTimeout(() => {
|
||||
observer.disconnect();
|
||||
reject(new Error("Timeout waiting for new messages"));
|
||||
}, timeoutMs);
|
||||
});
|
||||
}
|
||||
// timeoutHandle = setTimeout(() => {
|
||||
// observer.disconnect();
|
||||
// reject(new Error("Timeout waiting for new messages"));
|
||||
// }, timeoutMs);
|
||||
// });
|
||||
// }
|
||||
|
||||
private async _waitToloadMessages(stableTime = 300): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
|
|
@ -189,24 +189,24 @@ export class ContentService {
|
|||
});
|
||||
}
|
||||
|
||||
private _getTypeGeo() {
|
||||
const el = document.querySelector(".ck-placeholder");
|
||||
// private _getTypeGeo() {
|
||||
// const el = document.querySelector(".ck-placeholder");
|
||||
|
||||
if (el) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
// if (el) {
|
||||
// const rect = el.getBoundingClientRect();
|
||||
|
||||
return {
|
||||
top: rect.top,
|
||||
left: rect.left,
|
||||
right: rect.right,
|
||||
bottom: rect.bottom,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// top: rect.top,
|
||||
// left: rect.left,
|
||||
// right: rect.right,
|
||||
// bottom: rect.bottom,
|
||||
// width: rect.width,
|
||||
// height: rect.height,
|
||||
// };
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
// return null;
|
||||
// }
|
||||
|
||||
private async _rightClickMessage(date_time: number) {
|
||||
const selector = this.service.elTags.container_chat;
|
||||
|
|
@ -234,7 +234,7 @@ export class ContentService {
|
|||
|
||||
scrollContainer.scrollTop = Math.max(
|
||||
0,
|
||||
scrollContainer.scrollTop - scrollStep
|
||||
scrollContainer.scrollTop - scrollStep,
|
||||
);
|
||||
await delay(200); // Đợi scroll và DOM render lại
|
||||
|
||||
|
|
@ -385,6 +385,8 @@ export class ContentService {
|
|||
|
||||
initialMessages = await this._waitForMessagesToAppear(); // Đợi có item đầu tiên
|
||||
await this._waitToloadMessages();
|
||||
|
||||
console.log({ initialMessages });
|
||||
}
|
||||
|
||||
await this._clickIfExists(this.service.elTags.close_reply_btn);
|
||||
|
|
@ -392,7 +394,7 @@ export class ContentService {
|
|||
await this._rightClickMessage(time);
|
||||
|
||||
const replyBtn: any = document.querySelector(
|
||||
this.service.elTags.reply_btn
|
||||
this.service.elTags.reply_btn,
|
||||
);
|
||||
|
||||
if (replyBtn) {
|
||||
|
|
@ -410,7 +412,7 @@ export class ContentService {
|
|||
fixedHeightChatInput(retry = 20, interval = 2000) {
|
||||
const tryFind = () => {
|
||||
const el = document.querySelector(
|
||||
this.service.elTags.chat_input
|
||||
this.service.elTags.chat_input,
|
||||
) as HTMLElement;
|
||||
|
||||
if (el) {
|
||||
|
|
@ -419,7 +421,7 @@ export class ContentService {
|
|||
} else if (retry > 0) {
|
||||
setTimeout(
|
||||
() => this.fixedHeightChatInput(retry - 1, interval),
|
||||
interval
|
||||
interval,
|
||||
);
|
||||
} else {
|
||||
console.warn("✘ Element not found with provided XPath after retries");
|
||||
|
|
@ -448,7 +450,7 @@ export class ContentService {
|
|||
// Lấy attribute aria-labelledby
|
||||
const ariaValue = document
|
||||
.querySelector(
|
||||
'[aria-labelledby^="cn-normal-notification-main-content-"]'
|
||||
'[aria-labelledby^="cn-normal-notification-main-content-"]',
|
||||
)
|
||||
?.getAttribute("aria-labelledby");
|
||||
|
||||
|
|
@ -478,7 +480,7 @@ export class ContentService {
|
|||
|
||||
if (!roomId) {
|
||||
console.warn(
|
||||
"[Monitor] Could not extract room_id from aria-labelledby"
|
||||
"[Monitor] Could not extract room_id from aria-labelledby",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
@ -563,7 +565,7 @@ export class ContentService {
|
|||
() => {
|
||||
this.getConversations();
|
||||
},
|
||||
120000
|
||||
120000,
|
||||
);
|
||||
console.log("✅ startSyncConversations running");
|
||||
} else {
|
||||
|
|
@ -572,13 +574,73 @@ export class ContentService {
|
|||
}
|
||||
|
||||
// Interval chạy, chỉ add task vào queue
|
||||
autoSyncConversationPrefixMessages() {
|
||||
(window as any)._chatIntervals = (window as any)?._chatIntervals || {};
|
||||
// autoSyncConversationPrefixMessages() {
|
||||
// (window as any)._chatIntervals = (window as any)?._chatIntervals || {};
|
||||
|
||||
// if (!(window as any)._chatIntervals.syncPrefixMessages) {
|
||||
// (window as any)._chatIntervals.syncPrefixMessages = (
|
||||
// window as any
|
||||
// ).setInterval(() => {
|
||||
// (window as any)["is_sync_conversation_prefix"] = true;
|
||||
|
||||
// queue.add(async () => {
|
||||
// try {
|
||||
// const { data } =
|
||||
// (await conversationApi.getConversationByPrefix()) as {
|
||||
// data: ChatItem[];
|
||||
// };
|
||||
// if (!data) return;
|
||||
// for (const chat of data) {
|
||||
// this._clickToConversation(chat.id as string);
|
||||
// await delay(5000);
|
||||
// const currentRoom = this.service.getCurrentRoomInfo();
|
||||
// if (!currentRoom || currentRoom.room_id !== chat.id) return;
|
||||
// const filesMessages = this.filesMessages();
|
||||
// if (filesMessages.length) {
|
||||
// await this.clickToRefreshToken(filesMessages);
|
||||
// }
|
||||
// const messages = this.service.extractAllMessages();
|
||||
// await messageApi.createAndSendToZulip(messages);
|
||||
// await delay(5000);
|
||||
// }
|
||||
// } catch (err) {
|
||||
// console.error(
|
||||
// "❌ autoSyncConversationPrefixMessages error:",
|
||||
// (err as any)?.message,
|
||||
// );
|
||||
// messageApi.sendLog({
|
||||
// type: "error",
|
||||
// message: `auto_to_sync_conersations: ${(err as any)?.message}`,
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }, 60000);
|
||||
|
||||
// console.log("✅ autoSyncConversationPrefixMessages running with PQueue");
|
||||
// } else {
|
||||
// console.log("ℹ️ autoSyncConversationPrefixMessages already running");
|
||||
// }
|
||||
// }
|
||||
|
||||
autoSyncConversationPrefixMessages() {
|
||||
(window as any)._chatIntervals = (window as any)._chatIntervals || {};
|
||||
|
||||
if ((window as any)._chatIntervals.syncPrefixMessages) {
|
||||
console.log("autoSyncConversationPrefixMessages already running");
|
||||
return;
|
||||
}
|
||||
|
||||
let isRunning = false;
|
||||
|
||||
(window as any)._chatIntervals.syncPrefixMessages = window.setInterval(
|
||||
() => {
|
||||
if (isRunning) {
|
||||
console.log("syncPrefixMessages skipped (still running)");
|
||||
return;
|
||||
}
|
||||
|
||||
isRunning = true;
|
||||
|
||||
if (!(window as any)._chatIntervals.syncPrefixMessages) {
|
||||
(window as any)._chatIntervals.syncPrefixMessages = (
|
||||
window as any
|
||||
).setInterval(() => {
|
||||
queue.add(async () => {
|
||||
try {
|
||||
const { data } =
|
||||
|
|
@ -586,7 +648,7 @@ export class ContentService {
|
|||
data: ChatItem[];
|
||||
};
|
||||
|
||||
if (!data) return;
|
||||
if (!data?.length) return;
|
||||
|
||||
for (const chat of data) {
|
||||
this._clickToConversation(chat.id as string);
|
||||
|
|
@ -594,37 +656,39 @@ export class ContentService {
|
|||
await delay(5000);
|
||||
|
||||
const currentRoom = this.service.getCurrentRoomInfo();
|
||||
|
||||
if (!currentRoom || currentRoom.room_id !== chat.id) return;
|
||||
if (!currentRoom || currentRoom.room_id !== chat.id) {
|
||||
console.warn("room mismatch, skip:", chat.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
const filesMessages = this.filesMessages();
|
||||
|
||||
if (filesMessages.length) {
|
||||
await this.clickToRefreshToken(filesMessages);
|
||||
}
|
||||
|
||||
const messages = this.service.extractAllMessages();
|
||||
|
||||
await messageApi.createAndSendToZulip(messages);
|
||||
|
||||
await delay(5000);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"❌ autoSyncConversationPrefixMessages error:",
|
||||
(err as any)?.message
|
||||
"autoSyncConversationPrefixMessages error:",
|
||||
(err as any)?.message,
|
||||
);
|
||||
|
||||
messageApi.sendLog({
|
||||
type: "error",
|
||||
message: `auto_to_sync_conersations: ${(err as any)?.message}`,
|
||||
});
|
||||
} finally {
|
||||
isRunning = false; // 🔑 cực kỳ quan trọng
|
||||
}
|
||||
});
|
||||
}, 40000);
|
||||
},
|
||||
60000,
|
||||
);
|
||||
|
||||
console.log("✅ autoSyncConversationPrefixMessages running with PQueue");
|
||||
} else {
|
||||
console.log("ℹ️ autoSyncConversationPrefixMessages already running");
|
||||
}
|
||||
console.log("autoSyncConversationPrefixMessages running safely");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@
|
|||
import { messageApi } from "@/api/message-api.service";
|
||||
|
||||
export class TeamsChatService {
|
||||
private readonly MY_NAME = "Apactech com";
|
||||
// private readonly MY_NAME = "Apactech com";
|
||||
public lastMessage?: IMessage;
|
||||
public initialHistories: IMessage[] = [];
|
||||
|
||||
public elTags = {
|
||||
container_scroll:
|
||||
"/html/body/div[1]/div/div/div/div[5]/div[1]/div[1]/div[2]/div[1]/div[1]/div",
|
||||
conatainer_conversations:
|
||||
"/html/body/div[1]/div/div/div/div[5]/div[1]/div[1]/div[2]/div[1]/div[1]/div/div[1]",
|
||||
container_scroll: '//*[@data-testid="simple-collab-rail"]',
|
||||
conatainer_conversations: '//*[@data-testid="simple-collab-dnd-rail"]',
|
||||
container_chat: '[data-testid="message-wrapper"]',
|
||||
|
||||
root_id: '[aria-selected="true"] [id^="chat-list-item"]',
|
||||
|
|
@ -24,13 +22,13 @@ export class TeamsChatService {
|
|||
private _getImageFormEl(el: HTMLElement): HTMLImageElement[] {
|
||||
// Tìm tất cả img có data-gallery-src trong el
|
||||
let sharedImages = Array.from(
|
||||
el.querySelectorAll("img[data-gallery-src]")
|
||||
el.querySelectorAll("img[data-gallery-src]"),
|
||||
) as HTMLImageElement[];
|
||||
|
||||
// Nếu không tìm thấy thì thử tìm trong parentElement
|
||||
if (sharedImages.length === 0 && el.parentElement) {
|
||||
sharedImages = Array.from(
|
||||
el.parentElement.querySelectorAll("img[data-gallery-src]")
|
||||
el.parentElement.querySelectorAll("img[data-gallery-src]"),
|
||||
) as HTMLImageElement[];
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +172,7 @@ export class TeamsChatService {
|
|||
|
||||
// Lấy emoji
|
||||
const emojiImgs = Array.from(
|
||||
el.querySelectorAll("img[itemtype]")
|
||||
el.querySelectorAll("img[itemtype]"),
|
||||
) as HTMLImageElement[];
|
||||
const emojiAlts = emojiImgs
|
||||
.map((img) => img.getAttribute("alt") || "")
|
||||
|
|
@ -189,11 +187,11 @@ export class TeamsChatService {
|
|||
|
||||
public parseMessageElement(el: Element, isMine = false): IMessage | null {
|
||||
const timestampEl = el.querySelector(
|
||||
isMine ? ".fui-ChatMyMessage__timestamp" : ".fui-ChatMessage__timestamp"
|
||||
isMine ? ".fui-ChatMyMessage__timestamp" : ".fui-ChatMessage__timestamp",
|
||||
) as HTMLElement | null;
|
||||
|
||||
const authorEl = el.querySelector(
|
||||
isMine ? ".fui-ChatMyMessage__author" : ".fui-ChatMessage__author"
|
||||
isMine ? ".fui-ChatMyMessage__author" : ".fui-ChatMessage__author",
|
||||
) as HTMLElement | null;
|
||||
|
||||
if (!timestampEl) return null;
|
||||
|
|
@ -207,7 +205,7 @@ export class TeamsChatService {
|
|||
: Number(timestampEl.id.replace("timestamp-", ""));
|
||||
|
||||
const contentEl = document.querySelector(
|
||||
`#content-${dateTime}`
|
||||
`#content-${dateTime}`,
|
||||
) as HTMLElement | null;
|
||||
|
||||
(contentEl as any)["date_time"] = dateTime;
|
||||
|
|
@ -242,13 +240,13 @@ export class TeamsChatService {
|
|||
|
||||
extractAllMessages(): IMessage[] {
|
||||
const myMessages: IMessage[] = Array.from(
|
||||
document.querySelectorAll(".fui-ChatMyMessage")
|
||||
document.querySelectorAll(".fui-ChatMyMessage"),
|
||||
)
|
||||
.map((el) => this.parseMessageElement(el, true))
|
||||
.filter((msg): msg is IMessage => msg !== null);
|
||||
|
||||
const otherMessages: IMessage[] = Array.from(
|
||||
document.querySelectorAll(".fui-ChatMessage")
|
||||
document.querySelectorAll(".fui-ChatMessage"),
|
||||
)
|
||||
.map((el) => this.parseMessageElement(el, false))
|
||||
.filter((msg): msg is IMessage => msg !== null);
|
||||
|
|
@ -267,7 +265,7 @@ export class TeamsChatService {
|
|||
const allMessages = this.extractAllMessages();
|
||||
|
||||
const lastIndex = allMessages.findIndex(
|
||||
(msg) => msg.time === this.lastMessage?.time
|
||||
(msg) => msg.time === this.lastMessage?.time,
|
||||
);
|
||||
|
||||
const newMessages = allMessages.slice(lastIndex + 1);
|
||||
|
|
@ -302,14 +300,14 @@ export class TeamsChatService {
|
|||
}
|
||||
|
||||
private async _getConversationsInfo(
|
||||
xpath: string = this.elTags.conatainer_conversations
|
||||
xpath: string = this.elTags.conatainer_conversations,
|
||||
): Promise<ChatItem[]> {
|
||||
const result = document.evaluate(
|
||||
xpath,
|
||||
document,
|
||||
null,
|
||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
||||
null
|
||||
null,
|
||||
).singleNodeValue as HTMLElement | null;
|
||||
|
||||
if (!result) {
|
||||
|
|
@ -321,15 +319,15 @@ export class TeamsChatService {
|
|||
return [];
|
||||
}
|
||||
|
||||
// Lọc phần tử con có role="none"
|
||||
const matchedChildren = Array.from(result.children).filter(
|
||||
(child: Element) => {
|
||||
return child.getAttribute("role") === "none";
|
||||
}
|
||||
const chatItems = Array.from(
|
||||
result.querySelectorAll('[data-item-type="chat"]'),
|
||||
);
|
||||
|
||||
const data: ChatItem[] = matchedChildren.map((child: Element): ChatItem => {
|
||||
const id = child.id || null;
|
||||
const data: ChatItem[] = chatItems.map((child: Element): ChatItem => {
|
||||
const treeItemValue = child.getAttribute("data-fui-tree-item-value") || "";
|
||||
const lastSegment = treeItemValue.split("/").pop() || "";
|
||||
const id = lastSegment.includes("|") ? lastSegment.split("|")[1] : null;
|
||||
|
||||
const titleId = `title-chat-list-item_${id}`;
|
||||
const titleElement = document.getElementById(titleId);
|
||||
const spanText = titleElement?.innerText || null;
|
||||
|
|
@ -360,7 +358,7 @@ export class TeamsChatService {
|
|||
maxStableRounds?: number; // Số vòng scroll không thay đổi trước khi dừng
|
||||
delay?: number; // Thời gian chờ giữa mỗi lần scroll (ms)
|
||||
maxScrolls?: number; // Giới hạn số lần scroll tối đa
|
||||
}
|
||||
},
|
||||
): Promise<void> {
|
||||
const {
|
||||
maxStableRounds = 5,
|
||||
|
|
@ -373,7 +371,7 @@ export class TeamsChatService {
|
|||
document,
|
||||
null,
|
||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
||||
null
|
||||
null,
|
||||
).singleNodeValue as HTMLElement | null;
|
||||
|
||||
if (!container) {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@ import * as fs from 'fs';
|
|||
import { SocketIoAdapter } from './socket-adapter';
|
||||
|
||||
async function bootstrap() {
|
||||
const httpsOptions = {
|
||||
key: fs.readFileSync('ssl/localhost+1-key.pem'),
|
||||
cert: fs.readFileSync('ssl/localhost+1.pem'),
|
||||
};
|
||||
// const httpsOptions = {
|
||||
// key: fs.readFileSync('ssl/localhost+1-key.pem'),
|
||||
// cert: fs.readFileSync('ssl/localhost+1.pem'),
|
||||
// };
|
||||
|
||||
const app = await NestFactory.create(AppModule, { httpsOptions });
|
||||
const app = await NestFactory.create(AppModule);
|
||||
// const app = await NestFactory.create(AppModule, { httpsOptions });
|
||||
|
||||
const prefix_version = process.env.PREFIX_VERSION;
|
||||
|
||||
|
|
@ -54,12 +55,14 @@ async function bootstrap() {
|
|||
|
||||
useContainer(app.select(AppModule), { fallbackOnErrors: true });
|
||||
|
||||
app.useWebSocketAdapter(new SocketIoAdapter(app));
|
||||
|
||||
await app.listen(Number(process.env.APP_API_PORT));
|
||||
|
||||
// ===== App cho WebSocket (WS hoặc WSS) =====
|
||||
const wsApp = await NestFactory.create(AppModule);
|
||||
wsApp.useWebSocketAdapter(new SocketIoAdapter(wsApp));
|
||||
await wsApp.listen(Number(process.env.APP_SOCKET_PORT));
|
||||
// // ===== App cho WebSocket (WS hoặc WSS) =====
|
||||
// const wsApp = await NestFactory.create(AppModule);
|
||||
// wsApp.useWebSocketAdapter(new SocketIoAdapter(wsApp));
|
||||
// await wsApp.listen(Number(process.env.APP_SOCKET_PORT));
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export class MessagesGateway implements OnGatewayConnection {
|
|||
|
||||
for (const event of eventsToForward) {
|
||||
this.event.on(event, (data) => {
|
||||
console.log({ event, data });
|
||||
this.server.emit(event, data);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue