fix(HH-581): keep widget websocket on visitor auth (#152)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-24 10:54:38 +08:00
committed by GitHub
co-authored by rogee
parent c4ac664deb
commit 2c6bee2b37
5 changed files with 78 additions and 4 deletions
@@ -11,15 +11,18 @@ class BaseActionCableConnector {
app,
pubsubToken,
websocketHost = '',
presenceInterval = PRESENCE_INTERVAL
presenceInterval = PRESENCE_INTERVAL,
useSessionAuth = true
) {
this.consumer = null;
this.subscription = null;
this.websocketHost = websocketHost;
this.pubsubToken = pubsubToken;
this.useSessionAuth = useSessionAuth;
this.app = app;
this.events = {};
this.reconnectTimer = null;
this.ticketFailureLogged = false;
this.isAValidEvent = () => true;
this.connect();
this.triggerPresenceInterval = () => {
@@ -34,14 +37,20 @@ class BaseActionCableConnector {
async connect() {
const wsOrigin = this.websocketHost || window.location.origin;
let websocketURL = `${wsOrigin}/cable`;
if (Cookies.get('cw_d_session_state')) {
if (this.useSessionAuth && Cookies.get('cw_d_session_state')) {
try {
const response = await window.axios.post('/api/v1/auth/ws_ticket');
const ticket = response.data?.data?.ticket;
if (!ticket) throw new Error('missing websocket ticket');
websocketURL += `?ticket=${encodeURIComponent(ticket)}`;
this.usesWSTicket = true;
this.ticketFailureLogged = false;
} catch (error) {
if (!this.ticketFailureLogged) {
// eslint-disable-next-line no-console
console.warn('WebSocket ticket exchange failed; retrying');
this.ticketFailureLogged = true;
}
this.initReconnectTimer();
return;
}