@folklore/socket 0.4.25 → 0.4.27
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 +43 -53
- package/dist/es.js +43 -53
- package/package.json +7 -7
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,
|
|
@@ -873,31 +868,26 @@ SocketContainer.defaultProps = defaultProps;
|
|
|
873
868
|
const getDisplayName = WrappedComponent => WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
874
869
|
const withSocket = WrappedComponent => {
|
|
875
870
|
const WithSocketComponent = props => /*#__PURE__*/jsxRuntime.jsx(SocketContext.Consumer, {
|
|
876
|
-
children:
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
...props
|
|
887
|
-
});
|
|
888
|
-
}
|
|
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
|
+
})
|
|
889
881
|
});
|
|
890
882
|
WithSocketComponent.displayName = `WithSocket(${getDisplayName(WrappedComponent)})`;
|
|
891
883
|
return WithSocketComponent;
|
|
892
884
|
};
|
|
893
885
|
|
|
894
|
-
const useSocket =
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
keepAlive = true
|
|
900
|
-
} = 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
|
+
} = {}) => {
|
|
901
891
|
const {
|
|
902
892
|
socket: contextSocket,
|
|
903
893
|
subscribe,
|
|
@@ -940,9 +930,9 @@ const useSocket = function () {
|
|
|
940
930
|
if (socket === null) {
|
|
941
931
|
return () => {};
|
|
942
932
|
}
|
|
943
|
-
const onMessage =
|
|
933
|
+
const onMessage = (...args) => {
|
|
944
934
|
if (customOnMessage !== null) {
|
|
945
|
-
customOnMessage(...
|
|
935
|
+
customOnMessage(...args);
|
|
946
936
|
}
|
|
947
937
|
};
|
|
948
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,
|
|
@@ -869,31 +864,26 @@ SocketContainer.defaultProps = defaultProps;
|
|
|
869
864
|
const getDisplayName = WrappedComponent => WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
870
865
|
const withSocket = WrappedComponent => {
|
|
871
866
|
const WithSocketComponent = props => /*#__PURE__*/jsx(SocketContext.Consumer, {
|
|
872
|
-
children:
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
...props
|
|
883
|
-
});
|
|
884
|
-
}
|
|
867
|
+
children: ({
|
|
868
|
+
socket,
|
|
869
|
+
subscribe,
|
|
870
|
+
unsubscribe
|
|
871
|
+
}) => /*#__PURE__*/jsx(WrappedComponent, {
|
|
872
|
+
socket: socket,
|
|
873
|
+
socketSubscribe: subscribe,
|
|
874
|
+
socketUnsubscribe: unsubscribe,
|
|
875
|
+
...props
|
|
876
|
+
})
|
|
885
877
|
});
|
|
886
878
|
WithSocketComponent.displayName = `WithSocket(${getDisplayName(WrappedComponent)})`;
|
|
887
879
|
return WithSocketComponent;
|
|
888
880
|
};
|
|
889
881
|
|
|
890
|
-
const useSocket =
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
keepAlive = true
|
|
896
|
-
} = 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
|
+
} = {}) => {
|
|
897
887
|
const {
|
|
898
888
|
socket: contextSocket,
|
|
899
889
|
subscribe,
|
|
@@ -936,9 +926,9 @@ const useSocket = function () {
|
|
|
936
926
|
if (socket === null) {
|
|
937
927
|
return () => {};
|
|
938
928
|
}
|
|
939
|
-
const onMessage =
|
|
929
|
+
const onMessage = (...args) => {
|
|
940
930
|
if (customOnMessage !== null) {
|
|
941
|
-
customOnMessage(...
|
|
931
|
+
customOnMessage(...args);
|
|
942
932
|
}
|
|
943
933
|
};
|
|
944
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.27",
|
|
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",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"wolfy87-eventemitter": "^5.2.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
53
|
-
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
52
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
53
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
57
|
-
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
56
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
57
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "2056c43ca08a0a3eafdd4542887c6923871e100b"
|
|
60
60
|
}
|