From 4ecc92ad6d7d4076cc6a93079528a2ec526d20ef Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 12 May 2025 17:13:41 +0530 Subject: [PATCH] feat: setup wss --- app/javascript/dashboard/helper/actionCable.js | 9 +++++++-- app/javascript/dashboard/store/modules/auth.js | 3 +++ app/javascript/entrypoints/ui.js | 11 +++++++---- public/test-components.html | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/javascript/dashboard/helper/actionCable.js b/app/javascript/dashboard/helper/actionCable.js index adb33eb6d..95a660aaf 100644 --- a/app/javascript/dashboard/helper/actionCable.js +++ b/app/javascript/dashboard/helper/actionCable.js @@ -7,7 +7,10 @@ import { emitter } from 'shared/helpers/mitt'; class ActionCableConnector extends BaseActionCableConnector { constructor(app, pubsubToken) { const { websocketURL = '' } = window.chatwootConfig || {}; - super(app, pubsubToken, websocketURL); + + // eslint-disable-next-line no-underscore-dangle + const wsURL = websocketURL || window.__WEBSOCKET_URL__ || ''; + super(app, pubsubToken, wsURL); this.CancelTyping = []; this.events = { 'message.created': this.onMessageCreated, @@ -44,7 +47,9 @@ class ActionCableConnector extends BaseActionCableConnector { }; isAValidEvent = data => { - return this.app.$store.getters.getCurrentAccountId === data.account_id; + // eslint-disable-next-line no-underscore-dangle + const currentAccountId = this.app.$store.getters.getCurrentAccountId; + return currentAccountId === data.account_id; }; onMessageUpdated = data => { diff --git a/app/javascript/dashboard/store/modules/auth.js b/app/javascript/dashboard/store/modules/auth.js index fa49af339..642e20e47 100644 --- a/app/javascript/dashboard/store/modules/auth.js +++ b/app/javascript/dashboard/store/modules/auth.js @@ -51,6 +51,9 @@ export const getters = { }, getCurrentAccountId(_, __, rootState) { + // eslint-disable-next-line no-underscore-dangle + if (window.__WOOT_ACCOUNT_ID__) return window.__WOOT_ACCOUNT_ID__; + if (rootState.route.params && rootState.route.params.accountId) { return Number(rootState.route.params.accountId); } diff --git a/app/javascript/entrypoints/ui.js b/app/javascript/entrypoints/ui.js index f94be45c3..b3b17ded2 100644 --- a/app/javascript/entrypoints/ui.js +++ b/app/javascript/entrypoints/ui.js @@ -7,13 +7,14 @@ import 'floating-vue/dist/style.css'; import tailwindStyles from '../dashboard/assets/scss/_woot.scss?inline'; import VueDOMPurifyHTML from 'vue-dompurify-html'; -import { domPurifyConfig } from 'shared/helpers/HTMLSanitizer.js'; +import { domPurifyConfig } from '../shared/helpers/HTMLSanitizer.js'; -import store from 'dashboard/store'; -import constants from 'dashboard/constants/globals'; +import store from '../dashboard/store'; +import constants from '../dashboard/constants/globals'; import axios from 'axios'; import createAxios from '../ui/axios'; -import commonHelpers from 'dashboard/helper/commons'; +import commonHelpers from '../dashboard/helper/commons'; +import vueActionCable from '../dashboard/helper/actionCable'; import MessageList from '../ui/MessageList.vue'; import i18nMessages from '../dashboard/i18n'; @@ -30,6 +31,8 @@ const ceOptions = { app.use(store); app.use(i18n); app.use(VueDOMPurifyHTML, domPurifyConfig); + // eslint-disable-next-line no-underscore-dangle + vueActionCable.init(store, window.__PUBSUB_TOKEN__); // I18n has to be injected inside that can be picked // up by the compononent, the API stays the same, just use `useI18n` // https://vue-i18n.intlify.dev/guide/advanced/wc diff --git a/public/test-components.html b/public/test-components.html index 6c0e1c3be..112a16203 100644 --- a/public/test-components.html +++ b/public/test-components.html @@ -9,6 +9,8 @@ window.__WOOT_ACCOUNT_ID__ = 1; window.__WOOT_API_HOST__ = 'http://localhost:3000'; window.__WOOT_ACCESS_TOKEN__ = 'code'; + window.__PUBSUB_TOKEN__ = 'pubsub'; + window.__WEBSOCKET_URL__ = 'ws://localhost:3000';