mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
implemented ws auto reconnect
This commit is contained in:
@@ -38,15 +38,23 @@ export default class ConnectorRIS extends Connector{
|
|||||||
constructor(name, params, env) {
|
constructor(name, params, env) {
|
||||||
super(name, params, env);
|
super(name, params, env);
|
||||||
this.ws = null;
|
this.ws = null;
|
||||||
|
this.subscription = null;
|
||||||
|
this.pingTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect = () =>
|
connect = () =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
delete this.pingTimer;
|
||||||
this.ws = new WebSocket(this.params.url);
|
this.ws = new WebSocket(this.params.url);
|
||||||
|
|
||||||
|
this.pingTimer = setInterval(() => {
|
||||||
|
this.ws.ping(() => {})
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
this.ws.on('message', this.message);
|
this.ws.on('message', this.message);
|
||||||
this.ws.on('close', this.error);
|
this.ws.on('close', this.close);
|
||||||
|
this.ws.on('error', this.error);
|
||||||
this.ws.on('open', () => {
|
this.ws.on('open', () => {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
this.connected(this.name + ' connector connected');
|
this.connected(this.name + ' connector connected');
|
||||||
@@ -59,6 +67,12 @@ export default class ConnectorRIS extends Connector{
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
close = (error) => {
|
||||||
|
this.error(error);
|
||||||
|
clearInterval(this.pingTimer);
|
||||||
|
setTimeout(() => this.subscribe(this.subscription), 5000);
|
||||||
|
};
|
||||||
|
|
||||||
_subscribeToAll = (input) => {
|
_subscribeToAll = (input) => {
|
||||||
console.log("Subscribing to everything");
|
console.log("Subscribing to everything");
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
@@ -84,6 +98,7 @@ export default class ConnectorRIS extends Connector{
|
|||||||
|
|
||||||
subscribe = (input) =>
|
subscribe = (input) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
|
this.subscription = input;
|
||||||
try {
|
try {
|
||||||
return (this.params.carefulSubscription) ?
|
return (this.params.carefulSubscription) ?
|
||||||
this._subscribeToPrefixes(input) :
|
this._subscribeToPrefixes(input) :
|
||||||
|
|||||||
Reference in New Issue
Block a user