@live-change/online-service 0.9.173 → 0.9.174
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/LICENSE.md +11 -0
- package/index.js +20 -18
- package/package.json +2 -2
package/LICENSE.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2019-2024 Michał Łaszczewski
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/index.js
CHANGED
|
@@ -6,6 +6,8 @@ import { server as WebSocketServer } from 'websocket'
|
|
|
6
6
|
import App from '@live-change/framework'
|
|
7
7
|
const app = App.app()
|
|
8
8
|
|
|
9
|
+
const logger = App.utils.loggingHelpers('online', '0.1.0')
|
|
10
|
+
|
|
9
11
|
const definition = app.createServiceDefinition({
|
|
10
12
|
name: 'online'
|
|
11
13
|
})
|
|
@@ -24,29 +26,29 @@ async function sendOnlineEvent(path) {
|
|
|
24
26
|
try {
|
|
25
27
|
if(type === 'object') {
|
|
26
28
|
const { group } = params
|
|
27
|
-
|
|
29
|
+
logger.log("PARAMs", params)
|
|
28
30
|
const triggerName = `${group}Online`
|
|
29
|
-
|
|
31
|
+
logger.log("TRIGGER", triggerName)
|
|
30
32
|
await app.trigger({ type: triggerName }, {
|
|
31
33
|
...params
|
|
32
34
|
})
|
|
33
35
|
} else if(type === 'user') {
|
|
34
36
|
const { group, user } = params
|
|
35
37
|
const triggerName = `user${group ? group.slice(0, 1).toUpperCase() + group.slice(1) : ''}Online`
|
|
36
|
-
|
|
38
|
+
logger.log("TRIGGER", triggerName)
|
|
37
39
|
await app.trigger({ type: triggerName }, {
|
|
38
40
|
...params
|
|
39
41
|
})
|
|
40
42
|
} else if(type === 'session') {
|
|
41
43
|
const { group, session } = params
|
|
42
44
|
const triggerName = `session${group ? group.slice(0, 1).toUpperCase() + group.slice(1) : ''}Online`
|
|
43
|
-
|
|
45
|
+
logger.log("TRIGGER", triggerName)
|
|
44
46
|
await app.trigger({ type: triggerName }, {
|
|
45
47
|
...params
|
|
46
48
|
})
|
|
47
49
|
}
|
|
48
50
|
} catch(error) {
|
|
49
|
-
|
|
51
|
+
logger.error("ONLINE EVENT ERROR")
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -57,32 +59,32 @@ async function sendOfflineEvent(path) {
|
|
|
57
59
|
if(type === 'object') {
|
|
58
60
|
const { group } = params
|
|
59
61
|
const triggerName = `${group}Offline`
|
|
60
|
-
|
|
62
|
+
logger.log("TRIGGER", triggerName)
|
|
61
63
|
await app.trigger({ type: triggerName }, {
|
|
62
64
|
...params
|
|
63
65
|
})
|
|
64
66
|
} else if(type === 'user') {
|
|
65
67
|
const { group, user } = params
|
|
66
68
|
const triggerName = `user${group ? group.slice(0, 1).toUpperCase() + group.slice(1) : ''}Offline`
|
|
67
|
-
|
|
69
|
+
logger.log("TRIGGER", triggerName)
|
|
68
70
|
await app.trigger({ type: triggerName }, {
|
|
69
71
|
...params,
|
|
70
72
|
})
|
|
71
73
|
} else if(type === 'session') {
|
|
72
74
|
const { group, session } = params
|
|
73
75
|
const triggerName = `session${group ? group.slice(0, 1).toUpperCase() + group.slice(1) : ''}Offline`
|
|
74
|
-
|
|
76
|
+
logger.log("TRIGGER", triggerName)
|
|
75
77
|
await app.trigger({ type: triggerName }, {
|
|
76
78
|
...params
|
|
77
79
|
})
|
|
78
80
|
}
|
|
79
81
|
} catch(error) {
|
|
80
|
-
|
|
82
|
+
logger.error("OFFLINE EVENT ERROR")
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
async function sendAllOfflineEvent() {
|
|
85
|
-
|
|
87
|
+
logger.log("SEND ALL OFFLINE EVENT")
|
|
86
88
|
await app.trigger({ type: `allOffline` }, { })
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -97,7 +99,7 @@ class SelfObservable extends ReactiveDao.Observable {
|
|
|
97
99
|
this.offlineEventTimeout = null
|
|
98
100
|
this.lastEvent = null
|
|
99
101
|
|
|
100
|
-
|
|
102
|
+
logger.log("PATH", this.path, "IS ONLINE")
|
|
101
103
|
this.setOnlineEventTimeout()
|
|
102
104
|
}
|
|
103
105
|
setOnlineEventTimeout() {
|
|
@@ -134,14 +136,14 @@ class SelfObservable extends ReactiveDao.Observable {
|
|
|
134
136
|
this.fireObserver(observer, 'set', this.observers.length)
|
|
135
137
|
}
|
|
136
138
|
unobserve(observer) {
|
|
137
|
-
|
|
139
|
+
logger.log("ONLINE UNOBSERVED")
|
|
138
140
|
this.observers.splice(this.observers.indexOf(observer), 1)
|
|
139
141
|
this.fireObservers('set', this.observers.length)
|
|
140
142
|
if(this.isUseless()) this.dispose()
|
|
141
143
|
}
|
|
142
144
|
dispose() {
|
|
143
145
|
this.disposed = true
|
|
144
|
-
|
|
146
|
+
logger.log("PATH", this.path, "IS OFFLINE")
|
|
145
147
|
this.disposeTimeout = setTimeout(() => {
|
|
146
148
|
if(this.disposed) {
|
|
147
149
|
selfObservables.delete(JSON.stringify(this.path))
|
|
@@ -158,7 +160,7 @@ class SelfObservable extends ReactiveDao.Observable {
|
|
|
158
160
|
this.disposed = false
|
|
159
161
|
this.clearOfflineEventTimeout()
|
|
160
162
|
this.setOnlineEventTimeout()
|
|
161
|
-
|
|
163
|
+
logger.log("PATH", this.path, "IS ONLINE AGAIN")
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
|
|
@@ -172,12 +174,12 @@ function getSelfObservable(path) {
|
|
|
172
174
|
|
|
173
175
|
const onlineDao = {
|
|
174
176
|
observable([type, ...path]) {
|
|
175
|
-
|
|
177
|
+
logger.log("OBSERVABLE", type, path)
|
|
176
178
|
if(type !== 'online') throw new Error("not found")
|
|
177
179
|
return getSelfObservable(path)
|
|
178
180
|
},
|
|
179
181
|
get([type, ...path]) {
|
|
180
|
-
|
|
182
|
+
logger.log("GET", type, path)
|
|
181
183
|
if(type !== 'online') throw new Error("not found")
|
|
182
184
|
let observable = selfObservables.get(path)
|
|
183
185
|
return observable ? observable.observers.length : 0
|
|
@@ -187,7 +189,7 @@ const onlineDao = {
|
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
const createDao = (clientSessionId) => {
|
|
190
|
-
|
|
192
|
+
logger.log("ONLINE SERVICE DAO")
|
|
191
193
|
return onlineDao
|
|
192
194
|
}
|
|
193
195
|
|
|
@@ -205,7 +207,7 @@ definition.afterStart(async service => {
|
|
|
205
207
|
reactiveServer.handleConnection(serverConnection)
|
|
206
208
|
})
|
|
207
209
|
|
|
208
|
-
|
|
210
|
+
logger.log(`online server started at localhost:${onlinePort}`)
|
|
209
211
|
})
|
|
210
212
|
|
|
211
213
|
const onlineClient = new ReactiveDaoWebsocket.client("api-server-"+process.pid, onlineUrl)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/online-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.174",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
},
|
|
11
11
|
"author": "Michał Łaszczewski <michal@emikse.com>",
|
|
12
12
|
"license": "BSD-3-Clause",
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "6ebdadad702526df240bd3aa7ac3d97324a0308a",
|
|
14
14
|
"type": "module"
|
|
15
15
|
}
|