|
@@ -32,6 +32,10 @@ class NchanDelegator extends ConfigPubsubDelegator {
|
|
|
* @inheritdoc
|
|
* @inheritdoc
|
|
|
*/
|
|
*/
|
|
|
shouldResubscribe() {
|
|
shouldResubscribe() {
|
|
|
|
|
+ if (this.client == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (this.connection != null && this.connection.connected) {
|
|
if (this.connection != null && this.connection.connected) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -49,15 +53,15 @@ class NchanDelegator extends ConfigPubsubDelegator {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (this.shouldResubscribe()) {
|
|
|
|
|
+ logger.info('The connection to config pubsub server is offline. Try to reconnect...');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// init client
|
|
// init client
|
|
|
if (this.client == null) {
|
|
if (this.client == null) {
|
|
|
this.initClient();
|
|
this.initClient();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (this.shouldResubscribe()) {
|
|
|
|
|
- logger.info('The connection to config pubsub server is offline. Try to reconnect...');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// connect
|
|
// connect
|
|
|
this.isConnecting = true;
|
|
this.isConnecting = true;
|
|
|
const url = this.constructUrl(this.subscribePath).toString();
|
|
const url = this.constructUrl(this.subscribePath).toString();
|
|
@@ -82,8 +86,6 @@ class NchanDelegator extends ConfigPubsubDelegator {
|
|
|
addMessageHandler(handlable) {
|
|
addMessageHandler(handlable) {
|
|
|
super.addMessageHandler(handlable);
|
|
super.addMessageHandler(handlable);
|
|
|
|
|
|
|
|
- this.handlableList.push(handlable);
|
|
|
|
|
-
|
|
|
|
|
if (this.connection != null) {
|
|
if (this.connection != null) {
|
|
|
this.connection.on('message', (messageObj) => {
|
|
this.connection.on('message', (messageObj) => {
|
|
|
this.handleMessage(messageObj, handlable);
|
|
this.handleMessage(messageObj, handlable);
|
|
@@ -91,6 +93,14 @@ class NchanDelegator extends ConfigPubsubDelegator {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ removeMessageHandler(handlable) {
|
|
|
|
|
+ super.removeMessageHandler(handlable);
|
|
|
|
|
+ this.subscribe(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
constructUrl(basepath) {
|
|
constructUrl(basepath) {
|
|
|
const pathname = this.channelId == null
|
|
const pathname = this.channelId == null
|
|
|
? basepath // /pubsub
|
|
? basepath // /pubsub
|