@jcbuisson/express-x 1.5.14 → 1.5.15

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.5.14",
3
+ "version": "1.5.15",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/server.mjs CHANGED
@@ -19,15 +19,16 @@ export function expressX(prisma, options = {}) {
19
19
 
20
20
  const cnx2Socket = {}
21
21
 
22
- function createConnection(clientIP) {
22
+ async function createConnection(clientIP) {
23
23
  const now = new Date();
24
24
  const expirationTime = new Date(now.getTime() + 15 * 60000)
25
- return app.service('Connection').create({
25
+ const connection = await app.service('Connection').create({
26
26
  data: {
27
27
  clientIP,
28
28
  expirationTime,
29
29
  }
30
30
  })
31
+ return connection
31
32
  }
32
33
 
33
34
  function getConnection(id) {
@@ -38,8 +39,10 @@ export function expressX(prisma, options = {}) {
38
39
  await app.service('Connection').update({
39
40
  where: { id },
40
41
  data: {
42
+ clientIP: connection.clientIP,
41
43
  channelNames: connection.channelNames,
42
44
  data: connection.data,
45
+ expirationTime: connection.expirationTime,
43
46
  }
44
47
  })
45
48
  }
@@ -401,6 +404,31 @@ export function expressX(prisma, options = {}) {
401
404
  }
402
405
  }
403
406
 
407
+ async function getChannelConnections(channelName) {
408
+ const connections = await app.service('Connection').findMany({})
409
+ return connections.filter(connection => {
410
+ const channelNames = JSON.parse(connection.channelNames)
411
+ return channelNames.includes(channelName)
412
+ })
413
+ }
414
+
415
+ async function addChannelToConnection(connection, channelName) {
416
+ const channelNames = JSON.parse(connection.channelNames)
417
+ if (!channelNames.includes(channelName)) channelNames.push(channelName)
418
+ await app.service('Connection').update({
419
+ where: { id: connection.id },
420
+ data: { channelNames: JSON.stringify(channelNames) },
421
+ })
422
+ }
423
+
424
+ async function removeChannelFromConnection(connection, channelName) {
425
+ const channelNames = JSON.parse(connection.channelNames).filter(name => name !== channelName)
426
+ await app.service('Connection').update({
427
+ where: { id },
428
+ data: { channelNames: JSON.stringify(channelNames) },
429
+ })
430
+ }
431
+
404
432
  function joinChannel(channelName, connection) {
405
433
  addChannelToConnection(connection, channelName)
406
434
  }
package/src/channels.mjs DELETED
@@ -1,25 +0,0 @@
1
-
2
- export async function getChannelConnections(channelName) {
3
- const connections = await app.service('Connection').findMany({})
4
- return connections.filter(connection => {
5
- const channelNames = JSON.parse(connection.channelNames)
6
- return channelNames.includes(channelName)
7
- })
8
- }
9
-
10
- export async function addChannelToConnection(connection, channelName) {
11
- const channelNames = JSON.parse(connection.channelNames)
12
- if (!channelNames.includes(channelName)) channelNames.push(channelName)
13
- await app.service('Connection').update({
14
- where: { id: connection.id },
15
- data: { channelNames: JSON.stringify(channelNames) },
16
- })
17
- }
18
-
19
- export async function removeChannelFromConnection(connection, channelName) {
20
- const channelNames = JSON.parse(connection.channelNames).filter(name => name !== channelName)
21
- await app.service('Connection').update({
22
- where: { id },
23
- data: { channelNames: JSON.stringify(channelNames) },
24
- })
25
- }