Socket
Socket
Sign inDemoInstall

redux-websocket-bridge

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0-1 to 0.2.0-0

37

lib/index.js

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var CLOSE = exports.CLOSE = 'CLOSE';

@@ -60,17 +62,17 @@ var MESSAGE = exports.MESSAGE = 'MESSAGE';

return function (store) {
var ws = void 0;
var webSocket = void 0;
if (typeof urlOrFactory === 'function') {
ws = urlOrFactory();
webSocket = urlOrFactory();
} else {
ws = new WebSocket(urlOrFactory);
webSocket = new WebSocket(urlOrFactory);
}
ws.onopen = function () {
return store.dispatch({ type: '' + namespace + OPEN });
webSocket.onopen = function () {
return store.dispatch({ type: '' + namespace + OPEN, meta: { webSocket: webSocket } });
};
ws.onclose = function () {
return store.dispatch({ type: '' + namespace + CLOSE });
webSocket.onclose = function () {
return store.dispatch({ type: '' + namespace + CLOSE, meta: { webSocket: webSocket } });
};
ws.onmessage = function (event) {
webSocket.onmessage = function (event) {
var getPayload = void 0;

@@ -93,3 +95,7 @@

if ((0, _isFSA2.default)(action)) {
return store.dispatch(action);
return store.dispatch(_extends({}, action, {
meta: _extends({}, action.meta, {
webSocket: webSocket
})
}));
}

@@ -100,2 +106,3 @@ }

type: '' + namespace + MESSAGE,
meta: { webSocket: webSocket },
payload: payload

@@ -109,9 +116,9 @@ });

if (action.type === '' + namespace + SEND) {
ws.send(action.payload);
} else if (action.meta && (action.meta.send === true || action.meta.send === namespace)) {
var sendAction = _extends({}, action, {
meta: _extends({}, action.meta, { send: undefined })
});
webSocket.send(action.payload);
} else if (action.meta && (action.meta.send === true || action.meta.send === namespace || action.meta.send === webSocket)) {
var _action$meta = action.meta,
send = _action$meta.send,
meta = _objectWithoutProperties(_action$meta, ['send']);
ws.send(JSON.stringify(sendAction));
webSocket.send(JSON.stringify(_extends({}, action, { meta: meta })));
}

@@ -118,0 +125,0 @@

{
"name": "redux-websocket-bridge",
"version": "0.1.0-1",
"version": "0.2.0-0",
"description": "WebSocket messages to Redux action bridge",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -66,2 +66,3 @@ # Bridge WebSocket messages and Redux actions

case 'SERVER/GREETING':
// action.meta.webSocket reference to the WebSocket object
return { ...state, ...action.payload, connected: true };

@@ -123,3 +124,3 @@

id: 1,
type: ' message',
type: 'message',
channel: 'C024BE91L',

@@ -139,3 +140,3 @@ text: 'Hello world'

type: 'CLIENT/SIGN_IN',
meta: { send: true } // or '@@websocket',
meta: { send: true } // or '@@websocket', or a WebSocket object,
payload: { token: 'my very secret token' }

@@ -142,0 +143,0 @@ });

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