UNPKG

@soketi/soketi-js

Version:

Laravel Echo extension that works with Soketi, a Laravel-ready WebSockets service.

44 lines (43 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Connector = void 0; class Connector { constructor(options) { this._defaultOptions = { auth: { headers: {}, }, authEndpoint: '/broadcasting/auth', broadcaster: 'pusher', csrfToken: null, host: null, key: null, namespace: 'App.Events', }; this.setOptions(options); this.connect(); } setOptions(options) { this.options = Object.assign(this._defaultOptions, options); if (this.csrfToken()) { this.options.auth.headers['X-CSRF-TOKEN'] = this.csrfToken(); } return options; } csrfToken() { let selector; if (typeof window !== 'undefined' && window['Laravel'] && window['Laravel'].csrfToken) { return window['Laravel'].csrfToken; } else if (this.options.csrfToken) { return this.options.csrfToken; } else if (typeof document !== 'undefined' && typeof document.querySelector === 'function' && (selector = document.querySelector('meta[name="csrf-token"]'))) { return selector.getAttribute('content'); } return null; } } exports.Connector = Connector;