pubblue 0.5.0 → 0.6.1

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.
@@ -1,114 +0,0 @@
1
- // ../shared/bridge-protocol-core.ts
2
- var CONTROL_CHANNEL = "_control";
3
- var CHANNELS = {
4
- CHAT: "chat",
5
- CANVAS: "canvas",
6
- AUDIO: "audio",
7
- MEDIA: "media",
8
- FILE: "file"
9
- };
10
- var idCounter = 0;
11
- function generateMessageId() {
12
- const ts = Date.now().toString(36);
13
- const seq = (idCounter++).toString(36);
14
- const rand = Math.random().toString(36).slice(2, 6);
15
- return `${ts}-${seq}-${rand}`;
16
- }
17
- function encodeMessage(msg) {
18
- return JSON.stringify(msg);
19
- }
20
- function decodeMessage(raw) {
21
- try {
22
- const parsed = JSON.parse(raw);
23
- if (parsed && typeof parsed.id === "string" && typeof parsed.type === "string") {
24
- return parsed;
25
- }
26
- return null;
27
- } catch {
28
- return null;
29
- }
30
- }
31
- function makeEventMessage(event, meta) {
32
- return { id: generateMessageId(), type: "event", data: event, meta };
33
- }
34
- function makeAckMessage(messageId, channel) {
35
- return makeEventMessage("ack", { messageId, channel, receivedAt: Date.now() });
36
- }
37
- function parseAckMessage(msg) {
38
- if (msg.type !== "event" || msg.data !== "ack" || !msg.meta) return null;
39
- const messageId = typeof msg.meta.messageId === "string" ? msg.meta.messageId : null;
40
- const channel = typeof msg.meta.channel === "string" ? msg.meta.channel : null;
41
- if (!messageId || !channel) return null;
42
- const receivedAt = typeof msg.meta.receivedAt === "number" ? msg.meta.receivedAt : void 0;
43
- return { messageId, channel, receivedAt };
44
- }
45
- function shouldAcknowledgeMessage(channel, msg) {
46
- return channel !== CONTROL_CHANNEL && parseAckMessage(msg) === null;
47
- }
48
- var MAX_TUNNEL_EXPIRY_MS = 7 * 24 * 60 * 60 * 1e3;
49
- var DEFAULT_TUNNEL_EXPIRY_MS = 24 * 60 * 60 * 1e3;
50
-
51
- // src/lib/tunnel-ipc.ts
52
- import * as net from "net";
53
- function getSocketPath(slug) {
54
- return `/tmp/pubblue-${slug}.sock`;
55
- }
56
- async function ipcCall(socketPath, request) {
57
- return new Promise((resolve, reject) => {
58
- let settled = false;
59
- let timeoutId = null;
60
- const finish = (fn) => {
61
- if (settled) return;
62
- settled = true;
63
- if (timeoutId) clearTimeout(timeoutId);
64
- fn();
65
- };
66
- const client = net.createConnection(socketPath, () => {
67
- client.write(`${JSON.stringify(request)}
68
- `);
69
- });
70
- let data = "";
71
- client.on("data", (chunk) => {
72
- data += chunk.toString();
73
- const newlineIdx = data.indexOf("\n");
74
- if (newlineIdx !== -1) {
75
- const line = data.slice(0, newlineIdx);
76
- client.end();
77
- try {
78
- finish(() => resolve(JSON.parse(line)));
79
- } catch {
80
- finish(() => reject(new Error("Invalid response from daemon")));
81
- }
82
- }
83
- });
84
- client.on("error", (err) => {
85
- if (err.code === "ECONNREFUSED" || err.code === "ENOENT") {
86
- finish(() => reject(new Error("Daemon not running. Is the tunnel still active?")));
87
- } else {
88
- finish(() => reject(err));
89
- }
90
- });
91
- client.on("end", () => {
92
- if (!data.includes("\n")) {
93
- finish(() => reject(new Error("Daemon closed connection unexpectedly")));
94
- }
95
- });
96
- timeoutId = setTimeout(() => {
97
- client.destroy();
98
- finish(() => reject(new Error("Daemon request timed out")));
99
- }, 1e4);
100
- });
101
- }
102
-
103
- export {
104
- CONTROL_CHANNEL,
105
- CHANNELS,
106
- generateMessageId,
107
- encodeMessage,
108
- decodeMessage,
109
- makeAckMessage,
110
- parseAckMessage,
111
- shouldAcknowledgeMessage,
112
- getSocketPath,
113
- ipcCall
114
- };
@@ -1,2 +0,0 @@
1
-
2
- export { }