@bloks/link-session-manager
Advanced tools
Comparing version 0.2.623 to 0.2.624
/** | ||
* proton-link-session-manager v0.2.623 | ||
* proton-link-session-manager v0.2.624 | ||
* https://github.com/greymass/proton-link-session-manager | ||
@@ -4,0 +4,0 @@ * |
/** | ||
* proton-link-session-manager v0.2.623 | ||
* proton-link-session-manager v0.2.624 | ||
* https://github.com/greymass/proton-link-session-manager | ||
@@ -114,3 +114,2 @@ * | ||
this.pendingReconnect = undefined; | ||
this.connectivityEventsAttached = false; | ||
this.binaryType = 'blob'; | ||
@@ -125,9 +124,11 @@ this.opts = { | ||
shouldReconnect: function (event, ws) { | ||
if (event.code === 1008 || event.code === 1011) | ||
return; | ||
return [0, 3000, 10000][ws.attempts]; | ||
if ([1000, 4001].includes(event.code)) { | ||
return undefined; | ||
} | ||
else { | ||
return Math.pow(1.5, ws.attempts) * 300; | ||
} | ||
}, | ||
// Flag to control whether attachement to navigator online/offline events | ||
// should be disabled. | ||
ignoreConnectivityEvents: false, | ||
// React native netinfo | ||
netInfo: undefined, | ||
// Create and connect the WebSocket when the instance is instantiated. | ||
@@ -213,3 +214,3 @@ // Defaults to true to match standard WebSocket behavior | ||
} | ||
if (!this.opts.ignoreConnectivityEvents) { | ||
if (this.opts.netInfo) { | ||
console.log(10); | ||
@@ -225,26 +226,25 @@ this.attachConnectivityEvents(); | ||
}; | ||
RobustWebSocket.prototype.ononline = function (event) { | ||
if (this.reconnectWhenOnlineAgain) { | ||
this.clearPendingReconnectIfNeeded(); | ||
this.reconnect(event); | ||
} | ||
}; | ||
RobustWebSocket.prototype.onoffline = function () { | ||
this.reconnectWhenOnlineAgain = true; | ||
if (this.realWs) { | ||
this.realWs.close(1000); | ||
} | ||
}; | ||
RobustWebSocket.prototype.detachConnectivityEvents = function () { | ||
if (this.connectivityEventsAttached) { | ||
global.removeEventListener('online', this.ononline); | ||
global.removeEventListener('offline', this.onoffline); | ||
this.connectivityEventsAttached = false; | ||
if (this.unsubscribeNetInfo) { | ||
this.unsubscribeNetInfo(); | ||
} | ||
}; | ||
RobustWebSocket.prototype.attachConnectivityEvents = function () { | ||
if (!this.connectivityEventsAttached) { | ||
global.addEventListener('online', this.ononline); | ||
global.addEventListener('offline', this.onoffline); | ||
this.connectivityEventsAttached = true; | ||
var _this = this; | ||
if (!this.unsubscribeNetInfo && this.opts.netInfo) { | ||
this.unsubscribeNetInfo = this.opts.netInfo.addEventListener(function (state) { | ||
var isOnline = state.isConnected && !_this.netInfoState.isConnected; | ||
if (isOnline && _this.reconnectWhenOnlineAgain) { | ||
_this.clearPendingReconnectIfNeeded(); | ||
_this.reconnect({ code: 0 }); | ||
} | ||
var isOffline = !state.isConnected && _this.netInfoState.isConnected; | ||
if (isOffline) { | ||
_this.reconnectWhenOnlineAgain = true; | ||
if (_this.realWs) { | ||
_this.realWs.close(1000); | ||
} | ||
} | ||
_this.netInfoState = state; | ||
}); | ||
} | ||
@@ -254,3 +254,2 @@ }; | ||
if (this.realWs) { | ||
// eslint-disable-next-line prefer-spread, prefer-rest-params | ||
return this.realWs.send(data); | ||
@@ -257,0 +256,0 @@ } |
/** | ||
* proton-link-session-manager v0.2.623 | ||
* proton-link-session-manager v0.2.624 | ||
* https://github.com/greymass/proton-link-session-manager | ||
@@ -90,3 +90,2 @@ * | ||
this.pendingReconnect = undefined; | ||
this.connectivityEventsAttached = false; | ||
this.binaryType = 'blob'; | ||
@@ -101,9 +100,11 @@ this.opts = { | ||
shouldReconnect: function (event, ws) { | ||
if (event.code === 1008 || event.code === 1011) | ||
return; | ||
return [0, 3000, 10000][ws.attempts]; | ||
if ([1000, 4001].includes(event.code)) { | ||
return undefined; | ||
} | ||
else { | ||
return Math.pow(1.5, ws.attempts) * 300; | ||
} | ||
}, | ||
// Flag to control whether attachement to navigator online/offline events | ||
// should be disabled. | ||
ignoreConnectivityEvents: false, | ||
// React native netinfo | ||
netInfo: undefined, | ||
// Create and connect the WebSocket when the instance is instantiated. | ||
@@ -169,3 +170,3 @@ // Defaults to true to match standard WebSocket behavior | ||
} | ||
if (!this.opts.ignoreConnectivityEvents) { | ||
if (this.opts.netInfo) { | ||
console.log(10); | ||
@@ -181,26 +182,24 @@ this.attachConnectivityEvents(); | ||
} | ||
ononline(event) { | ||
if (this.reconnectWhenOnlineAgain) { | ||
this.clearPendingReconnectIfNeeded(); | ||
this.reconnect(event); | ||
} | ||
} | ||
onoffline() { | ||
this.reconnectWhenOnlineAgain = true; | ||
if (this.realWs) { | ||
this.realWs.close(1000); | ||
} | ||
} | ||
detachConnectivityEvents() { | ||
if (this.connectivityEventsAttached) { | ||
global.removeEventListener('online', this.ononline); | ||
global.removeEventListener('offline', this.onoffline); | ||
this.connectivityEventsAttached = false; | ||
if (this.unsubscribeNetInfo) { | ||
this.unsubscribeNetInfo(); | ||
} | ||
} | ||
attachConnectivityEvents() { | ||
if (!this.connectivityEventsAttached) { | ||
global.addEventListener('online', this.ononline); | ||
global.addEventListener('offline', this.onoffline); | ||
this.connectivityEventsAttached = true; | ||
if (!this.unsubscribeNetInfo && this.opts.netInfo) { | ||
this.unsubscribeNetInfo = this.opts.netInfo.addEventListener(state => { | ||
const isOnline = state.isConnected && !this.netInfoState.isConnected; | ||
if (isOnline && this.reconnectWhenOnlineAgain) { | ||
this.clearPendingReconnectIfNeeded(); | ||
this.reconnect({ code: 0 }); | ||
} | ||
const isOffline = !state.isConnected && this.netInfoState.isConnected; | ||
if (isOffline) { | ||
this.reconnectWhenOnlineAgain = true; | ||
if (this.realWs) { | ||
this.realWs.close(1000); | ||
} | ||
} | ||
this.netInfoState = state; | ||
}); | ||
} | ||
@@ -210,3 +209,2 @@ } | ||
if (this.realWs) { | ||
// eslint-disable-next-line prefer-spread, prefer-rest-params | ||
return this.realWs.send(data); | ||
@@ -213,0 +211,0 @@ } |
{ | ||
"name": "@bloks/link-session-manager", | ||
"description": "Session management for signature providers when receiving requests using the Anchor Link protocol", | ||
"version": "0.2.623", | ||
"version": "0.2.624", | ||
"homepage": "https://github.com/greymass/proton-link-session-manager", | ||
@@ -6,0 +6,0 @@ "license": "BSD-3-Clause", |
@@ -10,6 +10,15 @@ export default class RobustWebSocket { | ||
connectTimeout?: any | ||
connectivityEventsAttached = false | ||
binaryType: BinaryType = 'blob' | ||
opts = { | ||
netInfo?: any | ||
netInfoState?: any | ||
unsubscribeNetInfo?: any | ||
opts: { | ||
timeout: number | ||
shouldReconnect: (event: any, ws: any) => number | undefined | ||
netInfo: any | ||
automaticOpen: boolean | ||
handle1000: boolean | ||
} = { | ||
// the time to wait before a successful connection | ||
@@ -22,9 +31,11 @@ // before the attempt is considered to have timed out | ||
shouldReconnect: function (event, ws) { | ||
if (event.code === 1008 || event.code === 1011) return | ||
return [0, 3000, 10000][ws.attempts] | ||
if ([1000, 4001].includes(event.code)) { | ||
return undefined | ||
} else { | ||
return Math.pow(1.5, ws.attempts) * 300 | ||
} | ||
}, | ||
// Flag to control whether attachement to navigator online/offline events | ||
// should be disabled. | ||
ignoreConnectivityEvents: false, | ||
// React native netinfo | ||
netInfo: undefined, | ||
@@ -114,3 +125,3 @@ // Create and connect the WebSocket when the instance is instantiated. | ||
if (!this.opts.ignoreConnectivityEvents) { | ||
if (this.opts.netInfo) { | ||
console.log(10) | ||
@@ -127,21 +138,6 @@ this.attachConnectivityEvents() | ||
} | ||
ononline(event) { | ||
if (this.reconnectWhenOnlineAgain) { | ||
this.clearPendingReconnectIfNeeded() | ||
this.reconnect(event) | ||
} | ||
} | ||
onoffline() { | ||
this.reconnectWhenOnlineAgain = true | ||
if (this.realWs) { | ||
this.realWs.close(1000) | ||
} | ||
} | ||
detachConnectivityEvents() { | ||
if (this.connectivityEventsAttached) { | ||
global.removeEventListener('online', this.ononline) | ||
global.removeEventListener('offline', this.onoffline) | ||
this.connectivityEventsAttached = false | ||
if (this.unsubscribeNetInfo) { | ||
this.unsubscribeNetInfo() | ||
} | ||
@@ -151,6 +147,20 @@ } | ||
attachConnectivityEvents() { | ||
if (!this.connectivityEventsAttached) { | ||
global.addEventListener('online', this.ononline) | ||
global.addEventListener('offline', this.onoffline) | ||
this.connectivityEventsAttached = true | ||
if (!this.unsubscribeNetInfo && this.opts.netInfo) { | ||
this.unsubscribeNetInfo = this.opts.netInfo.addEventListener(state => { | ||
const isOnline = state.isConnected && !this.netInfoState.isConnected | ||
if (isOnline && this.reconnectWhenOnlineAgain) { | ||
this.clearPendingReconnectIfNeeded() | ||
this.reconnect({code: 0}) | ||
} | ||
const isOffline = !state.isConnected && this.netInfoState.isConnected | ||
if (isOffline) { | ||
this.reconnectWhenOnlineAgain = true | ||
if (this.realWs) { | ||
this.realWs.close(1000) | ||
} | ||
} | ||
this.netInfoState = state | ||
}) | ||
} | ||
@@ -161,3 +171,2 @@ } | ||
if (this.realWs) { | ||
// eslint-disable-next-line prefer-spread, prefer-rest-params | ||
return this.realWs.send(data) | ||
@@ -164,0 +173,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
102765
1760