@folklore/socket 0.4.2 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,122 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
-
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
5
-
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7
-
8
- import React, { useMemo, useEffect, useRef, useCallback, useState } from 'react';
9
- import PropTypes from 'prop-types';
10
- import Socket from './Socket';
11
- import SocketContext from './SocketContext';
12
- var propTypes = {
13
- socket: PropTypes.instanceOf(Socket),
14
- adapter: PropTypes.string,
15
- host: PropTypes.string,
16
- namespace: PropTypes.string,
17
- uuid: PropTypes.string,
18
- publishKey: PropTypes.string,
19
- subscribeKey: PropTypes.string,
20
- secretKey: PropTypes.string,
21
- channels: PropTypes.arrayOf(PropTypes.string),
22
- autoStart: PropTypes.bool,
23
- children: PropTypes.node
24
- };
25
- var defaultProps = {
26
- socket: null,
27
- adapter: 'pubnub',
28
- host: null,
29
- namespace: null,
30
- uuid: null,
31
- publishKey: null,
32
- subscribeKey: null,
33
- secretKey: null,
34
- channels: [],
35
- autoStart: false,
36
- children: null
37
- };
38
-
39
- var SocketContainer = function SocketContainer(_ref) {
40
- var children = _ref.children,
41
- socket = _ref.socket,
42
- autoStart = _ref.autoStart,
43
- adapter = _ref.adapter,
44
- host = _ref.host,
45
- namespace = _ref.namespace,
46
- uuid = _ref.uuid,
47
- publishKey = _ref.publishKey,
48
- subscribeKey = _ref.subscribeKey,
49
- secretKey = _ref.secretKey,
50
- initialChannels = _ref.channels;
51
- var finalSocket = useMemo(function () {
52
- return socket || new Socket({
53
- adapter: adapter,
54
- host: host,
55
- namespace: namespace,
56
- uuid: uuid,
57
- publishKey: publishKey,
58
- subscribeKey: subscribeKey,
59
- secretKey: secretKey
60
- });
61
- }, [socket, host, adapter, namespace, uuid, publishKey, subscribeKey, secretKey]);
62
-
63
- var _useState = useState([]),
64
- _useState2 = _slicedToArray(_useState, 2),
65
- channels = _useState2[0],
66
- setChannels = _useState2[1];
67
-
68
- var channelsCountRef = useRef({});
69
- var updateChannels = useCallback(function (newChannels) {
70
- finalSocket.setChannels(newChannels);
71
- setChannels(newChannels);
72
- }, [finalSocket, setChannels]);
73
- var addToChannelsCount = useCallback(function (newChannels) {
74
- channelsCountRef.current = newChannels.reduce(function (map, channel) {
75
- return _objectSpread({}, map, _defineProperty({}, channel, (map[channel] || 0) + 1));
76
- }, channelsCountRef.current);
77
- updateChannels(Object.keys(channelsCountRef.current));
78
- }, [updateChannels]);
79
- var removeToChannelsCount = useCallback(function (newChannels) {
80
- channelsCountRef.current = newChannels.reduce(function (map, channel) {
81
- var newCount = (map[channel] || 0) - 1;
82
- return newCount > 0 ? _objectSpread({}, map, _defineProperty({}, channel, newCount)) : map;
83
- }, channelsCountRef.current);
84
- updateChannels(Object.keys(channelsCountRef.current));
85
- }, [updateChannels]);
86
- var subscribe = useCallback(function (channelsToAdd) {
87
- return addToChannelsCount(channelsToAdd);
88
- }, [addToChannelsCount]);
89
- var unsubscribe = useCallback(function (channelsToRemove) {
90
- return removeToChannelsCount(channelsToRemove);
91
- }, [removeToChannelsCount]);
92
- useEffect(function () {
93
- subscribe(initialChannels);
94
- return function () {
95
- unsubscribe(initialChannels);
96
- };
97
- }, [initialChannels, subscribe, unsubscribe]);
98
- useEffect(function () {
99
- if (autoStart) {
100
- finalSocket.start();
101
- }
102
-
103
- return function () {
104
- finalSocket.destroy();
105
- };
106
- }, [autoStart, finalSocket]);
107
- var value = useMemo(function () {
108
- return {
109
- socket: finalSocket,
110
- subscribe: subscribe,
111
- unsubscribe: unsubscribe,
112
- channels: channels
113
- };
114
- }, [finalSocket, subscribe]);
115
- return React.createElement(SocketContext.Provider, {
116
- value: value
117
- }, children);
118
- };
119
-
120
- SocketContainer.propTypes = propTypes;
121
- SocketContainer.defaultProps = defaultProps;
122
- export default SocketContainer;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- var SocketContext = React.createContext({
3
- socket: null,
4
- subscribe: function subscribe() {},
5
- unsubscribe: function unsubscribe() {}
6
- });
7
- export default SocketContext;
@@ -1,213 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
7
- import _inherits from "@babel/runtime/helpers/inherits";
8
-
9
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
10
-
11
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
12
-
13
- import createDebug from 'debug';
14
- import EventEmitter from 'wolfy87-eventemitter';
15
- var debug = createDebug('folklore:socket:pubnub');
16
-
17
- var PubNubSocket =
18
- /*#__PURE__*/
19
- function (_EventEmitter) {
20
- _inherits(PubNubSocket, _EventEmitter);
21
-
22
- function PubNubSocket(opts) {
23
- var _this;
24
-
25
- _classCallCheck(this, PubNubSocket);
26
-
27
- _this = _possibleConstructorReturn(this, _getPrototypeOf(PubNubSocket).call(this));
28
- _this.options = _objectSpread({
29
- uuid: null,
30
- publishKey: null,
31
- subscribeKey: null,
32
- secretKey: null
33
- }, opts);
34
- _this.onReady = _this.onReady.bind(_assertThisInitialized(_this));
35
- _this.onStatus = _this.onStatus.bind(_assertThisInitialized(_this));
36
- _this.onMessage = _this.onMessage.bind(_assertThisInitialized(_this));
37
- _this.ready = false;
38
- _this.shouldStart = false;
39
- _this.started = false;
40
- _this.starting = false;
41
- _this.PubNub = null;
42
- _this.pubnub = null;
43
- _this.pubnubListener = null;
44
- _this.channels = [];
45
-
46
- _this.init();
47
-
48
- return _this;
49
- }
50
-
51
- _createClass(PubNubSocket, [{
52
- key: "onReady",
53
- value: function onReady() {
54
- this.ready = true;
55
- this.emit('ready');
56
- }
57
- }, {
58
- key: "onStatus",
59
- value: function onStatus(statusEvent) {
60
- if (statusEvent.category === 'PNConnectedCategory' && !this.started) {
61
- this.started = true;
62
- this.starting = false;
63
- this.emit('started');
64
- }
65
- }
66
- }, {
67
- key: "onMessage",
68
- value: function onMessage(_ref) {
69
- var message = _ref.message;
70
- this.emit('message', message);
71
-
72
- if (typeof message.event !== 'undefined') {
73
- this.emit(message.event, message.data || message);
74
- }
75
- }
76
- }, {
77
- key: "updateChannels",
78
- value: function updateChannels(channels) {
79
- debug("Updating channels: ".concat(channels.join(', ')));
80
- var shouldStart = this.shouldStart,
81
- started = this.started,
82
- starting = this.starting;
83
-
84
- if (started || starting) {
85
- this.stop();
86
- }
87
-
88
- this.channels = channels;
89
-
90
- if (started || starting || shouldStart) {
91
- this.shouldStart = false;
92
- this.start();
93
- }
94
- }
95
- }, {
96
- key: "init",
97
- value: function init() {
98
- var _this2 = this;
99
-
100
- import('pubnub').then(function (_ref2) {
101
- var PubNub = _ref2["default"];
102
- _this2.PubNub = PubNub;
103
- }).then(function () {
104
- return _this2.createPubNub();
105
- }).then(function () {
106
- return _this2.onReady();
107
- });
108
- }
109
- }, {
110
- key: "createPubNub",
111
- value: function createPubNub() {
112
- var PubNub = this.PubNub;
113
- var pubnubOptions = {
114
- publishKey: this.options.publishKey,
115
- subscribeKey: this.options.subscribeKey
116
- };
117
-
118
- if (this.options.uuid !== null) {
119
- pubnubOptions.uuid = this.options.uuid;
120
- }
121
-
122
- if (this.options.secretKey !== null) {
123
- pubnubOptions.secretKey = this.options.secretKey;
124
- }
125
-
126
- this.pubnub = new PubNub(pubnubOptions);
127
- this.pubnubListener = {
128
- status: this.onStatus,
129
- message: this.onMessage
130
- };
131
- this.pubnub.addListener(this.pubnubListener);
132
- }
133
- }, {
134
- key: "destroy",
135
- value: function destroy() {
136
- this.stop();
137
-
138
- if (this.pubnubListener) {
139
- this.pubnub.removeListener(this.pubnubListener);
140
- this.pubnubListener = null;
141
- }
142
-
143
- this.ready = false;
144
- debug('Destroyed.');
145
- }
146
- }, {
147
- key: "start",
148
- value: function start() {
149
- if (this.started) {
150
- debug('Skipping start: Already started.');
151
- return;
152
- }
153
-
154
- if (this.starting) {
155
- debug('Skipping start: Already starting.');
156
- return;
157
- }
158
-
159
- if (this.channels.length === 0) {
160
- debug('Skipping start: No channels.');
161
- this.shouldStart = true;
162
- return;
163
- }
164
-
165
- this.shouldStart = false;
166
- this.starting = true;
167
- this.pubnub.subscribe({
168
- channels: this.channels
169
- });
170
- this.emit('start');
171
- }
172
- }, {
173
- key: "stop",
174
- value: function stop() {
175
- if (!this.started && !this.starting) {
176
- return;
177
- }
178
-
179
- debug('Stopping...');
180
- this.shouldStart = false;
181
- this.started = false;
182
- this.starting = false;
183
- this.pubnub.unsubscribe({
184
- channels: this.channels
185
- });
186
- this.emit('stop');
187
- }
188
- }, {
189
- key: "send",
190
- value: function send(data) {
191
- var _this3 = this;
192
-
193
- debug('Sending', data);
194
- return new Promise(function (resolve, reject) {
195
- _this3.pubnub.publish(data, function (status, response) {
196
- if (status.error) {
197
- reject(new Error("Error operation:".concat(status.operation, " status:").concat(status.statusCode)));
198
- } else {
199
- resolve({
200
- status: status,
201
- response: response,
202
- data: data
203
- });
204
- }
205
- });
206
- });
207
- }
208
- }]);
209
-
210
- return PubNubSocket;
211
- }(EventEmitter);
212
-
213
- export default PubNubSocket;
@@ -1,226 +0,0 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
8
- import _inherits from "@babel/runtime/helpers/inherits";
9
-
10
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
11
-
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
-
14
- import createDebug from 'debug';
15
- import EventEmitter from 'wolfy87-eventemitter';
16
- import isArray from 'lodash/isArray';
17
- var debug = createDebug('folklore:socket:socketio');
18
-
19
- var SocketIOSocket =
20
- /*#__PURE__*/
21
- function (_EventEmitter) {
22
- _inherits(SocketIOSocket, _EventEmitter);
23
-
24
- function SocketIOSocket(opts) {
25
- var _this;
26
-
27
- _classCallCheck(this, SocketIOSocket);
28
-
29
- _this = _possibleConstructorReturn(this, _getPrototypeOf(SocketIOSocket).call(this));
30
- _this.options = _objectSpread({
31
- uuid: null,
32
- host: 'http://127.0.0.1',
33
- path: null,
34
- query: null
35
- }, opts);
36
- _this.onReady = _this.onReady.bind(_assertThisInitialized(_this));
37
- _this.onConnect = _this.onConnect.bind(_assertThisInitialized(_this));
38
- _this.onMessage = _this.onMessage.bind(_assertThisInitialized(_this));
39
- _this.ready = false;
40
- _this.shouldStart = false;
41
- _this.started = false;
42
- _this.starting = false;
43
- _this.IO = null;
44
- _this.io = null;
45
- _this.sockets = {};
46
- _this.channels = [];
47
-
48
- _this.init();
49
-
50
- return _this;
51
- }
52
-
53
- _createClass(SocketIOSocket, [{
54
- key: "onReady",
55
- value: function onReady() {
56
- this.ready = true;
57
- this.emit('ready');
58
- }
59
- }, {
60
- key: "onConnect",
61
- value: function onConnect() {
62
- if (!this.started) {
63
- this.started = true;
64
- this.starting = false;
65
- this.emit('started');
66
- }
67
- }
68
- }, {
69
- key: "onMessage",
70
- value: function onMessage(message) {
71
- debug('Message received', message);
72
- this.emit('message', message);
73
- }
74
- }, {
75
- key: "init",
76
- value: function init() {
77
- var _this2 = this;
78
-
79
- import('socket.io-client').then(function (_ref) {
80
- var IO = _ref["default"];
81
- _this2.IO = IO.Manager;
82
- }).then(function () {
83
- return _this2.createIO();
84
- }).then(function () {
85
- return _this2.onReady();
86
- }).then(function () {
87
- if (_this2.shouldStart) {
88
- _this2.start();
89
- }
90
- });
91
- }
92
- }, {
93
- key: "createIO",
94
- value: function createIO() {
95
- var IO = this.IO;
96
-
97
- var _this$options = this.options,
98
- host = _this$options.host,
99
- opts = _objectWithoutProperties(_this$options, ["host"]);
100
-
101
- this.io = IO(host, _objectSpread({
102
- autoConnect: false
103
- }, opts));
104
- }
105
- }, {
106
- key: "updateChannels",
107
- value: function updateChannels(channels) {
108
- debug("Updating channels: ".concat(channels.join(', ')));
109
- var shouldStart = this.shouldStart,
110
- started = this.started,
111
- starting = this.starting;
112
-
113
- if (started || starting) {
114
- this.stop();
115
- }
116
-
117
- this.channels = channels;
118
-
119
- if (started || starting || shouldStart) {
120
- this.start();
121
- }
122
- }
123
- }, {
124
- key: "start",
125
- value: function start() {
126
- var _this3 = this;
127
-
128
- if (this.started) {
129
- debug('Skipping start: Already started.');
130
- return;
131
- }
132
-
133
- if (this.starting) {
134
- debug('Skipping start: Already starting.');
135
- return;
136
- }
137
-
138
- if (this.io === null) {
139
- debug('Socket.io not ready.');
140
- this.shouldStart = true;
141
- return;
142
- }
143
-
144
- if (this.channels.length === 0) {
145
- debug('Skipping start: No channels.');
146
- this.shouldStart = true;
147
- return;
148
- }
149
-
150
- this.shouldStart = false;
151
- this.starting = true;
152
- this.sockets = this.channels.reduce(function (map, channel) {
153
- return _objectSpread({}, map, _defineProperty({}, channel, _this3.createSocket(channel)));
154
- }, {});
155
- this.emit('start');
156
- }
157
- }, {
158
- key: "stop",
159
- value: function stop() {
160
- var _this4 = this;
161
-
162
- if (!this.started && !this.starting) {
163
- return;
164
- }
165
-
166
- debug('Stopping...');
167
- this.shouldStart = false;
168
- this.started = false;
169
- this.starting = false;
170
- Object.values(this.sockets).forEach(function (socket) {
171
- return _this4.stopSocket(socket);
172
- });
173
- this.emit('stop');
174
- }
175
- }, {
176
- key: "createSocket",
177
- value: function createSocket(channel) {
178
- var _this5 = this;
179
-
180
- var socket = this.io.socket("/".concat(channel.replace(/^\//, '')));
181
- socket.on('message', function (message) {
182
- return _this5.onMessage(message, channel);
183
- });
184
- socket.on('connect', this.onConnect);
185
- socket.open();
186
- return socket;
187
- } // eslint-disable-next-line class-methods-use-this
188
-
189
- }, {
190
- key: "stopSocket",
191
- value: function stopSocket(socket) {
192
- socket.off('connect');
193
- socket.off('message');
194
- socket.close();
195
- return socket;
196
- }
197
- }, {
198
- key: "destroy",
199
- value: function destroy() {
200
- this.stop();
201
- this.sockets = {};
202
-
203
- if (this.io !== null) {
204
- this.io.close();
205
- this.io = null;
206
- }
207
- }
208
- }, {
209
- key: "send",
210
- value: function send(data) {
211
- var _this6 = this;
212
-
213
- var channel = data.channel,
214
- message = data.message;
215
- var channels = !isArray(channel) ? [channel] : channel;
216
- channels.forEach(function (ch) {
217
- _this6.sockets[ch].send(message);
218
- });
219
- return Promise.resolve();
220
- }
221
- }]);
222
-
223
- return SocketIOSocket;
224
- }(EventEmitter);
225
-
226
- export default SocketIOSocket;
@@ -1,6 +0,0 @@
1
- import PubNub from './PubNub';
2
- import SocketIO from './SocketIO';
3
- export default {
4
- PubNub: PubNub,
5
- SocketIO: SocketIO
6
- };
package/es/index.js DELETED
@@ -1,5 +0,0 @@
1
- export { default, default as Socket } from './Socket';
2
- export { default as SocketContext } from './SocketContext';
3
- export { default as SocketContainer } from './SocketContainer';
4
- export { default as withSocket } from './withSocket';
5
- export { default as useSocket } from './useSocket';
package/es/useSocket.js DELETED
@@ -1,96 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { useContext, useEffect, useState } from 'react';
3
- import isString from 'lodash/isString';
4
- import SocketContext from './SocketContext';
5
-
6
- var useSocket = function useSocket() {
7
- var channelNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
8
-
9
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
10
- _ref$socket = _ref.socket,
11
- customSocket = _ref$socket === void 0 ? null : _ref$socket,
12
- _ref$onMessage = _ref.onMessage,
13
- customOnMessage = _ref$onMessage === void 0 ? null : _ref$onMessage;
14
-
15
- var _useContext = useContext(SocketContext),
16
- contextSocket = _useContext.socket,
17
- subscribe = _useContext.subscribe,
18
- unsubscribe = _useContext.unsubscribe;
19
-
20
- var socket = customSocket || contextSocket || null;
21
-
22
- var _useState = useState(socket !== null ? socket.isStarted() : false),
23
- _useState2 = _slicedToArray(_useState, 2),
24
- started = _useState2[0],
25
- setStarted = _useState2[1];
26
-
27
- var channels = isString(channelNames) ? [channelNames] : channelNames;
28
- var channelsKey = (channels || []).sort().join(',');
29
- useEffect(function () {
30
- if (socket === null) {
31
- if (process.env.NODE_ENV !== 'production') {
32
- console.warn('Socket context is empty.');
33
- }
34
-
35
- return function () {};
36
- }
37
-
38
- var wasStarted = socket.isStarted();
39
-
40
- var onStarted = function onStarted() {
41
- return setStarted(true);
42
- };
43
-
44
- var onStop = function onStop() {
45
- return setStarted(false);
46
- };
47
-
48
- socket.on('stop', onStop);
49
- socket.on('started', onStarted);
50
-
51
- if (channels !== null) {
52
- subscribe(channels);
53
- }
54
-
55
- if (!wasStarted) {
56
- socket.start();
57
- }
58
-
59
- return function () {
60
- socket.off('stop', onStop);
61
- socket.off('started', onStarted);
62
-
63
- if (channels !== null) {
64
- unsubscribe(channels);
65
- }
66
-
67
- if (!wasStarted) {
68
- socket.stop();
69
- }
70
- };
71
- }, [channelsKey, customSocket]);
72
- useEffect(function () {
73
- if (socket === null) {
74
- return function () {};
75
- }
76
-
77
- var onMessage = function onMessage() {
78
- if (customOnMessage !== null) {
79
- customOnMessage.apply(void 0, arguments);
80
- }
81
- };
82
-
83
- socket.on('message', onMessage);
84
- return function () {
85
- socket.off('message', onMessage);
86
- };
87
- }, [customOnMessage]);
88
- return {
89
- socket: socket,
90
- started: started,
91
- subscribe: subscribe,
92
- unsubscribe: unsubscribe
93
- };
94
- };
95
-
96
- export default useSocket;
package/es/withSocket.js DELETED
@@ -1,27 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import React from 'react';
3
- import SocketContext from './SocketContext';
4
-
5
- var getDisplayName = function getDisplayName(WrappedComponent) {
6
- return WrappedComponent.displayName || WrappedComponent.name || 'Component';
7
- };
8
-
9
- var withSocket = function withSocket(WrappedComponent) {
10
- var WithSocketComponent = function WithSocketComponent(props) {
11
- return React.createElement(SocketContext.Consumer, null, function (_ref) {
12
- var socket = _ref.socket,
13
- subscribe = _ref.subscribe,
14
- unsubscribe = _ref.unsubscribe;
15
- return React.createElement(WrappedComponent, _extends({
16
- socket: socket,
17
- socketSubscribe: subscribe,
18
- socketUnsubscribe: unsubscribe
19
- }, props));
20
- });
21
- };
22
-
23
- WithSocketComponent.displayName = "WithSocket(".concat(getDisplayName(WrappedComponent), ")");
24
- return WithSocketComponent;
25
- };
26
-
27
- export default withSocket;