@dtudury/streamo 0.1.1 → 0.2.0
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/.claude/settings.json +1 -0
- package/.claude/settings.local.json +5 -1
- package/.env.dev +4 -0
- package/CLAUDE.md +73 -0
- package/README.md +45 -23
- package/ROADMAP.md +85 -50
- package/bin/streamo.js +33 -44
- package/jsconfig.json +3 -2
- package/package.json +4 -3
- package/public/apps/chat/main.js +70 -87
- package/public/apps/chat/server.js +35 -0
- package/public/streamo/Repo.js +39 -1
- package/public/streamo/StreamoComponent.js +92 -0
- package/public/streamo/StreamoServer.js +71 -0
- package/public/streamo/chat-cli.js +4 -3
- package/public/streamo/mount.js +69 -20
- package/public/streamo/webSync.js +2 -2
- package/public/streamo/chat-server.js +0 -60
- package/scripts/serve.js +0 -15
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* streamo chat server
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node public/streamo/chat-server.js [port]
|
|
7
|
-
*
|
|
8
|
-
* Starts an HTTP + WebSocket server. Auto-accepts any participant that
|
|
9
|
-
* announces their repo key to the root chat topic.
|
|
10
|
-
*
|
|
11
|
-
* The root key is printed on startup — pass it to clients via the
|
|
12
|
-
* /api/chat-info endpoint or by copying it into the config.
|
|
13
|
-
*/
|
|
14
|
-
import { createServer } from 'http'
|
|
15
|
-
import { WebSocketServer } from 'ws'
|
|
16
|
-
import { fileURLToPath } from 'url'
|
|
17
|
-
import { join, dirname } from 'path'
|
|
18
|
-
import express from 'express'
|
|
19
|
-
import { Signer } from './Signer.js'
|
|
20
|
-
import { RepoRegistry } from './RepoRegistry.js'
|
|
21
|
-
import { attachStreamSync } from './outletSync.js'
|
|
22
|
-
import { bytesToHex } from './utils.js'
|
|
23
|
-
|
|
24
|
-
const port = Number(process.argv[2] ?? process.env.PORT ?? 8080)
|
|
25
|
-
const __dir = dirname(fileURLToPath(import.meta.url))
|
|
26
|
-
|
|
27
|
-
// Derive a stable, well-known root key for this chat room.
|
|
28
|
-
// Using 1 PBKDF2 iteration so startup is instant; this is fine for a demo.
|
|
29
|
-
const rootSigner = new Signer('streamo-chat-room', 'streamo-chat', 1)
|
|
30
|
-
const { publicKey: rootPubKey } = await rootSigner.keysFor('v1')
|
|
31
|
-
const ROOT_KEY = bytesToHex(rootPubKey)
|
|
32
|
-
|
|
33
|
-
const registry = new RepoRegistry()
|
|
34
|
-
const rootRepo = await registry.open(ROOT_KEY)
|
|
35
|
-
if (!rootRepo.get('members')) rootRepo.set({ name: 'chat-root', members: [] })
|
|
36
|
-
|
|
37
|
-
// Auto-accept: when a client announces their key to the root topic, add them.
|
|
38
|
-
function onAnnounce (key, topic) {
|
|
39
|
-
if (topic !== ROOT_KEY) return
|
|
40
|
-
const members = rootRepo.get('members') ?? []
|
|
41
|
-
if (!members.includes(key)) {
|
|
42
|
-
rootRepo.set({ name: 'chat-root', members: [...members, key] })
|
|
43
|
-
console.log(`[chat] new member: ${key.slice(0, 12)}…`)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const app = express()
|
|
48
|
-
app.use(express.static(join(__dir, '../../apps/chat')))
|
|
49
|
-
// Also serve public/streamo/ so the browser can import streamo modules
|
|
50
|
-
app.use('/streamo', express.static(__dir))
|
|
51
|
-
app.get('/api/chat-info', (_req, res) => res.json({ rootKey: ROOT_KEY }))
|
|
52
|
-
|
|
53
|
-
const server = createServer(app)
|
|
54
|
-
const wss = new WebSocketServer({ server })
|
|
55
|
-
attachStreamSync(wss, registry, 'chat', { onAnnounce })
|
|
56
|
-
|
|
57
|
-
server.listen(port, () => {
|
|
58
|
-
console.log(`chat server → http://localhost:${port}`)
|
|
59
|
-
console.log(`root key → ${ROOT_KEY}`)
|
|
60
|
-
})
|
package/scripts/serve.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Serve public/ as a static site.
|
|
4
|
-
* Usage: node scripts/serve.js [port]
|
|
5
|
-
*/
|
|
6
|
-
import express from 'express'
|
|
7
|
-
import { fileURLToPath } from 'url'
|
|
8
|
-
import { join, dirname } from 'path'
|
|
9
|
-
|
|
10
|
-
const port = Number(process.argv[2] ?? process.env.PORT ?? 3000)
|
|
11
|
-
const root = join(dirname(fileURLToPath(import.meta.url)), '../public')
|
|
12
|
-
|
|
13
|
-
const app = express()
|
|
14
|
-
app.use(express.static(root))
|
|
15
|
-
app.listen(port, () => console.log(`http://localhost:${port}`))
|