@folklore/socket 0.4.12 → 0.4.14
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 +33 -2
- package/dist/es.js +33 -2
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -56,6 +56,7 @@ class PubNubSocket extends EventEmitter__default["default"] {
|
|
|
56
56
|
this.onReady = this.onReady.bind(this);
|
|
57
57
|
this.onStatus = this.onStatus.bind(this);
|
|
58
58
|
this.onMessage = this.onMessage.bind(this);
|
|
59
|
+
this.destroyed = false;
|
|
59
60
|
this.ready = false;
|
|
60
61
|
this.shouldStart = false;
|
|
61
62
|
this.started = false;
|
|
@@ -68,6 +69,10 @@ class PubNubSocket extends EventEmitter__default["default"] {
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
onReady() {
|
|
72
|
+
if (this.destroyed) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
71
76
|
this.ready = true;
|
|
72
77
|
this.emit('ready');
|
|
73
78
|
}
|
|
@@ -112,15 +117,31 @@ class PubNubSocket extends EventEmitter__default["default"] {
|
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
init() {
|
|
115
|
-
|
|
120
|
+
if (this.pubnub !== null) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
debug$2('Init');
|
|
125
|
+
this.destroyed = false;
|
|
126
|
+
const loadPubnub = this.PubNub !== null ? Promise.resolve() : this.loadPubNub();
|
|
127
|
+
loadPubnub.then(() => this.createPubNub()).then(() => this.onReady());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
loadPubNub() {
|
|
131
|
+
debug$2('Load PubNub');
|
|
132
|
+
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('pubnub')); }).then(_ref2 => {
|
|
116
133
|
let {
|
|
117
134
|
default: PubNub
|
|
118
135
|
} = _ref2;
|
|
119
136
|
this.PubNub = PubNub;
|
|
120
|
-
})
|
|
137
|
+
});
|
|
121
138
|
}
|
|
122
139
|
|
|
123
140
|
createPubNub() {
|
|
141
|
+
if (this.destroyed) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
124
145
|
const {
|
|
125
146
|
PubNub
|
|
126
147
|
} = this;
|
|
@@ -146,6 +167,7 @@ class PubNubSocket extends EventEmitter__default["default"] {
|
|
|
146
167
|
}
|
|
147
168
|
|
|
148
169
|
destroy() {
|
|
170
|
+
this.destroyed = true;
|
|
149
171
|
this.stop();
|
|
150
172
|
|
|
151
173
|
if (this.pubnubListener) {
|
|
@@ -153,6 +175,7 @@ class PubNubSocket extends EventEmitter__default["default"] {
|
|
|
153
175
|
this.pubnubListener = null;
|
|
154
176
|
}
|
|
155
177
|
|
|
178
|
+
this.pubnub = null;
|
|
156
179
|
this.ready = false;
|
|
157
180
|
debug$2('Destroyed.');
|
|
158
181
|
}
|
|
@@ -581,6 +604,12 @@ class Socket extends EventEmitter__default["default"] {
|
|
|
581
604
|
}
|
|
582
605
|
|
|
583
606
|
init() {
|
|
607
|
+
if (this.adapter !== null) {
|
|
608
|
+
debug('Already initialized');
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
debug('Init');
|
|
584
613
|
const {
|
|
585
614
|
adapter: adapterKey,
|
|
586
615
|
channels,
|
|
@@ -765,6 +794,8 @@ const SocketContainer = function (_ref) {
|
|
|
765
794
|
};
|
|
766
795
|
}, [initialChannels, subscribe, unsubscribe]);
|
|
767
796
|
React.useEffect(() => {
|
|
797
|
+
finalSocket.init();
|
|
798
|
+
|
|
768
799
|
if (autoStart) {
|
|
769
800
|
finalSocket.start();
|
|
770
801
|
}
|
package/dist/es.js
CHANGED
|
@@ -23,6 +23,7 @@ class PubNubSocket extends EventEmitter {
|
|
|
23
23
|
this.onReady = this.onReady.bind(this);
|
|
24
24
|
this.onStatus = this.onStatus.bind(this);
|
|
25
25
|
this.onMessage = this.onMessage.bind(this);
|
|
26
|
+
this.destroyed = false;
|
|
26
27
|
this.ready = false;
|
|
27
28
|
this.shouldStart = false;
|
|
28
29
|
this.started = false;
|
|
@@ -35,6 +36,10 @@ class PubNubSocket extends EventEmitter {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
onReady() {
|
|
39
|
+
if (this.destroyed) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
this.ready = true;
|
|
39
44
|
this.emit('ready');
|
|
40
45
|
}
|
|
@@ -79,15 +84,31 @@ class PubNubSocket extends EventEmitter {
|
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
init() {
|
|
82
|
-
|
|
87
|
+
if (this.pubnub !== null) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
debug$2('Init');
|
|
92
|
+
this.destroyed = false;
|
|
93
|
+
const loadPubnub = this.PubNub !== null ? Promise.resolve() : this.loadPubNub();
|
|
94
|
+
loadPubnub.then(() => this.createPubNub()).then(() => this.onReady());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
loadPubNub() {
|
|
98
|
+
debug$2('Load PubNub');
|
|
99
|
+
return import('pubnub').then(_ref2 => {
|
|
83
100
|
let {
|
|
84
101
|
default: PubNub
|
|
85
102
|
} = _ref2;
|
|
86
103
|
this.PubNub = PubNub;
|
|
87
|
-
})
|
|
104
|
+
});
|
|
88
105
|
}
|
|
89
106
|
|
|
90
107
|
createPubNub() {
|
|
108
|
+
if (this.destroyed) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
91
112
|
const {
|
|
92
113
|
PubNub
|
|
93
114
|
} = this;
|
|
@@ -113,6 +134,7 @@ class PubNubSocket extends EventEmitter {
|
|
|
113
134
|
}
|
|
114
135
|
|
|
115
136
|
destroy() {
|
|
137
|
+
this.destroyed = true;
|
|
116
138
|
this.stop();
|
|
117
139
|
|
|
118
140
|
if (this.pubnubListener) {
|
|
@@ -120,6 +142,7 @@ class PubNubSocket extends EventEmitter {
|
|
|
120
142
|
this.pubnubListener = null;
|
|
121
143
|
}
|
|
122
144
|
|
|
145
|
+
this.pubnub = null;
|
|
123
146
|
this.ready = false;
|
|
124
147
|
debug$2('Destroyed.');
|
|
125
148
|
}
|
|
@@ -548,6 +571,12 @@ class Socket extends EventEmitter {
|
|
|
548
571
|
}
|
|
549
572
|
|
|
550
573
|
init() {
|
|
574
|
+
if (this.adapter !== null) {
|
|
575
|
+
debug('Already initialized');
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
debug('Init');
|
|
551
580
|
const {
|
|
552
581
|
adapter: adapterKey,
|
|
553
582
|
channels,
|
|
@@ -732,6 +761,8 @@ const SocketContainer = function (_ref) {
|
|
|
732
761
|
};
|
|
733
762
|
}, [initialChannels, subscribe, unsubscribe]);
|
|
734
763
|
useEffect(() => {
|
|
764
|
+
finalSocket.init();
|
|
765
|
+
|
|
735
766
|
if (autoStart) {
|
|
736
767
|
finalSocket.start();
|
|
737
768
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/socket",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"description": "Socket utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
56
56
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "25ab3521653d3e6704e6e1b1b31c32410c2313cf"
|
|
59
59
|
}
|