Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

laravel-echo

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laravel-echo - npm Package Compare versions

Comparing version 0.0.22 to 0.0.23

362

dist/echo.js

@@ -63,2 +63,59 @@ var classCallCheck = function (instance, Constructor) {

var Connector = function () {
function Connector(options) {
classCallCheck(this, Connector);
this._defaultOptions = {
auth: {
headers: {}
},
authEndpoint: '/broadcasting/auth',
connector: 'pusher',
csrfToken: null,
host: null,
namespace: null,
pusherKey: null
};
this.setOptions(options);
this.connect();
}
createClass(Connector, [{
key: 'setOptions',
value: function setOptions(options) {
this.options = _extends(this._defaultOptions, options);
if (this.csrfToken()) {
this.options.auth.headers['X-CSRF-TOKEN'] = this.csrfToken();
}
return options;
}
}, {
key: 'csrfToken',
value: function csrfToken() {
var selector = document.querySelector('meta[name="csrf-token"]');
if (this.options.csrfToken) {
return this.options.csrfToken;
} else if (selector) {
return selector.getAttribute('content');
}
return null;
}
}]);
return Connector;
}();
var Channel = function () {
function Channel() {
classCallCheck(this, Channel);
}
createClass(Channel, [{
key: 'notification',
value: function notification(callback) {
return this.listen('.Illuminate.Notifications.Events.BroadcastNotificationCreated', callback);
}
}]);
return Channel;
}();
var EventFormatter = function () {

@@ -90,21 +147,20 @@ function EventFormatter() {

var Channel = function () {
function Channel(channel, connector) {
classCallCheck(this, Channel);
var PusherChannel = function (_Channel) {
inherits(PusherChannel, _Channel);
this.channel = channel;
this.connector = connector;
this.eventFormatter = new EventFormatter();
if (this.connector.options.namespace) {
this.eventFormatter.namespace(this.connector.options.namespace);
function PusherChannel(channel, connector) {
classCallCheck(this, PusherChannel);
var _this = possibleConstructorReturn(this, Object.getPrototypeOf(PusherChannel).call(this));
_this.channel = channel;
_this.connector = connector;
_this.eventFormatter = new EventFormatter();
if (_this.connector.options.namespace) {
_this.eventFormatter.namespace(_this.connector.options.namespace);
}
return _this;
}
createClass(Channel, [{
key: 'bind',
value: function bind(event, callback) {
var func = typeof this.channel.bind === 'function' ? 'bind' : 'on';
this.channel[func](event, callback);
}
}, {
createClass(PusherChannel, [{
key: 'listen',

@@ -116,19 +172,19 @@ value: function listen(event, callback) {

}, {
key: 'notification',
value: function notification(callback) {
return this.listen('.Illuminate.Notifications.Events.BroadcastNotificationCreated', callback);
key: 'bind',
value: function bind(event, callback) {
this.channel.bind(event, callback);
}
}]);
return Channel;
}();
return PusherChannel;
}(Channel);
var PresenceChannel = function (_Channel) {
inherits(PresenceChannel, _Channel);
var PusherPresenceChannel = function (_PusherChannel) {
inherits(PusherPresenceChannel, _PusherChannel);
function PresenceChannel() {
classCallCheck(this, PresenceChannel);
return possibleConstructorReturn(this, Object.getPrototypeOf(PresenceChannel).apply(this, arguments));
function PusherPresenceChannel() {
classCallCheck(this, PusherPresenceChannel);
return possibleConstructorReturn(this, Object.getPrototypeOf(PusherPresenceChannel).apply(this, arguments));
}
createClass(PresenceChannel, [{
createClass(PusherPresenceChannel, [{
key: 'here',

@@ -138,10 +194,6 @@ value: function here(callback) {

this.bind(this.connector.updating, function (data) {
var members = data;
if (data.members) {
members = Object.keys(data.members).map(function (k) {
return data.members[k];
});
}
callback(members, _this2.channel);
this.bind('pusher:subscription_succeeded', function (data) {
callback(Object.keys(data.members).map(function (k) {
return data.members[k];
}), _this2.channel);
});

@@ -155,5 +207,4 @@ return this;

this.bind(this.connector.adding, function (member) {
member = member.info || member;
callback(member, _this3.channel);
this.bind('pusher:member_added', function (member) {
callback(member.info, _this3.channel);
});

@@ -167,5 +218,4 @@ return this;

this.bind(this.connector.removing, function (member) {
member = member.info || member;
callback(member, _this4.channel);
this.bind('pusher:member_removed', function (member) {
callback(member.info, _this4.channel);
});

@@ -175,50 +225,78 @@ return this;

}]);
return PresenceChannel;
return PusherPresenceChannel;
}(PusherChannel);
var SocketIoChannel = function (_Channel) {
inherits(SocketIoChannel, _Channel);
function SocketIoChannel(channel, connector) {
classCallCheck(this, SocketIoChannel);
var _this = possibleConstructorReturn(this, Object.getPrototypeOf(SocketIoChannel).call(this));
_this.channel = channel;
_this.connector = connector;
_this.eventFormatter = new EventFormatter();
if (_this.connector.options.namespace) {
_this.eventFormatter.namespace(_this.connector.options.namespace);
}
return _this;
}
createClass(SocketIoChannel, [{
key: 'listen',
value: function listen(event, callback) {
this.on(this.eventFormatter.format(event), callback);
return this;
}
}, {
key: 'on',
value: function on(event, callback) {
this.channel.on(event, callback);
}
}]);
return SocketIoChannel;
}(Channel);
var Connector = function () {
function Connector(options) {
classCallCheck(this, Connector);
var SocketIoPresenceChannel = function (_SocketIoChannel) {
inherits(SocketIoPresenceChannel, _SocketIoChannel);
this._options = {
auth: {
headers: {}
},
authEndpoint: '/broadcasting/auth',
connector: 'pusher',
csrfToken: null,
host: null,
namespace: null,
pusherKey: null
};
this.adding = 'member:added';
this.removing = 'member:removed';
this.updating = 'members:updated';
this.setOptions(options);
this.connect();
function SocketIoPresenceChannel() {
classCallCheck(this, SocketIoPresenceChannel);
return possibleConstructorReturn(this, Object.getPrototypeOf(SocketIoPresenceChannel).apply(this, arguments));
}
createClass(Connector, [{
key: 'setOptions',
value: function setOptions(options) {
this.options = _extends(this._options, options);
if (this.csrfToken()) {
this.options.auth.headers['X-CSRF-TOKEN'] = this.csrfToken();
}
return options;
createClass(SocketIoPresenceChannel, [{
key: 'here',
value: function here(callback) {
var _this2 = this;
this.on('presence:subscribed', function (members) {
callback(members, _this2.channel);
});
return this;
}
}, {
key: 'csrfToken',
value: function csrfToken() {
var selector = document.querySelector('meta[name="csrf-token"]');
if (this.options.csrfToken) {
return this.options.csrfToken;
} else if (selector) {
return selector.getAttribute('content');
}
return null;
key: 'joining',
value: function joining(callback) {
var _this3 = this;
this.on('presence:joining', function (member) {
callback(member, _this3.channel);
});
return this;
}
}, {
key: 'leaving',
value: function leaving(callback) {
var _this4 = this;
this.on('presence:leaving', function (member) {
callback(member, _this4.channel);
});
return this;
}
}]);
return Connector;
}();
return SocketIoPresenceChannel;
}(SocketIoChannel);

@@ -239,5 +317,3 @@ var PusherConnector = function (_Connector) {

_this.updating = 'pusher:subscription_succeeded';
_this.adding = 'pusher:member_added';
_this.removing = 'pusher:member_removed';
_this.channels = [];
return _this;

@@ -265,2 +341,43 @@ }

}, {
key: 'listen',
value: function listen(channel, event, callback) {
return this.channel(channel).listen(event, callback);
}
}, {
key: 'channel',
value: function channel(_channel) {
return new PusherChannel(this.createChannel(_channel), this);
}
}, {
key: 'privateChannel',
value: function privateChannel(channel) {
return new PusherChannel(this.createChannel('private-' + channel), this);
}
}, {
key: 'presenceChannel',
value: function presenceChannel(channel) {
return new PusherPresenceChannel(this.createChannel('presence-' + channel), this);
}
}, {
key: 'createChannel',
value: function createChannel(channel) {
if (!this.channels[channel]) {
this.channels[channel] = this.subscribe(channel);
}
return this.channels[channel];
}
}, {
key: 'leave',
value: function leave(channel) {
var _this3 = this;
var channels = [channel, 'private-' + channel, 'presence-' + channel];
channels.forEach(function (channelName, index) {
if (_this3.channels[channelName]) {
_this3.unsubscribe(channelName);
delete _this3.channels[channelName];
}
});
}
}, {
key: 'subscribe',

@@ -298,5 +415,3 @@ value: function subscribe(channel) {

_this.adding = 'member:added';
_this.removing = 'member:removed';
_this.updating = 'members:updated';
_this.channels = [];
return _this;

@@ -312,2 +427,43 @@ }

}, {
key: 'listen',
value: function listen(channel, event, callback) {
return this.channel(channel).listen(event, callback);
}
}, {
key: 'channel',
value: function channel(_channel) {
return new SocketIoChannel(this.createChannel(_channel), this);
}
}, {
key: 'privateChannel',
value: function privateChannel(channel) {
return new SocketIoChannel(this.createChannel('private-' + channel), this);
}
}, {
key: 'presenceChannel',
value: function presenceChannel(channel) {
return new SocketIoPresenceChannel(this.createChannel('presence-' + channel), this);
}
}, {
key: 'createChannel',
value: function createChannel(channel) {
if (!this.channels[channel]) {
this.channels[channel] = this.subscribe(channel);
}
return this.channels[channel];
}
}, {
key: 'leave',
value: function leave(channel) {
var _this2 = this;
var channels = [channel, 'private-' + channel, 'presence-' + channel];
channels.forEach(function (channelName, index) {
if (_this2.channels[channelName]) {
_this2.unsubscribe(channelName);
delete _this2.channels[channelName];
}
});
}
}, {
key: 'subscribe',

@@ -341,7 +497,7 @@ value: function subscribe(channel) {

this.channels = [];
if (options.connector == 'pusher') {
this.connector = new PusherConnector(options);
} else if (options.connector == 'socket.io') {
this.connector = new SocketIoConnector(options);
this.options = options;
if (this.options.connector == 'pusher') {
this.connector = new PusherConnector(this.options);
} else if (this.options.connector == 'socket.io') {
this.connector = new SocketIoConnector(this.options);
}

@@ -353,3 +509,3 @@ }

value: function listen(channel, event, callback) {
return this.channel(channel).listen(event, callback);
return this.connector.listen(channel, event, callback);
}

@@ -359,3 +515,3 @@ }, {

value: function channel(_channel) {
return new Channel(this.createChannel(_channel), this.connector);
return this.connector.channel(_channel);
}

@@ -365,3 +521,3 @@ }, {

value: function _private(channel) {
return this.channel('private-' + channel);
return this.connector.privateChannel(channel);
}

@@ -371,24 +527,8 @@ }, {

value: function join(channel) {
return new PresenceChannel(this.createChannel('presence-' + channel), this.connector);
return this.connector.presenceChannel(channel);
}
}, {
key: 'createChannel',
value: function createChannel(channel) {
if (!this.channels[channel]) {
this.channels[channel] = this.connector.subscribe(channel);
}
return this.channels[channel];
}
}, {
key: 'leave',
value: function leave(channel) {
var _this = this;
var channels = [channel, 'private-' + channel, 'presence-' + channel];
channels.forEach(function (channelName, index) {
if (_this.channels[channelName]) {
_this.connector.unsubscribe(channelName);
delete _this.channels[channelName];
}
});
this.connector.leave(channel);
}

@@ -395,0 +535,0 @@ }, {

{
"name": "laravel-echo",
"version": "0.0.22",
"version": "0.0.23",
"description": "Laravel Echo library for beautiful Pusher integration",

@@ -5,0 +5,0 @@ "main": "dist/echo.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc