@laplace.live/event-bridge-server 0.3.1 → 0.3.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/CHANGELOG.md +6 -0
- package/index.ts +11 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { parseArgs } from 'util'
|
|
1
|
+
import { parseArgs } from 'node:util'
|
|
2
2
|
import type { LaplaceEvent } from '@laplace.live/event-types'
|
|
3
3
|
|
|
4
|
+
import pkg from './package.json' with { type: 'json' }
|
|
5
|
+
|
|
4
6
|
// Parse command line arguments properly
|
|
5
7
|
const { values } = parseArgs({
|
|
6
8
|
args: Bun.argv,
|
|
@@ -19,13 +21,13 @@ const { values } = parseArgs({
|
|
|
19
21
|
})
|
|
20
22
|
|
|
21
23
|
// Get authentication token from environment variable or CLI
|
|
22
|
-
const AUTH_TOKEN = process.env
|
|
24
|
+
const AUTH_TOKEN = process.env.LEB_AUTH || process.env.LAPLACE_EVENT_BRIDGE_AUTH || values.auth || ''
|
|
23
25
|
|
|
24
26
|
// Debug mode configuration
|
|
25
|
-
const DEBUG_MODE = process.env
|
|
27
|
+
const DEBUG_MODE = process.env.DEBUG === '1' || process.env.DEBUG?.toLowerCase() === 'true' || !!values.debug
|
|
26
28
|
|
|
27
29
|
// Network interface configuration
|
|
28
|
-
const HOST = process.env
|
|
30
|
+
const HOST = process.env.HOST || (values.host as string) || 'localhost'
|
|
29
31
|
|
|
30
32
|
interface Client {
|
|
31
33
|
id: string
|
|
@@ -83,7 +85,8 @@ const server = Bun.serve<Client, {}>({
|
|
|
83
85
|
type: 'established',
|
|
84
86
|
clientId,
|
|
85
87
|
isServer,
|
|
86
|
-
|
|
88
|
+
version: pkg.version,
|
|
89
|
+
message: 'Connected to LAPLACE Event Bridge',
|
|
87
90
|
})
|
|
88
91
|
)
|
|
89
92
|
},
|
|
@@ -94,7 +97,7 @@ const server = Bun.serve<Client, {}>({
|
|
|
94
97
|
try {
|
|
95
98
|
const messageStr = message.toString()
|
|
96
99
|
let parsedMessage: LaplaceEvent
|
|
97
|
-
let broadcastMessage
|
|
100
|
+
let broadcastMessage: unknown
|
|
98
101
|
|
|
99
102
|
try {
|
|
100
103
|
// Try to parse as JSON
|
|
@@ -111,7 +114,7 @@ const server = Bun.serve<Client, {}>({
|
|
|
111
114
|
...parsedMessage,
|
|
112
115
|
source: clientId,
|
|
113
116
|
})
|
|
114
|
-
} catch
|
|
117
|
+
} catch {
|
|
115
118
|
// Handle as plain text if not JSON
|
|
116
119
|
console.log(`Received message from ${clientId}: ${messageStr}`)
|
|
117
120
|
|
|
@@ -131,7 +134,7 @@ const server = Bun.serve<Client, {}>({
|
|
|
131
134
|
// console.log(`Broadcasting message from laplace-chat to all clients`)
|
|
132
135
|
|
|
133
136
|
// Broadcast to all clients except the server
|
|
134
|
-
for (const [client,
|
|
137
|
+
for (const [client, _data] of clients.entries()) {
|
|
135
138
|
if (client !== ws) {
|
|
136
139
|
client.send(broadcastMessage)
|
|
137
140
|
}
|