@jcbuisson/express-x 2.0.1 → 2.0.2
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 +1 -1
- package/src/common-hooks.mjs +2 -3
- package/src/server.mjs +7 -0
package/package.json
CHANGED
package/src/common-hooks.mjs
CHANGED
|
@@ -35,14 +35,13 @@ export function protect(field) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/*
|
|
38
|
-
* Does nothing for calls which are not client-side
|
|
38
|
+
* Does nothing for calls which are not client-side
|
|
39
39
|
* Check if the 'expireAt' key in socket.data is met
|
|
40
40
|
* If it is met, throw an error (which will be sent back to the calling server or client) and reset socket.data
|
|
41
41
|
* If not, do nothing. If needed, an application-level hook may automatically extend the expiration data at each service call
|
|
42
42
|
*/
|
|
43
43
|
export const isNotExpired = async (context) => {
|
|
44
|
-
|
|
45
|
-
if (context.caller !== 'client' || context.transport !== 'ws') return
|
|
44
|
+
if (context.caller !== 'client') return
|
|
46
45
|
|
|
47
46
|
const expireAt = context.socket.data.expireAt
|
|
48
47
|
if (expireAt) {
|
package/src/server.mjs
CHANGED
|
@@ -253,6 +253,12 @@ export function expressX(config) {
|
|
|
253
253
|
socket.leave(channelName)
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
// There is a need for events sent outside any service method call, for example on unsolicited-by-frontend backend state change
|
|
257
|
+
async function sendAppEvent(channelName, type, value) {
|
|
258
|
+
console.log('sendAppEvent', channelName, type, value)
|
|
259
|
+
io.to(channelName).emit('app-event', { type, value })
|
|
260
|
+
}
|
|
261
|
+
|
|
256
262
|
// enhance `app` with objects and methods
|
|
257
263
|
return Object.assign(app, {
|
|
258
264
|
io,
|
|
@@ -263,6 +269,7 @@ export function expressX(config) {
|
|
|
263
269
|
hooks,
|
|
264
270
|
joinChannel,
|
|
265
271
|
leaveChannel,
|
|
272
|
+
sendAppEvent,
|
|
266
273
|
})
|
|
267
274
|
|
|
268
275
|
}
|