Socket
Socket
Sign inDemoInstall

laravel-wave

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.0 to 0.7.1

6

CHANGELOG.md
# Changelog
## [Unreleased](https://github.com/qruto/laravel-wave-client/compare/v0.7.0...main)
## [Unreleased](https://github.com/qruto/laravel-wave-client/compare/0.7.0...main)

@@ -14,1 +14,5 @@ ## 0.5.1 - 2022-08-02

Checkout ➡️ [README](https://github.com/qruto/laravel-wave/blob/main/README.md).
## [0.7.0](https://github.com/qruto/laravel-wave-client/compare/v0.7.0...0.7.0) - 2023-06-09
[Release notes](https://github.com/qruto/laravel-wave/releases/tag/0.7.0) 📣 ➡︎

2

dist/index.iife.d.ts

@@ -1,1 +0,1 @@

export { default } from './wave';
export { Wave, WaveConnector } from './wave';

@@ -1436,2 +1436,1 @@ 'use strict';

exports.WaveConnector = WaveConnector;
exports["default"] = Wave;
import { Wave } from "./wave-broadcaster";
import { WaveConnector } from "./echo-broadcaster/wave-connector";
export default Wave;
export { Wave, WaveConnector, };

@@ -1,2 +0,2 @@

var Wave = (function (fetchEventSource) {
var Wave = (function (exports, fetchEventSource, laravelEcho) {
'use strict';

@@ -305,2 +305,11 @@

}
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _classCallCheck(instance, Constructor) {

@@ -468,2 +477,25 @@ if (!(instance instanceof Constructor)) {

}
function _superPropBase(object, property) {
while (!Object.prototype.hasOwnProperty.call(object, property)) {
object = _getPrototypeOf(object);
if (object === null) break;
}
return object;
}
function _get() {
if (typeof Reflect !== "undefined" && Reflect.get) {
_get = Reflect.get.bind();
} else {
_get = function _get(target, property, receiver) {
var base = _superPropBase(target, property);
if (!base) return;
var desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.get) {
return desc.get.call(arguments.length < 3 ? target : receiver);
}
return desc.value;
};
}
return _get.apply(this, arguments);
}
function _toPrimitive(input, hint) {

@@ -948,4 +980,461 @@ if (typeof input !== "object" || input === null) return input;

return Wave;
var Connector = /*#__PURE__*/function () {
/**
* Create a new class instance.
*/
function Connector(options) {
_classCallCheck(this, Connector);
/**
* Default connector options.
*/
this._defaultOptions = {
auth: {
headers: {}
},
authEndpoint: '/broadcasting/auth',
userAuthentication: {
endpoint: '/broadcasting/user-auth',
headers: {}
},
broadcaster: 'pusher',
csrfToken: null,
bearerToken: null,
host: null,
key: null,
namespace: 'App.Events'
};
this.setOptions(options);
this.connect();
}
/**
* Merge the custom options with the defaults.
*/
_createClass(Connector, [{
key: "setOptions",
value: function setOptions(options) {
this.options = _extends(this._defaultOptions, options);
var token = this.csrfToken();
if (token) {
this.options.auth.headers['X-CSRF-TOKEN'] = token;
this.options.userAuthentication.headers['X-CSRF-TOKEN'] = token;
}
token = this.options.bearerToken;
if (token) {
this.options.auth.headers['Authorization'] = 'Bearer ' + token;
this.options.userAuthentication.headers['Authorization'] = 'Bearer ' + token;
}
return options;
}
/**
* Extract the CSRF token from the page.
*/
}, {
key: "csrfToken",
value: function csrfToken() {
var 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;
}
}]);
return Connector;
}();
})(fetchEventSource);
/**
* Event name formatter
*/
var EventFormatter = /*#__PURE__*/function () {
/**
* Create a new class instance.
*/
function EventFormatter(namespace) {
_classCallCheck(this, EventFormatter);
this.setNamespace(namespace);
}
/**
* Format the given event name.
*/
_createClass(EventFormatter, [{
key: "format",
value: function format(event) {
if (event.charAt(0) === '.' || event.charAt(0) === '\\') {
return event.substr(1);
} else if (this.namespace) {
event = this.namespace + '.' + event;
}
return event.replace(/\./g, '\\');
}
/**
* Set the event namespace.
*/
}, {
key: "setNamespace",
value: function setNamespace(value) {
this.namespace = value;
}
}]);
return EventFormatter;
}();
var WaveChannel = /*#__PURE__*/function (_Channel) {
_inherits(WaveChannel, _Channel);
var _super = _createSuper(WaveChannel);
/**
* Create a new class instance.
*/
function WaveChannel(connection, name, options) {
var _this;
_classCallCheck(this, WaveChannel);
_this = _super.call(this);
/**
* The event callbacks applied to the channel.
*/
_this.events = [];
/**
* The event callbacks applied to the channel.
*/
_this.name = name;
_this.connection = connection;
_this.options = options;
_this.eventFormatter = new EventFormatter(_this.options.namespace);
return _this;
}
/**
* Listen for an event on the channel instance.
*/
_createClass(WaveChannel, [{
key: "listen",
value: function listen(event, callback) {
this.on(this.eventFormatter.format(event), callback);
return this;
}
/**
* Stop listening for an event on the channel instance.
*/
}, {
key: "stopListening",
value: function stopListening(event) {
var name = this.eventFormatter.format(event);
this.connection.unsubscribe("".concat(this.name, ".").concat(name));
this.events = this.events.filter(function (e) {
return e !== name;
});
return this;
}
/**
* Bind the channel's socket to an event and store the callback.
*/
}, {
key: "on",
value: function on(event, callback) {
if (!this.events.find(function (e) {
return e === event;
})) {
this.events.push(event);
}
this.connection.subscribe("".concat(this.name, ".").concat(event), callback);
return this;
}
}, {
key: "unsubscribe",
value: function unsubscribe() {
var _this2 = this;
this.events.forEach(function (event) {
_this2.connection.unsubscribe("".concat(_this2.name, ".").concat(event));
});
this.events = [];
}
}, {
key: "subscribed",
value: function subscribed(callback) {
this.connection.afterConnect(callback);
return this;
}
}, {
key: "error",
value: function error(callback) {
return callback();
}
}]);
return WaveChannel;
}(laravelEcho.Channel);
var WavePrivateChannel = /*#__PURE__*/function (_WaveChannel) {
_inherits(WavePrivateChannel, _WaveChannel);
var _super = _createSuper(WavePrivateChannel);
function WavePrivateChannel(connection, name, options) {
var _this;
_classCallCheck(this, WavePrivateChannel);
_this = _super.call(this, connection, name, options);
_this.authorized = false;
_this.afterAuthCallbacks = {};
_this.whisperCallbacks = new Map();
_this.errorCallbacks = [];
_this.auth = authRequest(name, connection, _this.options);
_this.auth.response["catch"](function (error) {
return _this.errorCallbacks.forEach(function (callback) {
return callback(error);
});
});
return _this;
}
_createClass(WavePrivateChannel, [{
key: "whisper",
value: function whisper(eventName, data) {
var _this2 = this;
request(this.connection).post(this.options.endpoint + '/whisper', this.options, {
channel_name: this.name,
event_name: eventName,
data: data
})["catch"](function (error) {
return _this2.errorCallbacks.forEach(function (callback) {
return callback(error);
});
});
return this;
}
}, {
key: "listenForWhisper",
value: function listenForWhisper(event, callback) {
var listener = function listener(data) {
callback(Array.isArray(data) && data.length === 1 && _typeof(data[0]) !== 'object' ? data[0] : data);
};
this.whisperCallbacks.set(callback, listener);
_get(_getPrototypeOf(WavePrivateChannel.prototype), "listenForWhisper", this).call(this, event, listener);
return this;
}
}, {
key: "stopListeningForWhisper",
value: function stopListeningForWhisper(event, callback) {
if (callback) {
callback = this.whisperCallbacks.get(callback);
this.whisperCallbacks["delete"](callback);
}
_get(_getPrototypeOf(WavePrivateChannel.prototype), "stopListeningForWhisper", this).call(this, event, callback);
return this;
}
}, {
key: "on",
value: function on(event, callback) {
var _this3 = this;
this.auth.after(function () {
return _get(_getPrototypeOf(WavePrivateChannel.prototype), "on", _this3).call(_this3, event, callback);
});
return this;
}
}, {
key: "error",
value: function error(callback) {
this.errorCallbacks.push(callback);
return this;
}
}]);
return WavePrivateChannel;
}(WaveChannel);
var WavePresenceChannel = /*#__PURE__*/function (_WavePrivateChannel) {
_inherits(WavePresenceChannel, _WavePrivateChannel);
var _super = _createSuper(WavePresenceChannel);
function WavePresenceChannel(connection, name, options) {
var _this;
_classCallCheck(this, WavePresenceChannel);
_this = _super.call(this, connection, name, options);
_this.joined = false;
_this.joinRequest = authRequest(name, connection, _extends(_extends({}, _this.options), {
authEndpoint: _this.options.endpoint + '/presence-channel-users'
})).after(function () {
return _this.joined = true;
});
_this.joinRequest.response["catch"](function (error) {
_this.errorCallbacks.forEach(function (callback) {
return callback(error);
});
});
if (typeof window !== 'undefined') {
window.addEventListener('beforeunload', function () {
return __awaiter(_assertThisInitialized(_this), void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return this.unsubscribe();
case 2:
return _context.abrupt("return", _context.sent);
case 3:
case "end":
return _context.stop();
}
}, _callee, this);
}));
});
}
return _this;
}
_createClass(WavePresenceChannel, [{
key: "here",
value: function here(callback) {
var _this2 = this;
var getUsersList = function getUsersList(response) {
return __awaiter(_this2, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.t0 = callback;
_context2.next = 3;
return response.json();
case 3:
_context2.t1 = _context2.sent;
return _context2.abrupt("return", (0, _context2.t0)(_context2.t1));
case 5:
case "end":
return _context2.stop();
}
}, _callee2);
}));
};
if (this.joined) {
request(this.connection).get(this.options.endpoint + '/presence-channel-users', this.options, {
channel_name: this.name
}).then(getUsersList)["catch"](function (error) {
return _this2.errorCallbacks.forEach(function (callback) {
return callback(error);
});
});
return this;
}
this.joinRequest.after(getUsersList);
return this;
}
/**
* Listen for someone joining the channel.
*/
}, {
key: "joining",
value: function joining(callback) {
this.listen('.join', callback);
return this;
}
/**
* Listen for someone leaving the channel.
*/
}, {
key: "leaving",
value: function leaving(callback) {
this.listen('.leave', callback);
return this;
}
}, {
key: "unsubscribe",
value: function unsubscribe() {
var _this3 = this;
return new Promise(function (resolve, reject) {
_this3.joinRequest.after(function () {
request(_this3.connection, true)["delete"](_this3.options.endpoint + '/presence-channel-users', _this3.options, {
channel_name: _this3.name
}).then(function () {
_get(_getPrototypeOf(WavePresenceChannel.prototype), "unsubscribe", _this3).call(_this3);
resolve(null);
})["catch"](function (error) {
_this3.errorCallbacks.forEach(function (callback) {
return callback(error);
});
reject(error);
});
});
});
}
}]);
return WavePresenceChannel;
}(WavePrivateChannel);
var WaveConnector = /*#__PURE__*/function (_Connector) {
_inherits(WaveConnector, _Connector);
var _super = _createSuper(WaveConnector);
function WaveConnector(options) {
var _this;
_classCallCheck(this, WaveConnector);
_this = _super.call(this, _extends({
endpoint: '/wave'
}, options));
_this.channels = {};
return _this;
}
_createClass(WaveConnector, [{
key: "connect",
value: function connect() {
this.connection = new EventSourceConnection(this.options.endpoint, this.options.request, {
pauseInactive: this.options.pauseInactive,
debug: this.options.debug
});
}
}, {
key: "channel",
value: function channel(_channel) {
if (!this.channels[_channel]) {
this.channels[_channel] = new WaveChannel(this.connection, _channel, this.options);
}
return this.channels[_channel];
}
}, {
key: "presenceChannel",
value: function presenceChannel(channel) {
if (!this.channels['presence-' + channel]) {
this.channels['presence-' + channel] = new WavePresenceChannel(this.connection, 'presence-' + channel, this.options);
}
return this.channels['presence-' + channel];
}
}, {
key: "privateChannel",
value: function privateChannel(channel) {
if (!this.channels['private-' + channel]) {
this.channels['private-' + channel] = new WavePrivateChannel(this.connection, 'private-' + channel, this.options);
}
return this.channels['private-' + channel];
}
}, {
key: "disconnect",
value: function disconnect() {
this.connection.disconnect();
}
}, {
key: "leave",
value: function leave(channel) {
var _this2 = this;
var channels = [channel, 'private-' + channel, 'presence-' + channel];
channels.forEach(function (name) {
_this2.leaveChannel(name);
});
}
/**
* Leave the given channel.
*/
}, {
key: "leaveChannel",
value: function leaveChannel(channel) {
if (this.channels[channel]) {
this.channels[channel].unsubscribe();
delete this.channels[channel];
}
}
}, {
key: "socketId",
value: function socketId() {
return this.connection.getId();
}
}]);
return WaveConnector;
}(Connector);
exports.Wave = Wave;
exports.WaveConnector = WaveConnector;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
})({}, fetchEventSource, Echo);

@@ -1430,2 +1430,2 @@ import { fetchEventSource } from '@microsoft/fetch-event-source';

export { Wave, WaveConnector, Wave as default };
export { Wave, WaveConnector };
{
"name": "laravel-wave",
"version": "0.7.0",
"version": "0.7.1",
"description": "Server-sent event client for Laravel broadcasting system.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -30,10 +30,18 @@ import babel from '@rollup/plugin-babel';

plugins,
external: ['laravel-echo'],
external: ['laravel-echo', '@microsoft/fetch-event-source'],
},
{
input: './src/index.iife.ts',
output: [{ file: './dist/wave.iife.js', format: 'iife', name: 'Wave' }],
output: [{
file: './dist/wave.iife.js',
format: 'iife',
name: 'Wave',
globals: {
'@microsoft/fetch-event-source': 'fetchEventSource',
'laravel-echo': 'Echo',
},
}],
plugins,
external: ['laravel-echo'],
external: ['laravel-echo', '@microsoft/fetch-event-source'],
},
];

@@ -1,1 +0,1 @@

export { default } from './wave';
export { Wave, WaveConnector } from './wave';
import { Wave } from "./wave-broadcaster";
import { WaveConnector } from "./echo-broadcaster/wave-connector";
export default Wave;
export {

@@ -7,0 +5,0 @@ Wave,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc