@kigi/components 1.62.5-beta.1 → 1.62.6-beta.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/package.json
CHANGED
|
@@ -27,11 +27,32 @@ class MbgConnectionRetry {
|
|
|
27
27
|
|
|
28
28
|
constructor(public $scope, public $element, public $attrs, public $timeout, public $http) { }
|
|
29
29
|
|
|
30
|
+
private isDebugEnabled = () => {
|
|
31
|
+
try {
|
|
32
|
+
return localStorage.getItem('mbgConnectionRetryDebug') === 'true'
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private debugLog = (message: string, payload?: any) => {
|
|
39
|
+
if (!this.isDebugEnabled()) { return }
|
|
40
|
+
if (payload !== undefined) {
|
|
41
|
+
console.log(`[mbg-connection-retry] ${message}`, payload)
|
|
42
|
+
} else {
|
|
43
|
+
console.log(`[mbg-connection-retry] ${message}`)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
$onInit() {
|
|
31
48
|
this.verifingCount = 0
|
|
32
49
|
this.onLine = navigator.onLine
|
|
33
50
|
this.wifiImage = wifiImage
|
|
34
51
|
this.connectionError = false
|
|
52
|
+
this.debugLog('$onInit', {
|
|
53
|
+
onLine: this.onLine,
|
|
54
|
+
pingUrl: this.pingUrl,
|
|
55
|
+
})
|
|
35
56
|
window.addEventListener('online', this.handleConnectionChange)
|
|
36
57
|
window.addEventListener('offline', this.handleConnectionChange)
|
|
37
58
|
this.tryConnect()
|
|
@@ -44,6 +65,11 @@ class MbgConnectionRetry {
|
|
|
44
65
|
|
|
45
66
|
handleConnectionChange = (evt) => {
|
|
46
67
|
this.onLine = evt.type === 'online'
|
|
68
|
+
this.debugLog('handleConnectionChange', {
|
|
69
|
+
eventType: evt.type,
|
|
70
|
+
onLine: this.onLine,
|
|
71
|
+
navigatorOnLine: navigator.onLine,
|
|
72
|
+
})
|
|
47
73
|
this.tryConnect()
|
|
48
74
|
}
|
|
49
75
|
|
|
@@ -51,22 +77,40 @@ class MbgConnectionRetry {
|
|
|
51
77
|
if (this.verifing) { return }
|
|
52
78
|
this.verifing = true
|
|
53
79
|
this.verifingCount++
|
|
80
|
+
this.debugLog('tryConnect:start', {
|
|
81
|
+
verifingCount: this.verifingCount,
|
|
82
|
+
onLine: this.onLine,
|
|
83
|
+
pingUrl: this.pingUrl,
|
|
84
|
+
})
|
|
54
85
|
this.$timeout(() => {
|
|
55
86
|
if (!this.pingUrl) { throw `O atributo ping-url não foi informado ou não possui valor.` }
|
|
56
87
|
if (!this.onLine) {
|
|
57
88
|
this.verifingCount = 0
|
|
58
89
|
this.verifing = false
|
|
59
90
|
this.connectionError = true
|
|
91
|
+
this.debugLog('tryConnect:blocked_offline', {
|
|
92
|
+
connectionError: this.connectionError,
|
|
93
|
+
navigatorOnLine: navigator.onLine,
|
|
94
|
+
})
|
|
60
95
|
} else {
|
|
61
96
|
return this.$http.get(this.pingUrl)
|
|
62
97
|
.then(() => {
|
|
63
98
|
this.verifing = false
|
|
64
99
|
this.verifingCount = 0
|
|
100
|
+
this.debugLog('tryConnect:success', {
|
|
101
|
+
connectionError: false,
|
|
102
|
+
})
|
|
65
103
|
this.$timeout(() => this.connectionError = false)
|
|
66
104
|
})
|
|
67
|
-
.catch(() => {
|
|
105
|
+
.catch((error) => {
|
|
68
106
|
this.connectionError = true
|
|
69
107
|
this.verifing = false
|
|
108
|
+
this.debugLog('tryConnect:error', {
|
|
109
|
+
status: error && error.status,
|
|
110
|
+
url: error && error.config && error.config.url,
|
|
111
|
+
message: error && error.message,
|
|
112
|
+
navigatorOnLine: navigator.onLine,
|
|
113
|
+
})
|
|
70
114
|
this.$timeout(() => this.tryConnect(), 1500)
|
|
71
115
|
})
|
|
72
116
|
}
|