New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

happychat-service

Package Overview
Dependencies
Maintainers
3
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

happychat-service - npm Package Compare versions

Comparing version 0.10.1-4 to 0.10.1-5

3

lib/customer.js

@@ -131,4 +131,3 @@ 'use strict';

events.on('accept', function (chat, accepted) {
// broadcast the status of accepting coneections
events.on('accept', function (accepted) {
io.emit('accept', accepted);

@@ -135,0 +134,0 @@ });

@@ -61,2 +61,3 @@ 'use strict';

var currentState = selector(getState());
var patch = void 0;

@@ -69,14 +70,14 @@ var listen = function listen(socket) {

var dispatchListener = function dispatchListener(remoteAction, callback) {
new Promise(function (resolve, reject) {
var user = (0, _store.selectSocketIdentity)(getState(), socket);
var action = { type: REMOTE_ACTION_TYPE, action: remoteAction, socket: socket, user: user };
if (canRemoteDispatch(action, getState)) {
dispatch((0, _ramda.merge)(action, { resolve: resolve, reject: reject }));
} else {
reject(new Error('Remote dispatch not allowed'));
}
}).then(function (r) {
return callback(null, r);
debug('received remote dispatch', remoteAction.type);
var user = (0, _store.selectSocketIdentity)(getState(), socket);
var action = { type: REMOTE_ACTION_TYPE, action: remoteAction, socket: socket, user: user };
if (!canRemoteDispatch(action, getState)) {
debug('remote dispatch not allowed for action', remoteAction.type);
callback('Remote dispatch not allowed');
return;
}
dispatch(action).then(function (result) {
return callback(null, result);
}, function (e) {
return callback(e);
return callback(e.message);
});

@@ -102,9 +103,16 @@ };

case REMOTE_ACTION_TYPE:
try {
dispatch(action.action);
action.resolve();
} catch (e) {
action.reject(e);
}
return next(action);
debug('handling REMOTE_ACTION_TYPE');
return new Promise(function (resolve, reject) {
try {
if (action.action.version && action.action.version !== version) {
// if action is dispatched with a version number, require it to
// be up to date with the server version
return action.reject(new Error('out of date'));
}
dispatch(action.action);
resolve(version);
} catch (e) {
reject(e.message);
}
});
// when the socket joins operators initialize them

@@ -121,8 +129,9 @@ case _index.OPERATOR_READY:

var nextState = currentState = selector(getState());
var patch = diff(previousState, nextState);
var nextPatch = diff(previousState, nextState);
// TODO: throttle?
if (!(0, _ramda.isEmpty)(patch)) {
if (!(0, _ramda.isEmpty)(nextPatch)) {
var nextVersion = (0, _uuid.v4)();
patch = nextPatch;
broadcastVersion(io, version, nextVersion, patch);

@@ -129,0 +138,0 @@ version = nextVersion;

@@ -21,4 +21,2 @@ 'use strict';

var _operator = require('../../operator');
var _util = require('../../util');

@@ -61,2 +59,3 @@

store.dispatch((0, _actions.setChatStatus)(chat, _reducer.STATUS_ASSIGNED));
return;
}

@@ -82,23 +81,13 @@ });

customers.on('join', function (socket, chat) {
var notifyStatus = function notifyStatus(status) {
return customers.emit('accept', status);
};
var status = (0, _selectors.getChatStatus)(chat.id, store.getState());
customers.on('join', function (socketid, chat, socket) {
// when a customer joins inform of status update
debug('socket?', socket);
socket.emit('accept', (0, _store.isSystemAcceptingCustomers)(store.getState()));
});
if (status === _reducer.STATUS_ASSIGNED || status === _reducer.STATUS_ASSIGNING) {
debug('already chatting', chat, status);
notifyStatus(true);
customers.on('disconnect', function (chat) {
if ((0, _selectors.isChatStatusNew)(chat.id, store.getState())) {
debug('Customer disconnected without starting chat', chat.id);
return;
}
var _selectTotalCapacity = (0, _store.selectTotalCapacity)(store.getState(), _operator.STATUS_AVAILABLE);
var load = _selectTotalCapacity.load;
var capacity = _selectTotalCapacity.capacity;
notifyStatus(load < capacity);
});
customers.on('disconnect', function (chat) {
store.dispatch((0, _actions.setChatStatus)(chat, _reducer.STATUS_CUSTOMER_DISCONNECT));

@@ -105,0 +94,0 @@

@@ -24,3 +24,3 @@ 'use strict';

var OPERATOR_QUERY_AVAILABILITY = exports.OPERATOR_QUERY_AVAILABILITY = 'OPERATOR_QUERY_AVAILABILITY';
var SET_ACCEPTS_CUSTOMERS = exports.SET_ACCEPTS_CUSTOMERS = 'SET_ACCEPTS_CUSTOMERS';
var SET_SYSTEM_ACCEPTS_CUSTOMERS = exports.SET_SYSTEM_ACCEPTS_CUSTOMERS = 'SET_SYSTEM_ACCEPTS_CUSTOMERS';

@@ -102,4 +102,4 @@ var updateIdentity = exports.updateIdentity = function updateIdentity(socket, user) {

var setAcceptsCustomers = exports.setAcceptsCustomers = function setAcceptsCustomers(accept) {
return { type: SET_ACCEPTS_CUSTOMERS, accept: accept };
var setAcceptsCustomers = exports.setAcceptsCustomers = function setAcceptsCustomers(isEnabled) {
return { type: SET_SYSTEM_ACCEPTS_CUSTOMERS, isEnabled: isEnabled };
};

@@ -18,3 +18,3 @@ 'use strict';

switch (action.type) {
case _actions.SET_ACCEPTS_CUSTOMERS:
case _actions.SET_SYSTEM_ACCEPTS_CUSTOMERS:
return true;

@@ -21,0 +21,0 @@ default:

@@ -6,3 +6,3 @@ 'use strict';

});
exports.selectTotalCapacity = exports.selectUser = exports.selectSocketIdentity = exports.selectIdentities = undefined;
exports.isSystemAcceptingCustomers = exports.getSystemAcceptsCustomers = exports.selectTotalCapacity = exports.selectUser = exports.selectSocketIdentity = exports.selectIdentities = undefined;

@@ -49,2 +49,4 @@ var _assign = require('lodash/assign');

var _index = require('./index');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -69,4 +71,5 @@

};
var selectTotalCapacity = exports.selectTotalCapacity = function selectTotalCapacity(_ref4, matchingStatus) {
var selectTotalCapacity = exports.selectTotalCapacity = function selectTotalCapacity(_ref4) {
var identities = _ref4.operators.identities;
var matchingStatus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _index.STATUS_AVAILABLE;
return (0, _reduce2.default)(identities, function (_ref5, _ref6) {

@@ -79,4 +82,4 @@ var totalLoad = _ref5.load;

return {
load: totalLoad + (status === matchingStatus ? load : 0),
capacity: totalCapacity + (status === matchingStatus ? capacity : 0)
load: totalLoad + (status === matchingStatus ? parseInt(load) : 0),
capacity: totalCapacity + (status === matchingStatus ? parseInt(capacity) : 0)
};

@@ -86,2 +89,23 @@ }, { load: 0, capacity: 0 });

var getSystemAcceptsCustomers = exports.getSystemAcceptsCustomers = function getSystemAcceptsCustomers(_ref7) {
var acceptsCustomers = _ref7.operators.system.acceptsCustomers;
return acceptsCustomers;
};
var isSystemAcceptingCustomers = exports.isSystemAcceptingCustomers = function isSystemAcceptingCustomers(state) {
var systemAcceptsCustomers = getSystemAcceptsCustomers(state);
debug('is system on?', systemAcceptsCustomers);
if (!systemAcceptsCustomers) {
return false;
}
debug('is there capacity?', systemAcceptsCustomers);
var _selectTotalCapacity = selectTotalCapacity(state);
var load = _selectTotalCapacity.load;
var capacity = _selectTotalCapacity.capacity;
return load < capacity;
};
// Reducers

@@ -125,6 +149,6 @@ var user_sockets = function user_sockets() {

var setOpAvailability = function setOpAvailability(opsStatuses, state) {
return opsStatuses.reduce(function (collection, _ref7) {
var id = _ref7.id;
var load = _ref7.load;
var capacity = _ref7.capacity;
return opsStatuses.reduce(function (collection, _ref8) {
var id = _ref8.id;
var load = _ref8.load;
var capacity = _ref8.capacity;

@@ -191,4 +215,5 @@ if (!id) {

switch (action.type) {
case _actions.SET_ACCEPTS_CUSTOMERS:
return (0, _assign2.default)({}, state, { acceptsCustomers: action.accept });
case _actions.SET_SYSTEM_ACCEPTS_CUSTOMERS:
debug('accepts customers?', action);
return (0, _assign2.default)({}, state, { acceptsCustomers: action.isEnabled });
}

@@ -195,0 +220,0 @@ return state;

{
"name": "happychat-service",
"version": "0.10.1-4",
"version": "0.10.1-5",
"description": "Socket.IO based chat server for happychat.",

@@ -5,0 +5,0 @@ "main": "index.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