(key: string, content: any)
| 43 | } |
| 44 | |
| 45 | async publish(key: string, content: any) { |
| 46 | const sessionID = await this.getSessionID() |
| 47 | if ( |
| 48 | !key.startsWith(`session/info/${sessionID}`) && |
| 49 | !key.startsWith(`session/message/${sessionID}/`) && |
| 50 | !key.startsWith(`session/part/${sessionID}/`) |
| 51 | ) |
| 52 | return new Response("Error: Invalid key", { status: 400 }) |
| 53 | |
| 54 | // store message |
| 55 | await this.env.Bucket.put(`share/${key}.json`, JSON.stringify(content), { |
| 56 | httpMetadata: { |
| 57 | contentType: "application/json", |
| 58 | }, |
| 59 | }) |
| 60 | await this.ctx.storage.put(key, content) |
| 61 | const clients = this.ctx.getWebSockets() |
| 62 | console.log("SyncServer publish", key, "to", clients.length, "subscribers") |
| 63 | for (const client of clients) { |
| 64 | client.send(JSON.stringify({ key, content })) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public async share(sessionID: string) { |
| 69 | let secret = await this.getSecret() |
no test coverage detected