tangled
alpha
login
or
join now
accidental.cc
/
skypod
3
fork
atom
podcast manager
3
fork
atom
overview
issues
pulls
pipelines
cleanups
Jonathan Raphaelson
4 months ago
2d4988e6
16000440
+53
-41
9 changed files
expand all
collapse all
unified
split
src
client
page-app.tsx
skypod
context.tsx
middleware-feeds.ts
common
socket.ts
realm
client
connection-manager.tsx
service-connection-peer.ts
service-connection.ts
server
handler-realm.ts
state-storage.ts
+1
-1
src/client/page-app.tsx
···
1
1
import {DatabaseProvider} from '#client/root/context-database'
2
2
import {SkypodProvider} from '#client/skypod/context'
3
3
-
import {RealmConnectionManager} from '#realm/client/cmpnt-connection-manager'
3
3
+
import {RealmConnectionManager} from '#realm/client/connection-manager'
4
4
import {
5
5
RealmConnectionFallbackProps,
6
6
RealmConnectionProvider,
+3
-31
src/client/skypod/context.tsx
···
12
12
13
13
import {LogicalClock} from '#realm/protocol/logical-clock'
14
14
import FeedFetchWorker from './feed-fetch.worker?worker'
15
15
+
import {createFeedMiddleware} from './middleware-feeds'
15
16
16
17
export type MiddlewareFn = (
17
18
this: undefined,
···
48
49
49
50
const processor = useRef<Worker>(null)
50
51
51
51
-
// initial middleware
52
52
-
// TODO: import from elsewhere
53
53
-
const middleware = useRef<Middleware[]>([
54
54
-
{
55
55
-
'feed:add': async (action) => {
56
56
-
await db.feeds.add({
57
57
-
url: action.dat.url,
58
58
-
tags: [],
59
59
-
lock: action.dat.lock || null,
60
60
-
private: action.dat.private,
61
61
-
lastRefresh: {
62
62
-
hp: 100,
63
63
-
at: action.clk,
64
64
-
status: 'pending',
65
65
-
httpEtag: null,
66
66
-
httpStatus: null,
67
67
-
},
68
68
-
})
69
69
-
70
70
-
processor.current?.postMessage({msg: 'poll'})
71
71
-
},
72
72
-
73
73
-
'feed:remove': async (action) => {
74
74
-
await db.feeds.delete({url: action.dat.url})
75
75
-
},
76
76
-
77
77
-
'feed:patch': async (action) => {
78
78
-
await db.feeds.update(action.dat.url, action.dat.payload)
79
79
-
},
80
80
-
},
81
81
-
])
52
52
+
// Initial middleware - feed management
53
53
+
const middleware = useRef<Middleware[]>([createFeedMiddleware(db, processor.current)])
82
54
83
55
const context = useRef<SkypodContext>({
84
56
dispatch: async <K extends keyof ActionMap>(action: ActionMap[K]) => {
+40
src/client/skypod/middleware-feeds.ts
···
1
1
+
import {Database} from '#client/root/service-database'
2
2
+
import {Middleware} from './context'
3
3
+
4
4
+
/**
5
5
+
* Feed management middleware
6
6
+
*
7
7
+
* Handles feed lifecycle actions:
8
8
+
* - feed:add - Creates feed record and triggers fetch
9
9
+
* - feed:remove - Deletes feed from database
10
10
+
* - feed:patch - Updates feed metadata
11
11
+
*/
12
12
+
export function createFeedMiddleware(db: Database, worker: Worker | null): Middleware {
13
13
+
return {
14
14
+
'feed:add': async (action) => {
15
15
+
await db.feeds.add({
16
16
+
url: action.dat.url,
17
17
+
tags: [],
18
18
+
lock: action.dat.lock || null,
19
19
+
private: action.dat.private,
20
20
+
lastRefresh: {
21
21
+
hp: 100,
22
22
+
at: action.clk,
23
23
+
status: 'pending',
24
24
+
httpEtag: null,
25
25
+
httpStatus: null,
26
26
+
},
27
27
+
})
28
28
+
29
29
+
worker?.postMessage({msg: 'poll'})
30
30
+
},
31
31
+
32
32
+
'feed:remove': async (action) => {
33
33
+
await db.feeds.delete({url: action.dat.url})
34
34
+
},
35
35
+
36
36
+
'feed:patch': async (action) => {
37
37
+
await db.feeds.update(action.dat.url, action.dat.payload)
38
38
+
},
39
39
+
}
40
40
+
}
+1
-1
src/common/socket.ts
···
166
166
// TODO: eslint thinks inBackoffMode is always falsey...
167
167
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
168
168
if (inBackoffMode && queue.depth < backoffThresh) {
169
169
-
console.log('message stream will stop dropping messages due to eased backpressure')
169
169
+
console.debug('message stream will stop dropping messages due to eased backpressure')
170
170
inBackoffMode = false
171
171
}
172
172
+2
-2
src/realm/client/cmpnt-connection-manager.tsx
src/realm/client/connection-manager.tsx
···
15
15
16
16
const invitation = useSignal<string>()
17
17
const register = useCallback(() => {
18
18
-
console.log('register')
18
18
+
console.debug('register realm')
19
19
connection.connectopts.value = {
20
20
realmid: RealmBrand.generate(),
21
21
register: true,
···
23
23
}, [connection.connectopts])
24
24
25
25
const exchange = useCallback(() => {
26
26
-
console.log('exchange', invitation.value)
26
26
+
console.debug('exchange invitation:', invitation.value)
27
27
jwtSchema
28
28
.parseAsync(invitation.value)
29
29
.then((token) => {
+1
-1
src/realm/client/service-connection-peer.ts
···
99
99
}
100
100
101
101
#aborted = () => {
102
102
-
console.log('peer connected aborted...', this.identid)
102
102
+
console.debug('peer connection aborted:', this.identid)
103
103
104
104
// stop listeners; loops were stopped by the abort signal
105
105
this.off('data', this.#receive)
+2
-2
src/realm/client/service-connection.ts
···
130
130
}
131
131
132
132
destroy() {
133
133
-
console.log('realm connection destroy!')
133
133
+
console.debug('realm connection destroy!')
134
134
if (this.connected) {
135
135
this.#socket.close()
136
136
}
···
242
242
continue
243
243
}
244
244
245
245
-
console.log('connecting to peer...:', peerid)
245
245
+
console.debug('connecting to peer...:', peerid)
246
246
this.#connectPeer(peerid, true)
247
247
}
248
248
+2
-2
src/realm/server/handler-realm.ts
···
134
134
auth: realm.AuthenticatedIdentity,
135
135
ping: protocol.RealmRtcPingRequest,
136
136
) {
137
137
-
console.log('ping from', auth.identid, ping.dat)
137
137
+
console.debug('ping from', auth.identid, ping.dat)
138
138
139
139
const peerClocks = await auth.realm.storage.buildSyncState()
140
140
const response: protocol.RealmRtcPongResponse = {
···
159
159
auth: realm.AuthenticatedIdentity,
160
160
announce: protocol.RealmRtcAnnounceRequest,
161
161
) {
162
162
-
console.log('announce from', auth.identid, announce.dat)
162
162
+
console.debug('announce from', auth.identid, announce.dat)
163
163
164
164
auth.deviceCaps = announce.dat.deviceCaps
165
165
auth.deviceInfo = announce.dat.deviceInfo
+1
-1
src/realm/server/state-storage.ts
···
69
69
// expect to raise if the file doesn't exist
70
70
const content = await fs.readFile(metapath, 'utf-8')
71
71
const metadata = realmMetadataSchema.parse(JSON.parse(content))
72
72
-
console.log(`loaded realm metadata: ${realmid}`)
72
72
+
console.debug(`loaded realm metadata: ${realmid}`)
73
73
74
74
// import identities
75
75
const identities = new StrictMap<IdentID, CryptoKey>()