@larksuiteoapi/node-sdk 1.48.0 → 1.49.0-alpha.1
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/es/index.js +26 -6
- package/lib/index.js +26 -6
- package/package.json +1 -1
- package/types/index.d.ts +6 -0
package/es/index.js
CHANGED
|
@@ -82742,6 +82742,10 @@ class WSClient {
|
|
|
82742
82742
|
constructor(params) {
|
|
82743
82743
|
this.wsConfig = new WSConfig();
|
|
82744
82744
|
this.isConnecting = false;
|
|
82745
|
+
this.reconnectInfo = {
|
|
82746
|
+
lastConnectTime: 0,
|
|
82747
|
+
nextConnectTime: 0,
|
|
82748
|
+
};
|
|
82745
82749
|
const { appId, appSecret, domain = Domain.Feishu, httpInstance = defaultHttpInstance, loggerLevel = LoggerLevel.info, logger = defaultLogger, autoReconnect = true } = params;
|
|
82746
82750
|
this.logger = new LoggerProxy(loggerLevel, logger);
|
|
82747
82751
|
assert(!appId, () => this.logger.error('appId is needed'));
|
|
@@ -82822,6 +82826,7 @@ class WSClient {
|
|
|
82822
82826
|
}
|
|
82823
82827
|
this.isConnecting = true;
|
|
82824
82828
|
const tryConnect = () => {
|
|
82829
|
+
this.reconnectInfo.lastConnectTime = Date.now();
|
|
82825
82830
|
return this.pullConnectConfig()
|
|
82826
82831
|
.then(isSuccess => isSuccess ? this.connect() : Promise.resolve(false))
|
|
82827
82832
|
.then(isSuccess => {
|
|
@@ -82830,8 +82835,6 @@ class WSClient {
|
|
|
82830
82835
|
return Promise.resolve(true);
|
|
82831
82836
|
}
|
|
82832
82837
|
return Promise.resolve(false);
|
|
82833
|
-
}).finally(() => {
|
|
82834
|
-
this.isConnecting = false;
|
|
82835
82838
|
});
|
|
82836
82839
|
};
|
|
82837
82840
|
if (this.pingInterval) {
|
|
@@ -82842,7 +82845,16 @@ class WSClient {
|
|
|
82842
82845
|
if (wsInstance) {
|
|
82843
82846
|
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
82844
82847
|
}
|
|
82845
|
-
|
|
82848
|
+
if (this.reconnectInterval) {
|
|
82849
|
+
clearTimeout(this.reconnectInterval);
|
|
82850
|
+
}
|
|
82851
|
+
let isSuccess = false;
|
|
82852
|
+
try {
|
|
82853
|
+
isSuccess = yield tryConnect();
|
|
82854
|
+
}
|
|
82855
|
+
finally {
|
|
82856
|
+
this.isConnecting = false;
|
|
82857
|
+
}
|
|
82846
82858
|
if (!isSuccess) {
|
|
82847
82859
|
this.logger.error('[ws]', 'connect failed');
|
|
82848
82860
|
yield this.reConnect();
|
|
@@ -82859,7 +82871,8 @@ class WSClient {
|
|
|
82859
82871
|
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
82860
82872
|
}
|
|
82861
82873
|
this.wsConfig.setWSInstance(null);
|
|
82862
|
-
|
|
82874
|
+
const reconnectNonceTime = reconnectNonce ? reconnectNonce * Math.random() : 0;
|
|
82875
|
+
this.reconnectInterval = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
82863
82876
|
(function loopReConnect(count) {
|
|
82864
82877
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82865
82878
|
count++;
|
|
@@ -82867,18 +82880,22 @@ class WSClient {
|
|
|
82867
82880
|
// if reconnectCount < 0, the reconnect time is infinite
|
|
82868
82881
|
if (isSuccess) {
|
|
82869
82882
|
this.logger.debug('[ws]', 'reconnect success');
|
|
82883
|
+
this.isConnecting = false;
|
|
82870
82884
|
return;
|
|
82871
82885
|
}
|
|
82872
82886
|
this.logger.info('ws', `unable to connect to the server after trying ${count} times")`);
|
|
82873
82887
|
if (reconnectCount >= 0 && count >= reconnectCount) {
|
|
82888
|
+
this.isConnecting = false;
|
|
82874
82889
|
return;
|
|
82875
82890
|
}
|
|
82876
|
-
setTimeout(() => {
|
|
82891
|
+
this.reconnectInterval = setTimeout(() => {
|
|
82877
82892
|
loopReConnect.bind(this)(count);
|
|
82878
82893
|
}, reconnectInterval);
|
|
82894
|
+
this.reconnectInfo.nextConnectTime = Date.now() + reconnectInterval;
|
|
82879
82895
|
});
|
|
82880
82896
|
}).bind(this)(0);
|
|
82881
|
-
}),
|
|
82897
|
+
}), reconnectNonceTime);
|
|
82898
|
+
this.reconnectInfo.nextConnectTime = Date.now() + reconnectInterval;
|
|
82882
82899
|
});
|
|
82883
82900
|
}
|
|
82884
82901
|
pingLoop() {
|
|
@@ -82995,6 +83012,9 @@ class WSClient {
|
|
|
82995
83012
|
});
|
|
82996
83013
|
}
|
|
82997
83014
|
}
|
|
83015
|
+
getReconnectInfo() {
|
|
83016
|
+
return this.reconnectInfo;
|
|
83017
|
+
}
|
|
82998
83018
|
start(params) {
|
|
82999
83019
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83000
83020
|
this.logger.info('[ws]', `receive events or callbacks through persistent connection only available in self-build & Feishu app, Configured in:
|
package/lib/index.js
CHANGED
|
@@ -82757,6 +82757,10 @@ class WSClient {
|
|
|
82757
82757
|
constructor(params) {
|
|
82758
82758
|
this.wsConfig = new WSConfig();
|
|
82759
82759
|
this.isConnecting = false;
|
|
82760
|
+
this.reconnectInfo = {
|
|
82761
|
+
lastConnectTime: 0,
|
|
82762
|
+
nextConnectTime: 0,
|
|
82763
|
+
};
|
|
82760
82764
|
const { appId, appSecret, domain = exports.Domain.Feishu, httpInstance = defaultHttpInstance, loggerLevel = exports.LoggerLevel.info, logger = defaultLogger, autoReconnect = true } = params;
|
|
82761
82765
|
this.logger = new LoggerProxy(loggerLevel, logger);
|
|
82762
82766
|
assert(!appId, () => this.logger.error('appId is needed'));
|
|
@@ -82837,6 +82841,7 @@ class WSClient {
|
|
|
82837
82841
|
}
|
|
82838
82842
|
this.isConnecting = true;
|
|
82839
82843
|
const tryConnect = () => {
|
|
82844
|
+
this.reconnectInfo.lastConnectTime = Date.now();
|
|
82840
82845
|
return this.pullConnectConfig()
|
|
82841
82846
|
.then(isSuccess => isSuccess ? this.connect() : Promise.resolve(false))
|
|
82842
82847
|
.then(isSuccess => {
|
|
@@ -82845,8 +82850,6 @@ class WSClient {
|
|
|
82845
82850
|
return Promise.resolve(true);
|
|
82846
82851
|
}
|
|
82847
82852
|
return Promise.resolve(false);
|
|
82848
|
-
}).finally(() => {
|
|
82849
|
-
this.isConnecting = false;
|
|
82850
82853
|
});
|
|
82851
82854
|
};
|
|
82852
82855
|
if (this.pingInterval) {
|
|
@@ -82857,7 +82860,16 @@ class WSClient {
|
|
|
82857
82860
|
if (wsInstance) {
|
|
82858
82861
|
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
82859
82862
|
}
|
|
82860
|
-
|
|
82863
|
+
if (this.reconnectInterval) {
|
|
82864
|
+
clearTimeout(this.reconnectInterval);
|
|
82865
|
+
}
|
|
82866
|
+
let isSuccess = false;
|
|
82867
|
+
try {
|
|
82868
|
+
isSuccess = yield tryConnect();
|
|
82869
|
+
}
|
|
82870
|
+
finally {
|
|
82871
|
+
this.isConnecting = false;
|
|
82872
|
+
}
|
|
82861
82873
|
if (!isSuccess) {
|
|
82862
82874
|
this.logger.error('[ws]', 'connect failed');
|
|
82863
82875
|
yield this.reConnect();
|
|
@@ -82874,7 +82886,8 @@ class WSClient {
|
|
|
82874
82886
|
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
82875
82887
|
}
|
|
82876
82888
|
this.wsConfig.setWSInstance(null);
|
|
82877
|
-
|
|
82889
|
+
const reconnectNonceTime = reconnectNonce ? reconnectNonce * Math.random() : 0;
|
|
82890
|
+
this.reconnectInterval = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
82878
82891
|
(function loopReConnect(count) {
|
|
82879
82892
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82880
82893
|
count++;
|
|
@@ -82882,18 +82895,22 @@ class WSClient {
|
|
|
82882
82895
|
// if reconnectCount < 0, the reconnect time is infinite
|
|
82883
82896
|
if (isSuccess) {
|
|
82884
82897
|
this.logger.debug('[ws]', 'reconnect success');
|
|
82898
|
+
this.isConnecting = false;
|
|
82885
82899
|
return;
|
|
82886
82900
|
}
|
|
82887
82901
|
this.logger.info('ws', `unable to connect to the server after trying ${count} times")`);
|
|
82888
82902
|
if (reconnectCount >= 0 && count >= reconnectCount) {
|
|
82903
|
+
this.isConnecting = false;
|
|
82889
82904
|
return;
|
|
82890
82905
|
}
|
|
82891
|
-
setTimeout(() => {
|
|
82906
|
+
this.reconnectInterval = setTimeout(() => {
|
|
82892
82907
|
loopReConnect.bind(this)(count);
|
|
82893
82908
|
}, reconnectInterval);
|
|
82909
|
+
this.reconnectInfo.nextConnectTime = Date.now() + reconnectInterval;
|
|
82894
82910
|
});
|
|
82895
82911
|
}).bind(this)(0);
|
|
82896
|
-
}),
|
|
82912
|
+
}), reconnectNonceTime);
|
|
82913
|
+
this.reconnectInfo.nextConnectTime = Date.now() + reconnectInterval;
|
|
82897
82914
|
});
|
|
82898
82915
|
}
|
|
82899
82916
|
pingLoop() {
|
|
@@ -83010,6 +83027,9 @@ class WSClient {
|
|
|
83010
83027
|
});
|
|
83011
83028
|
}
|
|
83012
83029
|
}
|
|
83030
|
+
getReconnectInfo() {
|
|
83031
|
+
return this.reconnectInfo;
|
|
83032
|
+
}
|
|
83013
83033
|
start(params) {
|
|
83014
83034
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83015
83035
|
this.logger.info('[ws]', `receive events or callbacks through persistent connection only available in self-build & Feishu app, Configured in:
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -265917,7 +265917,9 @@ declare class WSClient {
|
|
|
265917
265917
|
private httpInstance;
|
|
265918
265918
|
private eventDispatcher?;
|
|
265919
265919
|
private pingInterval?;
|
|
265920
|
+
private reconnectInterval?;
|
|
265920
265921
|
private isConnecting;
|
|
265922
|
+
private reconnectInfo;
|
|
265921
265923
|
constructor(params: IConstructorParams);
|
|
265922
265924
|
private pullConnectConfig;
|
|
265923
265925
|
private connect;
|
|
@@ -265927,6 +265929,10 @@ declare class WSClient {
|
|
|
265927
265929
|
private handleControlData;
|
|
265928
265930
|
private handleEventData;
|
|
265929
265931
|
private sendMessage;
|
|
265932
|
+
getReconnectInfo(): {
|
|
265933
|
+
lastConnectTime: number;
|
|
265934
|
+
nextConnectTime: number;
|
|
265935
|
+
};
|
|
265930
265936
|
start(params: {
|
|
265931
265937
|
eventDispatcher: EventDispatcher;
|
|
265932
265938
|
}): Promise<void>;
|