@folklore/socket 0.4.24 → 0.4.26
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.
- package/dist/cjs.js +50 -56
- package/dist/es.js +50 -56
- package/package.json +3 -3
package/dist/cjs.js
CHANGED
|
@@ -52,10 +52,9 @@ class PubNubSocket extends EventEmitter {
|
|
|
52
52
|
this.emit('started');
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
onMessage(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} = _ref;
|
|
55
|
+
onMessage({
|
|
56
|
+
message
|
|
57
|
+
}) {
|
|
59
58
|
this.emit('message', message);
|
|
60
59
|
if (typeof message.event !== 'undefined') {
|
|
61
60
|
this.emit(message.event, message.data || message);
|
|
@@ -88,10 +87,9 @@ class PubNubSocket extends EventEmitter {
|
|
|
88
87
|
}
|
|
89
88
|
loadPubNub() {
|
|
90
89
|
debug$3('Load PubNub');
|
|
91
|
-
return import('pubnub').then(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
} = _ref2;
|
|
90
|
+
return import('pubnub').then(({
|
|
91
|
+
default: PubNub
|
|
92
|
+
}) => {
|
|
95
93
|
this.PubNub = PubNub;
|
|
96
94
|
});
|
|
97
95
|
}
|
|
@@ -229,10 +227,9 @@ class SocketIOSocket extends EventEmitter {
|
|
|
229
227
|
this.emit('message', message, channel);
|
|
230
228
|
}
|
|
231
229
|
init() {
|
|
232
|
-
import('socket.io-client').then(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
} = _ref;
|
|
230
|
+
import('socket.io-client').then(({
|
|
231
|
+
default: IO
|
|
232
|
+
}) => {
|
|
236
233
|
this.Manager = IO.Manager;
|
|
237
234
|
}).then(() => this.createManager()).then(() => this.onReady()).then(() => {
|
|
238
235
|
if (this.shouldStart) {
|
|
@@ -412,10 +409,9 @@ class PusherSocket extends EventEmitter {
|
|
|
412
409
|
}
|
|
413
410
|
loadPusher() {
|
|
414
411
|
debug$1('Load Pusher');
|
|
415
|
-
return import('pusher-js').then(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
} = _ref;
|
|
412
|
+
return import('pusher-js').then(({
|
|
413
|
+
default: Pusher
|
|
414
|
+
}) => {
|
|
419
415
|
this.Pusher = Pusher;
|
|
420
416
|
});
|
|
421
417
|
}
|
|
@@ -787,21 +783,20 @@ const defaultProps = {
|
|
|
787
783
|
autoStart: false,
|
|
788
784
|
children: null
|
|
789
785
|
};
|
|
790
|
-
function SocketContainer(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
} = _ref;
|
|
786
|
+
function SocketContainer({
|
|
787
|
+
children,
|
|
788
|
+
socket,
|
|
789
|
+
autoStart,
|
|
790
|
+
adapter,
|
|
791
|
+
host,
|
|
792
|
+
namespace,
|
|
793
|
+
uuid,
|
|
794
|
+
publishKey,
|
|
795
|
+
subscribeKey,
|
|
796
|
+
secretKey,
|
|
797
|
+
channels: initialChannels,
|
|
798
|
+
...props
|
|
799
|
+
}) {
|
|
805
800
|
const finalSocket = React.useMemo(() => socket || new Socket({
|
|
806
801
|
...props,
|
|
807
802
|
adapter,
|
|
@@ -827,11 +822,15 @@ function SocketContainer(_ref) {
|
|
|
827
822
|
}, [updateChannels]);
|
|
828
823
|
const removeToChannelsCount = React.useCallback(newChannels => {
|
|
829
824
|
channelsCountRef.current = newChannels.reduce((map, channel) => {
|
|
830
|
-
const
|
|
825
|
+
const {
|
|
826
|
+
[channel]: currentCount = 0,
|
|
827
|
+
...otherCount
|
|
828
|
+
} = map;
|
|
829
|
+
const newCount = (currentCount || 0) - 1;
|
|
831
830
|
return newCount > 0 ? {
|
|
832
|
-
...
|
|
831
|
+
...otherCount,
|
|
833
832
|
[channel]: newCount
|
|
834
|
-
} :
|
|
833
|
+
} : otherCount;
|
|
835
834
|
}, channelsCountRef.current);
|
|
836
835
|
updateChannels(Object.keys(channelsCountRef.current));
|
|
837
836
|
}, [updateChannels]);
|
|
@@ -869,31 +868,26 @@ SocketContainer.defaultProps = defaultProps;
|
|
|
869
868
|
const getDisplayName = WrappedComponent => WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
870
869
|
const withSocket = WrappedComponent => {
|
|
871
870
|
const WithSocketComponent = props => /*#__PURE__*/jsxRuntime.jsx(SocketContext.Consumer, {
|
|
872
|
-
children:
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
...props
|
|
883
|
-
});
|
|
884
|
-
}
|
|
871
|
+
children: ({
|
|
872
|
+
socket,
|
|
873
|
+
subscribe,
|
|
874
|
+
unsubscribe
|
|
875
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(WrappedComponent, {
|
|
876
|
+
socket: socket,
|
|
877
|
+
socketSubscribe: subscribe,
|
|
878
|
+
socketUnsubscribe: unsubscribe,
|
|
879
|
+
...props
|
|
880
|
+
})
|
|
885
881
|
});
|
|
886
882
|
WithSocketComponent.displayName = `WithSocket(${getDisplayName(WrappedComponent)})`;
|
|
887
883
|
return WithSocketComponent;
|
|
888
884
|
};
|
|
889
885
|
|
|
890
|
-
const useSocket =
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
keepAlive = true
|
|
896
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
886
|
+
const useSocket = (channelNames = null, {
|
|
887
|
+
socket: customSocket = null,
|
|
888
|
+
onMessage: customOnMessage = null,
|
|
889
|
+
keepAlive = true
|
|
890
|
+
} = {}) => {
|
|
897
891
|
const {
|
|
898
892
|
socket: contextSocket,
|
|
899
893
|
subscribe,
|
|
@@ -936,9 +930,9 @@ const useSocket = function () {
|
|
|
936
930
|
if (socket === null) {
|
|
937
931
|
return () => {};
|
|
938
932
|
}
|
|
939
|
-
const onMessage =
|
|
933
|
+
const onMessage = (...args) => {
|
|
940
934
|
if (customOnMessage !== null) {
|
|
941
|
-
customOnMessage(...
|
|
935
|
+
customOnMessage(...args);
|
|
942
936
|
}
|
|
943
937
|
};
|
|
944
938
|
socket.on('message', onMessage);
|
package/dist/es.js
CHANGED
|
@@ -48,10 +48,9 @@ class PubNubSocket extends EventEmitter {
|
|
|
48
48
|
this.emit('started');
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
onMessage(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} = _ref;
|
|
51
|
+
onMessage({
|
|
52
|
+
message
|
|
53
|
+
}) {
|
|
55
54
|
this.emit('message', message);
|
|
56
55
|
if (typeof message.event !== 'undefined') {
|
|
57
56
|
this.emit(message.event, message.data || message);
|
|
@@ -84,10 +83,9 @@ class PubNubSocket extends EventEmitter {
|
|
|
84
83
|
}
|
|
85
84
|
loadPubNub() {
|
|
86
85
|
debug$3('Load PubNub');
|
|
87
|
-
return import('pubnub').then(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} = _ref2;
|
|
86
|
+
return import('pubnub').then(({
|
|
87
|
+
default: PubNub
|
|
88
|
+
}) => {
|
|
91
89
|
this.PubNub = PubNub;
|
|
92
90
|
});
|
|
93
91
|
}
|
|
@@ -225,10 +223,9 @@ class SocketIOSocket extends EventEmitter {
|
|
|
225
223
|
this.emit('message', message, channel);
|
|
226
224
|
}
|
|
227
225
|
init() {
|
|
228
|
-
import('socket.io-client').then(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
} = _ref;
|
|
226
|
+
import('socket.io-client').then(({
|
|
227
|
+
default: IO
|
|
228
|
+
}) => {
|
|
232
229
|
this.Manager = IO.Manager;
|
|
233
230
|
}).then(() => this.createManager()).then(() => this.onReady()).then(() => {
|
|
234
231
|
if (this.shouldStart) {
|
|
@@ -408,10 +405,9 @@ class PusherSocket extends EventEmitter {
|
|
|
408
405
|
}
|
|
409
406
|
loadPusher() {
|
|
410
407
|
debug$1('Load Pusher');
|
|
411
|
-
return import('pusher-js').then(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
} = _ref;
|
|
408
|
+
return import('pusher-js').then(({
|
|
409
|
+
default: Pusher
|
|
410
|
+
}) => {
|
|
415
411
|
this.Pusher = Pusher;
|
|
416
412
|
});
|
|
417
413
|
}
|
|
@@ -783,21 +779,20 @@ const defaultProps = {
|
|
|
783
779
|
autoStart: false,
|
|
784
780
|
children: null
|
|
785
781
|
};
|
|
786
|
-
function SocketContainer(
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
} = _ref;
|
|
782
|
+
function SocketContainer({
|
|
783
|
+
children,
|
|
784
|
+
socket,
|
|
785
|
+
autoStart,
|
|
786
|
+
adapter,
|
|
787
|
+
host,
|
|
788
|
+
namespace,
|
|
789
|
+
uuid,
|
|
790
|
+
publishKey,
|
|
791
|
+
subscribeKey,
|
|
792
|
+
secretKey,
|
|
793
|
+
channels: initialChannels,
|
|
794
|
+
...props
|
|
795
|
+
}) {
|
|
801
796
|
const finalSocket = useMemo(() => socket || new Socket({
|
|
802
797
|
...props,
|
|
803
798
|
adapter,
|
|
@@ -823,11 +818,15 @@ function SocketContainer(_ref) {
|
|
|
823
818
|
}, [updateChannels]);
|
|
824
819
|
const removeToChannelsCount = useCallback(newChannels => {
|
|
825
820
|
channelsCountRef.current = newChannels.reduce((map, channel) => {
|
|
826
|
-
const
|
|
821
|
+
const {
|
|
822
|
+
[channel]: currentCount = 0,
|
|
823
|
+
...otherCount
|
|
824
|
+
} = map;
|
|
825
|
+
const newCount = (currentCount || 0) - 1;
|
|
827
826
|
return newCount > 0 ? {
|
|
828
|
-
...
|
|
827
|
+
...otherCount,
|
|
829
828
|
[channel]: newCount
|
|
830
|
-
} :
|
|
829
|
+
} : otherCount;
|
|
831
830
|
}, channelsCountRef.current);
|
|
832
831
|
updateChannels(Object.keys(channelsCountRef.current));
|
|
833
832
|
}, [updateChannels]);
|
|
@@ -865,31 +864,26 @@ SocketContainer.defaultProps = defaultProps;
|
|
|
865
864
|
const getDisplayName = WrappedComponent => WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
866
865
|
const withSocket = WrappedComponent => {
|
|
867
866
|
const WithSocketComponent = props => /*#__PURE__*/jsx(SocketContext.Consumer, {
|
|
868
|
-
children:
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
...props
|
|
879
|
-
});
|
|
880
|
-
}
|
|
867
|
+
children: ({
|
|
868
|
+
socket,
|
|
869
|
+
subscribe,
|
|
870
|
+
unsubscribe
|
|
871
|
+
}) => /*#__PURE__*/jsx(WrappedComponent, {
|
|
872
|
+
socket: socket,
|
|
873
|
+
socketSubscribe: subscribe,
|
|
874
|
+
socketUnsubscribe: unsubscribe,
|
|
875
|
+
...props
|
|
876
|
+
})
|
|
881
877
|
});
|
|
882
878
|
WithSocketComponent.displayName = `WithSocket(${getDisplayName(WrappedComponent)})`;
|
|
883
879
|
return WithSocketComponent;
|
|
884
880
|
};
|
|
885
881
|
|
|
886
|
-
const useSocket =
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
keepAlive = true
|
|
892
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
882
|
+
const useSocket = (channelNames = null, {
|
|
883
|
+
socket: customSocket = null,
|
|
884
|
+
onMessage: customOnMessage = null,
|
|
885
|
+
keepAlive = true
|
|
886
|
+
} = {}) => {
|
|
893
887
|
const {
|
|
894
888
|
socket: contextSocket,
|
|
895
889
|
subscribe,
|
|
@@ -932,9 +926,9 @@ const useSocket = function () {
|
|
|
932
926
|
if (socket === null) {
|
|
933
927
|
return () => {};
|
|
934
928
|
}
|
|
935
|
-
const onMessage =
|
|
929
|
+
const onMessage = (...args) => {
|
|
936
930
|
if (customOnMessage !== null) {
|
|
937
|
-
customOnMessage(...
|
|
931
|
+
customOnMessage(...args);
|
|
938
932
|
}
|
|
939
933
|
};
|
|
940
934
|
socket.on('message', onMessage);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/socket",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.26",
|
|
4
4
|
"description": "Socket utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"clean": "rm -rf dist",
|
|
37
37
|
"build": "rollup --bundleConfigAsCjs --config ../../rollup.config.js",
|
|
38
|
-
"
|
|
38
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@babel/runtime": "^7.4.3",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
57
57
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "a04cfaacb364f3b35307d65d8778b078dace4491"
|
|
60
60
|
}
|