@jcbuisson/express-x 1.5.33 → 1.5.35
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/server.mjs +8 -4
package/package.json
CHANGED
package/src/server.mjs
CHANGED
|
@@ -9,7 +9,6 @@ import express from 'express'
|
|
|
9
9
|
export function expressX(prisma, options = {}) {
|
|
10
10
|
|
|
11
11
|
const app = express()
|
|
12
|
-
// app.set('prisma', prisma)
|
|
13
12
|
|
|
14
13
|
if (options.ws === undefined) options.ws = { ws_prefix: "expressx" }
|
|
15
14
|
|
|
@@ -114,18 +113,20 @@ export function expressX(prisma, options = {}) {
|
|
|
114
113
|
if (publishFunc) {
|
|
115
114
|
const channelNames = await publishFunc(result, app)
|
|
116
115
|
app.log('verbose', `publish channels ${service.name} ${methodName} ${channelNames}`)
|
|
116
|
+
const connections = await app.prisma.Connection.findMany({})
|
|
117
|
+
console.log('connections', connections)
|
|
117
118
|
for (const channelName of channelNames) {
|
|
118
119
|
app.log('verbose', `service-event ${service.name} ${methodName} ${channelName}`)
|
|
119
|
-
const connections = await app.prisma.Connection.findMany({})
|
|
120
120
|
const connectionList = connections.filter(connection => {
|
|
121
121
|
const channelNames = JSON.parse(connection.channelNames)
|
|
122
122
|
return channelNames.includes(channelName)
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
for (const connection of connectionList) {
|
|
126
|
-
const trimmedResult = JSON.stringify(result).slice(0, 300)
|
|
126
|
+
const trimmedResult = result ? JSON.stringify(result).slice(0, 300) : ''
|
|
127
127
|
app.log('verbose', `emit to ${connection.id} ${service.name} ${methodName} ${trimmedResult}`)
|
|
128
128
|
const socket = cnx2Socket[connection.id]
|
|
129
|
+
console.log()
|
|
129
130
|
if (!socket) {
|
|
130
131
|
continue // SHOULD NOT HAPPEN
|
|
131
132
|
}
|
|
@@ -313,6 +314,7 @@ export function expressX(prisma, options = {}) {
|
|
|
313
314
|
cnx2Socket[connection.id] = socket
|
|
314
315
|
|
|
315
316
|
// emit 'connection' event for app (expressjs extends EventEmitter)
|
|
317
|
+
console.log('EMIT CONNECTION')
|
|
316
318
|
app.emit('connection', connection)
|
|
317
319
|
|
|
318
320
|
// send 'connected' event to client
|
|
@@ -365,7 +367,7 @@ export function expressX(prisma, options = {}) {
|
|
|
365
367
|
|
|
366
368
|
try {
|
|
367
369
|
const result = await serviceMethod(context, ...args)
|
|
368
|
-
const trimmedResult = JSON.stringify(result).slice(0, 300)
|
|
370
|
+
const trimmedResult = result ? JSON.stringify(result).slice(0, 300) : ''
|
|
369
371
|
app.log('verbose', `client-response ${uid} ${trimmedResult}`)
|
|
370
372
|
socket.emit('client-response', {
|
|
371
373
|
uid,
|
|
@@ -401,6 +403,7 @@ export function expressX(prisma, options = {}) {
|
|
|
401
403
|
}
|
|
402
404
|
|
|
403
405
|
async function joinChannel(channelName, connection) {
|
|
406
|
+
app.log('verbose', `Joining channel ${channelName} ${connection.id}`)
|
|
404
407
|
const channelNames = JSON.parse(connection.channelNames)
|
|
405
408
|
if (!channelNames.includes(channelName)) channelNames.push(channelName)
|
|
406
409
|
await app.prisma.Connection.update({
|
|
@@ -410,6 +413,7 @@ export function expressX(prisma, options = {}) {
|
|
|
410
413
|
}
|
|
411
414
|
|
|
412
415
|
async function leaveChannel(channelName, connection) {
|
|
416
|
+
app.log('verbose', `Leaving channel ${channelName} ${connection.id}`)
|
|
413
417
|
const channelNames = JSON.parse(connection.channelNames).filter(name => name !== channelName)
|
|
414
418
|
await app.prisma.Connection.update({
|
|
415
419
|
where: { id },
|