bitchat-node 0.1.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/README.md +223 -0
- package/dist/bin/bitchat.d.ts +7 -0
- package/dist/bin/bitchat.d.ts.map +1 -0
- package/dist/bin/bitchat.js +69 -0
- package/dist/bin/bitchat.js.map +1 -0
- package/dist/client.d.ts +77 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +411 -0
- package/dist/client.js.map +1 -0
- package/dist/crypto/index.d.ts +6 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +6 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/noise.d.ts +72 -0
- package/dist/crypto/noise.d.ts.map +1 -0
- package/dist/crypto/noise.js +470 -0
- package/dist/crypto/noise.js.map +1 -0
- package/dist/crypto/signing.d.ts +34 -0
- package/dist/crypto/signing.d.ts.map +1 -0
- package/dist/crypto/signing.js +56 -0
- package/dist/crypto/signing.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/mesh/deduplicator.d.ts +48 -0
- package/dist/mesh/deduplicator.d.ts.map +1 -0
- package/dist/mesh/deduplicator.js +107 -0
- package/dist/mesh/deduplicator.js.map +1 -0
- package/dist/mesh/index.d.ts +6 -0
- package/dist/mesh/index.d.ts.map +1 -0
- package/dist/mesh/index.js +6 -0
- package/dist/mesh/index.js.map +1 -0
- package/dist/mesh/router.d.ts +90 -0
- package/dist/mesh/router.d.ts.map +1 -0
- package/dist/mesh/router.js +204 -0
- package/dist/mesh/router.js.map +1 -0
- package/dist/protocol/binary.d.ts +37 -0
- package/dist/protocol/binary.d.ts.map +1 -0
- package/dist/protocol/binary.js +310 -0
- package/dist/protocol/binary.js.map +1 -0
- package/dist/protocol/constants.d.ts +30 -0
- package/dist/protocol/constants.d.ts.map +1 -0
- package/dist/protocol/constants.js +37 -0
- package/dist/protocol/constants.js.map +1 -0
- package/dist/protocol/index.d.ts +8 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +8 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/packets.d.ts +38 -0
- package/dist/protocol/packets.d.ts.map +1 -0
- package/dist/protocol/packets.js +177 -0
- package/dist/protocol/packets.js.map +1 -0
- package/dist/protocol/types.d.ts +134 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +108 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +113 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +371 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/transport/ble.d.ts +92 -0
- package/dist/transport/ble.d.ts.map +1 -0
- package/dist/transport/ble.js +434 -0
- package/dist/transport/ble.js.map +1 -0
- package/dist/transport/index.d.ts +5 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +2 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/server.d.ts +16 -0
- package/dist/ui/server.d.ts.map +1 -0
- package/dist/ui/server.js +510 -0
- package/dist/ui/server.js.map +1 -0
- package/package.json +79 -0
- package/src/bin/bitchat.ts +87 -0
- package/src/client.ts +519 -0
- package/src/crypto/index.ts +22 -0
- package/src/crypto/noise.ts +574 -0
- package/src/crypto/signing.ts +66 -0
- package/src/index.ts +95 -0
- package/src/mesh/deduplicator.ts +129 -0
- package/src/mesh/index.ts +6 -0
- package/src/mesh/router.ts +258 -0
- package/src/protocol/binary.ts +345 -0
- package/src/protocol/constants.ts +43 -0
- package/src/protocol/index.ts +15 -0
- package/src/protocol/packets.ts +223 -0
- package/src/protocol/types.ts +182 -0
- package/src/session/index.ts +9 -0
- package/src/session/manager.ts +476 -0
- package/src/transport/ble.ts +553 -0
- package/src/transport/index.ts +10 -0
- package/src/ui/index.ts +1 -0
- package/src/ui/server.ts +569 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BLE Transport
|
|
3
|
+
* Handles Bluetooth Low Energy communication for Bitchat mesh
|
|
4
|
+
*
|
|
5
|
+
* Uses noble for central mode (scanning/connecting) and
|
|
6
|
+
* bleno for peripheral mode (advertising/accepting)
|
|
7
|
+
*/
|
|
8
|
+
import { EventEmitter } from 'node:events';
|
|
9
|
+
import { BLE_MAX_MTU, CHARACTERISTIC_UUID, SERVICE_UUID, SERVICE_UUID_TESTNET, } from '../protocol/constants.js';
|
|
10
|
+
const DEFAULT_CONFIG = {
|
|
11
|
+
serviceUUID: SERVICE_UUID,
|
|
12
|
+
characteristicUUID: CHARACTERISTIC_UUID,
|
|
13
|
+
testnet: false,
|
|
14
|
+
enableCentral: true,
|
|
15
|
+
enablePeripheral: true,
|
|
16
|
+
scanDuplicates: true, // Enable to allow reconnection attempts
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* BLE link implementation
|
|
20
|
+
*/
|
|
21
|
+
export class BLELink {
|
|
22
|
+
id;
|
|
23
|
+
peripheral;
|
|
24
|
+
characteristic;
|
|
25
|
+
_peerID;
|
|
26
|
+
mtu;
|
|
27
|
+
constructor(peripheral, characteristic, mtu = BLE_MAX_MTU) {
|
|
28
|
+
this.id = peripheral.uuid;
|
|
29
|
+
this.peripheral = peripheral;
|
|
30
|
+
this.characteristic = characteristic;
|
|
31
|
+
this.mtu = mtu;
|
|
32
|
+
}
|
|
33
|
+
get peerID() {
|
|
34
|
+
return this._peerID;
|
|
35
|
+
}
|
|
36
|
+
setPeerID(peerID) {
|
|
37
|
+
this._peerID = peerID;
|
|
38
|
+
}
|
|
39
|
+
async send(data) {
|
|
40
|
+
// Fragment if necessary
|
|
41
|
+
if (data.length > this.mtu) {
|
|
42
|
+
// TODO: Implement fragmentation
|
|
43
|
+
throw new Error('Message too large for MTU, fragmentation not yet implemented');
|
|
44
|
+
}
|
|
45
|
+
console.log('[BLE] Sending', data.length, 'bytes to', this.id);
|
|
46
|
+
console.log('[BLE] First 50 bytes:', Buffer.from(data.slice(0, 50)).toString('hex'));
|
|
47
|
+
console.log('[BLE] Last 20 bytes:', Buffer.from(data.slice(-20)).toString('hex'));
|
|
48
|
+
const buf = Buffer.from(data);
|
|
49
|
+
console.log('[BLE] Buffer check - is Buffer:', Buffer.isBuffer(buf), 'length:', buf.length);
|
|
50
|
+
// Try write WITHOUT response (withoutResponse = true)
|
|
51
|
+
// This uses a different BLE write type that might work better
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
this.characteristic.write(buf, true, (error) => {
|
|
54
|
+
if (error) {
|
|
55
|
+
console.error('[BLE] Send error:', error);
|
|
56
|
+
reject(error);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log('[BLE] Send success (without response)');
|
|
60
|
+
resolve();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
get isConnected() {
|
|
66
|
+
return this.peripheral.state === 'connected';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* BLE Transport - handles Bluetooth mesh networking
|
|
71
|
+
*/
|
|
72
|
+
export class BLETransport extends EventEmitter {
|
|
73
|
+
config;
|
|
74
|
+
noble;
|
|
75
|
+
bleno;
|
|
76
|
+
running = false;
|
|
77
|
+
// Connected peripherals (central mode)
|
|
78
|
+
peripherals = new Map();
|
|
79
|
+
links = new Map();
|
|
80
|
+
// Subscribed centrals (peripheral mode)
|
|
81
|
+
subscribedCentrals = new Set();
|
|
82
|
+
notifyCallback;
|
|
83
|
+
constructor(config = {}) {
|
|
84
|
+
super();
|
|
85
|
+
const baseConfig = { ...DEFAULT_CONFIG, ...config };
|
|
86
|
+
// Use testnet UUID if testnet is true and no explicit serviceUUID was provided
|
|
87
|
+
if (baseConfig.testnet && !config.serviceUUID) {
|
|
88
|
+
baseConfig.serviceUUID = SERVICE_UUID_TESTNET;
|
|
89
|
+
}
|
|
90
|
+
this.config = baseConfig;
|
|
91
|
+
console.log('[BLE] Config: testnet =', this.config.testnet, ', serviceUUID =', this.config.serviceUUID);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Start the BLE transport
|
|
95
|
+
*/
|
|
96
|
+
async start() {
|
|
97
|
+
if (this.running)
|
|
98
|
+
return;
|
|
99
|
+
try {
|
|
100
|
+
// Initialize central mode (noble)
|
|
101
|
+
if (this.config.enableCentral) {
|
|
102
|
+
await this.initCentral();
|
|
103
|
+
}
|
|
104
|
+
// Initialize peripheral mode (bleno)
|
|
105
|
+
if (this.config.enablePeripheral) {
|
|
106
|
+
await this.initPeripheral();
|
|
107
|
+
}
|
|
108
|
+
this.running = true;
|
|
109
|
+
this.emit('ready');
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.emit('error', error, 'start');
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Stop the BLE transport
|
|
118
|
+
*/
|
|
119
|
+
async stop() {
|
|
120
|
+
if (!this.running)
|
|
121
|
+
return;
|
|
122
|
+
try {
|
|
123
|
+
// Stop scanning
|
|
124
|
+
if (this.noble) {
|
|
125
|
+
await this.noble.stopScanningAsync();
|
|
126
|
+
}
|
|
127
|
+
// Stop advertising
|
|
128
|
+
if (this.bleno) {
|
|
129
|
+
this.bleno.stopAdvertising();
|
|
130
|
+
}
|
|
131
|
+
// Disconnect all peripherals
|
|
132
|
+
for (const [, conn] of this.peripherals) {
|
|
133
|
+
try {
|
|
134
|
+
await conn.peripheral.disconnectAsync();
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Ignore disconnect errors
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
this.peripherals.clear();
|
|
141
|
+
this.links.clear();
|
|
142
|
+
this.subscribedCentrals.clear();
|
|
143
|
+
this.running = false;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
this.emit('error', error, 'stop');
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get all active links
|
|
152
|
+
*/
|
|
153
|
+
getLinks() {
|
|
154
|
+
return Array.from(this.links.values());
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get link by ID
|
|
158
|
+
*/
|
|
159
|
+
getLink(id) {
|
|
160
|
+
return this.links.get(id);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Broadcast data to all connected peers
|
|
164
|
+
*/
|
|
165
|
+
async broadcast(data) {
|
|
166
|
+
// Send via central mode (noble) links
|
|
167
|
+
const sendPromises = Array.from(this.links.values()).map(async (link) => {
|
|
168
|
+
try {
|
|
169
|
+
await link.send(data);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
this.emit('error', error, `broadcast to ${link.id}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
// Send via peripheral mode (bleno) notifications
|
|
176
|
+
if (this.notifyCallback) {
|
|
177
|
+
try {
|
|
178
|
+
console.log('[BLE] Notifying subscribed centrals,', data.length, 'bytes');
|
|
179
|
+
this.notifyCallback(Buffer.from(data));
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.error('[BLE] Notify error:', error);
|
|
183
|
+
this.emit('error', error, 'notify');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
console.log('[BLE] No notify callback (no centrals subscribed)');
|
|
188
|
+
}
|
|
189
|
+
await Promise.allSettled(sendPromises);
|
|
190
|
+
}
|
|
191
|
+
// --- Central Mode (Noble) ---
|
|
192
|
+
async initCentral() {
|
|
193
|
+
console.log('[BLE] Initializing central mode (noble)...');
|
|
194
|
+
const nobleModule = await import('@abandonware/noble');
|
|
195
|
+
this.noble = nobleModule.default;
|
|
196
|
+
console.log('[BLE] Noble imported, state:', this.noble.state);
|
|
197
|
+
// Wait for powered on
|
|
198
|
+
await this.waitForPoweredOn();
|
|
199
|
+
console.log('[BLE] Noble powered on');
|
|
200
|
+
// Set up event handlers
|
|
201
|
+
this.noble.on('discover', (peripheral) => this.onDiscover(peripheral));
|
|
202
|
+
this.noble.on('stateChange', (state) => this.emit('state', state));
|
|
203
|
+
// Start scanning
|
|
204
|
+
console.log('[BLE] Starting scan for service:', this.config.serviceUUID);
|
|
205
|
+
await this.noble.startScanningAsync([this.config.serviceUUID], this.config.scanDuplicates);
|
|
206
|
+
console.log('[BLE] Scanning started');
|
|
207
|
+
}
|
|
208
|
+
async waitForPoweredOn() {
|
|
209
|
+
if (!this.noble)
|
|
210
|
+
throw new Error('Noble not initialized');
|
|
211
|
+
const noble = this.noble;
|
|
212
|
+
if (noble.state === 'poweredOn')
|
|
213
|
+
return;
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
const timeout = setTimeout(() => {
|
|
216
|
+
reject(new Error('Bluetooth adapter timeout'));
|
|
217
|
+
}, 10000);
|
|
218
|
+
const handler = (state) => {
|
|
219
|
+
if (state === 'poweredOn') {
|
|
220
|
+
clearTimeout(timeout);
|
|
221
|
+
noble.removeListener('stateChange', handler);
|
|
222
|
+
resolve();
|
|
223
|
+
}
|
|
224
|
+
else if (state === 'poweredOff' || state === 'unauthorized') {
|
|
225
|
+
clearTimeout(timeout);
|
|
226
|
+
reject(new Error(`Bluetooth state: ${state}`));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
noble.on('stateChange', handler);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
// Track failed connection attempts for retry logic
|
|
233
|
+
failedConnections = new Map();
|
|
234
|
+
// Track peripherals currently being connected to (prevent duplicate attempts)
|
|
235
|
+
connectingPeripherals = new Set();
|
|
236
|
+
async onDiscover(peripheral) {
|
|
237
|
+
// Skip verbose logging for repeated discoveries
|
|
238
|
+
const isRepeatedDiscovery = this.failedConnections.has(peripheral.uuid) ||
|
|
239
|
+
this.peripherals.has(peripheral.uuid) ||
|
|
240
|
+
this.connectingPeripherals.has(peripheral.uuid);
|
|
241
|
+
if (!isRepeatedDiscovery) {
|
|
242
|
+
console.log('[BLE] Discovered peripheral:', peripheral.uuid, peripheral.advertisement?.localName);
|
|
243
|
+
}
|
|
244
|
+
// Skip if already connected
|
|
245
|
+
if (this.peripherals.has(peripheral.uuid))
|
|
246
|
+
return;
|
|
247
|
+
// Skip if currently connecting (prevents duplicate connect attempts)
|
|
248
|
+
if (this.connectingPeripherals.has(peripheral.uuid))
|
|
249
|
+
return;
|
|
250
|
+
// If we have a working peripheral connection (someone subscribed to us),
|
|
251
|
+
// don't spam central connection attempts - mesh protocol doesn't need bidirectional
|
|
252
|
+
if (this.notifyCallback && this.links.size === 0) {
|
|
253
|
+
// We have a working inbound connection, don't need outbound
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// Check if we've failed too recently
|
|
257
|
+
const failed = this.failedConnections.get(peripheral.uuid);
|
|
258
|
+
if (failed) {
|
|
259
|
+
const backoffMs = Math.min(60000, 2000 * 2 ** failed.count); // Longer backoff
|
|
260
|
+
const elapsed = Date.now() - failed.lastAttempt.getTime();
|
|
261
|
+
if (elapsed < backoffMs) {
|
|
262
|
+
// Don't log every skip - too noisy
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Mark as connecting to prevent duplicate attempts
|
|
267
|
+
this.connectingPeripherals.add(peripheral.uuid);
|
|
268
|
+
try {
|
|
269
|
+
console.log('[BLE] Connecting to', peripheral.uuid);
|
|
270
|
+
await peripheral.connectAsync();
|
|
271
|
+
console.log('[BLE] Connected to', peripheral.uuid);
|
|
272
|
+
// Clear tracking state on success
|
|
273
|
+
this.connectingPeripherals.delete(peripheral.uuid);
|
|
274
|
+
this.failedConnections.delete(peripheral.uuid);
|
|
275
|
+
// Discover services and characteristics
|
|
276
|
+
console.log('[BLE] Discovering services for', peripheral.uuid);
|
|
277
|
+
const { characteristics } = await peripheral.discoverSomeServicesAndCharacteristicsAsync([this.config.serviceUUID], [this.config.characteristicUUID]);
|
|
278
|
+
console.log('[BLE] Found', characteristics.length, 'characteristics');
|
|
279
|
+
if (characteristics.length === 0) {
|
|
280
|
+
console.log('[BLE] No characteristics found, disconnecting');
|
|
281
|
+
await peripheral.disconnectAsync();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const characteristic = characteristics[0];
|
|
285
|
+
// Get MTU
|
|
286
|
+
const mtu = peripheral.mtu ?? BLE_MAX_MTU;
|
|
287
|
+
console.log('[BLE] Peripheral MTU:', peripheral.mtu, '(using:', `${mtu})`);
|
|
288
|
+
// Store connection
|
|
289
|
+
const conn = {
|
|
290
|
+
peripheral,
|
|
291
|
+
characteristic,
|
|
292
|
+
mtu,
|
|
293
|
+
};
|
|
294
|
+
this.peripherals.set(peripheral.uuid, conn);
|
|
295
|
+
// Create link
|
|
296
|
+
const link = new BLELink(peripheral, characteristic, mtu);
|
|
297
|
+
this.links.set(peripheral.uuid, link);
|
|
298
|
+
// Subscribe to notifications
|
|
299
|
+
await characteristic.subscribeAsync();
|
|
300
|
+
characteristic.on('data', (data) => {
|
|
301
|
+
this.emit('data', new Uint8Array(data), link);
|
|
302
|
+
});
|
|
303
|
+
// Handle disconnect
|
|
304
|
+
peripheral.once('disconnect', () => {
|
|
305
|
+
this.onDisconnect(peripheral.uuid);
|
|
306
|
+
});
|
|
307
|
+
this.emit('link:connected', link);
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
// Clear connecting state
|
|
311
|
+
this.connectingPeripherals.delete(peripheral.uuid);
|
|
312
|
+
const err = error;
|
|
313
|
+
// Track failure for retry backoff
|
|
314
|
+
const failed = this.failedConnections.get(peripheral.uuid) ?? {
|
|
315
|
+
count: 0,
|
|
316
|
+
lastAttempt: new Date(),
|
|
317
|
+
};
|
|
318
|
+
failed.count++;
|
|
319
|
+
failed.lastAttempt = new Date();
|
|
320
|
+
this.failedConnections.set(peripheral.uuid, failed);
|
|
321
|
+
// Only log first few failures, then go quiet
|
|
322
|
+
if (failed.count <= 3) {
|
|
323
|
+
console.error('[BLE] Connection failed:', err?.message ?? 'unknown error', `(attempt ${failed.count})`);
|
|
324
|
+
}
|
|
325
|
+
// Try to disconnect if still connected
|
|
326
|
+
try {
|
|
327
|
+
if (peripheral.state === 'connected' || peripheral.state === 'connecting') {
|
|
328
|
+
await peripheral.disconnectAsync();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
catch { }
|
|
332
|
+
// Only emit error for first failure
|
|
333
|
+
if (failed.count === 1) {
|
|
334
|
+
this.emit('error', err ?? new Error('Unknown BLE discover error'), 'discover');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
onDisconnect(peripheralUUID) {
|
|
339
|
+
this.peripherals.delete(peripheralUUID);
|
|
340
|
+
this.links.delete(peripheralUUID);
|
|
341
|
+
this.emit('link:disconnected', peripheralUUID);
|
|
342
|
+
}
|
|
343
|
+
// --- Peripheral Mode (Bleno) ---
|
|
344
|
+
async initPeripheral() {
|
|
345
|
+
try {
|
|
346
|
+
const blenoModule = await import('@abandonware/bleno');
|
|
347
|
+
this.bleno = blenoModule.default;
|
|
348
|
+
// Wait for powered on
|
|
349
|
+
await this.waitForBlenoPoweredOn();
|
|
350
|
+
// Create characteristic
|
|
351
|
+
const CharacteristicClass = this.bleno.Characteristic;
|
|
352
|
+
const characteristic = new CharacteristicClass({
|
|
353
|
+
uuid: this.config.characteristicUUID.replace(/-/g, ''),
|
|
354
|
+
properties: ['read', 'write', 'writeWithoutResponse', 'notify'],
|
|
355
|
+
onWriteRequest: (data, _offset, _withoutResponse, callback) => {
|
|
356
|
+
// Handle incoming data from central
|
|
357
|
+
this.emit('data', new Uint8Array(data), null);
|
|
358
|
+
callback(CharacteristicClass.RESULT_SUCCESS);
|
|
359
|
+
},
|
|
360
|
+
onSubscribe: (_maxValueSize, updateValueCallback) => {
|
|
361
|
+
// Central subscribed to notifications - store callback
|
|
362
|
+
this.notifyCallback = updateValueCallback;
|
|
363
|
+
console.log('Central subscribed to notifications');
|
|
364
|
+
},
|
|
365
|
+
onUnsubscribe: () => {
|
|
366
|
+
// Central unsubscribed
|
|
367
|
+
this.notifyCallback = undefined;
|
|
368
|
+
console.log('Central unsubscribed');
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
// Create service
|
|
372
|
+
const PrimaryServiceClass = this.bleno.PrimaryService;
|
|
373
|
+
const service = new PrimaryServiceClass({
|
|
374
|
+
uuid: this.config.serviceUUID.replace(/-/g, ''),
|
|
375
|
+
characteristics: [characteristic],
|
|
376
|
+
});
|
|
377
|
+
// Set services
|
|
378
|
+
this.bleno.setServices([service]);
|
|
379
|
+
// Listen for central connection events
|
|
380
|
+
const bleno = this.bleno;
|
|
381
|
+
bleno.on('accept', (clientAddress) => {
|
|
382
|
+
console.log('[BLE] Central accepted connection from:', clientAddress);
|
|
383
|
+
});
|
|
384
|
+
bleno.on('disconnect', (clientAddress) => {
|
|
385
|
+
console.log('[BLE] Central disconnected:', clientAddress);
|
|
386
|
+
});
|
|
387
|
+
bleno.on('servicesSet', (error) => {
|
|
388
|
+
console.log('[BLE] Services set, error:', error);
|
|
389
|
+
});
|
|
390
|
+
bleno.on('advertisingStart', (error) => {
|
|
391
|
+
console.log('[BLE] Advertising started, error:', error);
|
|
392
|
+
});
|
|
393
|
+
// Start advertising
|
|
394
|
+
const name = this.config.advertisingName ?? 'bitchat';
|
|
395
|
+
this.bleno.startAdvertising(name, [this.config.serviceUUID]);
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
// Bleno might not be available on all platforms
|
|
399
|
+
console.warn('Bleno (peripheral mode) not available:', error);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
async waitForBlenoPoweredOn() {
|
|
403
|
+
if (!this.bleno)
|
|
404
|
+
throw new Error('Bleno not initialized');
|
|
405
|
+
const bleno = this.bleno;
|
|
406
|
+
if (bleno.state === 'poweredOn')
|
|
407
|
+
return;
|
|
408
|
+
return new Promise((resolve, reject) => {
|
|
409
|
+
const timeout = setTimeout(() => {
|
|
410
|
+
reject(new Error('Bleno timeout'));
|
|
411
|
+
}, 10000);
|
|
412
|
+
const handler = (state) => {
|
|
413
|
+
if (state === 'poweredOn') {
|
|
414
|
+
clearTimeout(timeout);
|
|
415
|
+
bleno.removeListener('stateChange', handler);
|
|
416
|
+
resolve();
|
|
417
|
+
}
|
|
418
|
+
else if (state === 'poweredOff' || state === 'unauthorized') {
|
|
419
|
+
clearTimeout(timeout);
|
|
420
|
+
reject(new Error(`Bleno state: ${state}`));
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
bleno.on('stateChange', handler);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Clean up
|
|
428
|
+
*/
|
|
429
|
+
destroy() {
|
|
430
|
+
this.stop().catch(() => { });
|
|
431
|
+
this.removeAllListeners();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=ble.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ble.js","sourceRoot":"","sources":["../../src/transport/ble.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAqBlC,MAAM,cAAc,GAAuB;IACzC,WAAW,EAAE,YAAY;IACzB,kBAAkB,EAAE,mBAAmB;IACvC,OAAO,EAAE,KAAK;IACd,aAAa,EAAE,IAAI;IACnB,gBAAgB,EA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+1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,OAAO,EACP,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,OAAO,EACP,YAAY,GAGb,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitchat Web UI Server
|
|
3
|
+
* Simple HTTP + WebSocket server for testing
|
|
4
|
+
*/
|
|
5
|
+
import type { BitchatClient } from '../client.js';
|
|
6
|
+
export interface UIServerConfig {
|
|
7
|
+
port: number;
|
|
8
|
+
webhookUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Start a web UI server for the Bitchat client
|
|
12
|
+
*/
|
|
13
|
+
export declare function startUIServer(client: BitchatClient, config: UIServerConfig): {
|
|
14
|
+
stop: () => void;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/ui/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAwPlD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAYD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAuSjG"}
|