@magicred-1/react-native-lxmf 0.2.16 → 0.2.18

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.
@@ -92,13 +92,13 @@ class LxmfModule : Module() {
92
92
  }
93
93
 
94
94
  // Messaging
95
- AsyncFunction("send") { destHex: String, bodyBase64: String ->
96
- nativeSend(destHex, bodyBase64).toDouble()
95
+ AsyncFunction("send") { destHex: String, bodyBase64: String, fieldsJson: String? ->
96
+ nativeSend(destHex, bodyBase64, fieldsJson).toDouble()
97
97
  }
98
98
 
99
- AsyncFunction("broadcast") { destsHex: List<String>, bodyBase64: String ->
99
+ AsyncFunction("broadcast") { destsHex: List<String>, bodyBase64: String, fieldsJson: String? ->
100
100
  val destsJson = org.json.JSONArray(destsHex).toString()
101
- nativeBroadcast(destsJson, bodyBase64).toDouble()
101
+ nativeBroadcast(destsJson, bodyBase64, fieldsJson).toDouble()
102
102
  }
103
103
 
104
104
  // Identity
@@ -202,8 +202,8 @@ class LxmfModule : Module() {
202
202
  private external fun nativeStop(): Int
203
203
  private external fun nativeIsRunning(): Boolean
204
204
  private external fun nativePollEvents(): String?
205
- private external fun nativeSend(destHex: String, bodyBase64: String): Long
206
- private external fun nativeBroadcast(destsJson: String, bodyBase64: String): Long
205
+ private external fun nativeSend(destHex: String, bodyBase64: String, fieldsJson: String?): Long
206
+ private external fun nativeBroadcast(destsJson: String, bodyBase64: String, fieldsJson: String?): Long
207
207
  private external fun nativeGetIdentityHex(): String?
208
208
  private external fun nativeGetStatus(): String?
209
209
  private external fun nativeGetBeacons(): String?
@@ -6,8 +6,8 @@ export type NativeModuleType = {
6
6
  }[], displayName: string, isBeacon: boolean): Promise<boolean>;
7
7
  stop(): Promise<boolean>;
8
8
  isRunning(): boolean;
9
- send(destHex: string, bodyBase64: string): Promise<number>;
10
- broadcast(destsHex: string[], bodyBase64: string): Promise<number>;
9
+ send(destHex: string, bodyBase64: string, fieldsJson?: string | null): Promise<number>;
10
+ broadcast(destsHex: string[], bodyBase64: string, fieldsJson?: string | null): Promise<number>;
11
11
  getIdentityHex(): string | null;
12
12
  getStatus(): string | null;
13
13
  getBeacons(): string | null;
package/build/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { LxmfModule, LxmfModuleNative, isLxmfNativeAvailable, NativeModuleType } from './LxmfModule';
2
- export { useLxmf, LxmfNodeMode, type UseLxmfOptions, type TcpInterface, type LxmfNodeStatus, type Beacon, type LxmfEvent } from './useLxmf';
2
+ export { useLxmf, LxmfNodeMode, type UseLxmfOptions, type TcpInterface, type LxmfNodeStatus, type Beacon, type LxmfEvent, type LxmfMessageEvent, type LxmfMedia } from './useLxmf';
@@ -18,6 +18,21 @@ export interface Beacon {
18
18
  lastAnnounce: number;
19
19
  reconnectAttempts: number;
20
20
  }
21
+ export interface LxmfMessageEvent {
22
+ type: 'messageReceived';
23
+ source: string;
24
+ title: string;
25
+ body: string;
26
+ timestamp: number;
27
+ image?: {
28
+ mimeType: string;
29
+ data: string;
30
+ };
31
+ files?: {
32
+ name: string;
33
+ data: string;
34
+ }[];
35
+ }
21
36
  export interface LxmfEvent {
22
37
  type: 'statusChanged' | 'packetReceived' | 'txReceived' | 'beaconDiscovered' | 'messageReceived' | 'announceReceived' | 'log' | 'error';
23
38
  [key: string]: any;
@@ -39,6 +54,22 @@ export interface TcpInterface {
39
54
  host: string;
40
55
  port: number;
41
56
  }
57
+ /** Media attachments to include in an LXMF message.
58
+ * Encoded as LXMF standard fields: FIELD_IMAGE (0x06) and FIELD_FILE_ATTACHMENTS (0x05).
59
+ * Compatible with Sideband and other LXMF clients.
60
+ */
61
+ export interface LxmfMedia {
62
+ /** Inline image: LXMF FIELD_IMAGE — rendered by receiving clients. */
63
+ image?: {
64
+ mimeType: string;
65
+ dataBase64: string;
66
+ };
67
+ /** File attachments: LXMF FIELD_FILE_ATTACHMENTS — list of named blobs. */
68
+ files?: {
69
+ name: string;
70
+ dataBase64: string;
71
+ }[];
72
+ }
42
73
  export interface UseLxmfOptions {
43
74
  autoStart?: boolean;
44
75
  identityHex?: string;
@@ -74,8 +105,8 @@ export declare function useLxmf(options?: UseLxmfOptions): {
74
105
  isBeacon?: boolean;
75
106
  }) => Promise<boolean>;
76
107
  stop: () => Promise<void>;
77
- send: (destHex: string, bodyBase64: string) => Promise<number>;
78
- broadcast: (destsHex: string[], bodyBase64: string) => Promise<number>;
108
+ send: (destHex: string, bodyBase64: string, media?: LxmfMedia) => Promise<number>;
109
+ broadcast: (destsHex: string[], bodyBase64: string, media?: LxmfMedia) => Promise<number>;
79
110
  getStatus: () => LxmfNodeStatus | null;
80
111
  getBeacons: () => Beacon[];
81
112
  fetchMessages: (limit?: number) => any[];
package/build/useLxmf.js CHANGED
@@ -177,18 +177,20 @@ function useLxmf(options = {}) {
177
177
  setError(e?.message ?? 'Failed to stop');
178
178
  }
179
179
  }, []);
180
- const send = (0, react_1.useCallback)(async (destHex, bodyBase64) => {
180
+ const send = (0, react_1.useCallback)(async (destHex, bodyBase64, media) => {
181
181
  try {
182
- return await LxmfModule_1.LxmfModule.send(destHex, bodyBase64);
182
+ const fieldsJson = media ? JSON.stringify(media) : null;
183
+ return await LxmfModule_1.LxmfModule.send(destHex, bodyBase64, fieldsJson);
183
184
  }
184
185
  catch (e) {
185
186
  setError(e.message);
186
187
  return -1;
187
188
  }
188
189
  }, []);
189
- const broadcast = (0, react_1.useCallback)(async (destsHex, bodyBase64) => {
190
+ const broadcast = (0, react_1.useCallback)(async (destsHex, bodyBase64, media) => {
190
191
  try {
191
- return await LxmfModule_1.LxmfModule.broadcast(destsHex, bodyBase64);
192
+ const fieldsJson = media ? JSON.stringify(media) : null;
193
+ return await LxmfModule_1.LxmfModule.broadcast(destsHex, bodyBase64, fieldsJson);
192
194
  }
193
195
  catch (e) {
194
196
  setError(e.message);
@@ -27,7 +27,8 @@ func lxmf_is_running() -> Int32
27
27
  func lxmf_send(
28
28
  _ destPtr: UnsafePointer<UInt8>?,
29
29
  _ bodyPtr: UnsafePointer<UInt8>?,
30
- _ bodyLen: Int
30
+ _ bodyLen: Int,
31
+ _ fieldsJson: UnsafePointer<CChar>?
31
32
  ) -> Int64
32
33
 
33
34
  @_silgen_name("lxmf_broadcast")
@@ -35,7 +36,8 @@ func lxmf_broadcast(
35
36
  _ destsPtr: UnsafePointer<UInt8>?,
36
37
  _ destCount: Int,
37
38
  _ bodyPtr: UnsafePointer<UInt8>?,
38
- _ bodyLen: Int
39
+ _ bodyLen: Int,
40
+ _ fieldsJson: UnsafePointer<CChar>?
39
41
  ) -> Int64
40
42
 
41
43
  @_silgen_name("lxmf_poll_events")
@@ -230,22 +232,33 @@ public class LxmfModule: Module {
230
232
 
231
233
  // --- Messaging ---
232
234
 
233
- AsyncFunction("send") { (destHex: String, bodyBase64: String) -> Double in
235
+ AsyncFunction("send") { (destHex: String, bodyBase64: String, fieldsJson: String?) -> Double in
234
236
  guard let destBytes = Self.hexToBytes(destHex),
235
237
  destBytes.count == 16,
236
238
  let bodyData = Data(base64Encoded: bodyBase64) else {
237
239
  return -1
238
240
  }
239
241
 
240
- let opId = destBytes.withUnsafeBufferPointer { destBuf in
241
- [UInt8](bodyData).withUnsafeBufferPointer { bodyBuf in
242
- lxmf_send(destBuf.baseAddress, bodyBuf.baseAddress, bodyData.count)
242
+ let opId: Int64
243
+ if let json = fieldsJson {
244
+ opId = destBytes.withUnsafeBufferPointer { destBuf in
245
+ [UInt8](bodyData).withUnsafeBufferPointer { bodyBuf in
246
+ json.withCString { jsonPtr in
247
+ lxmf_send(destBuf.baseAddress, bodyBuf.baseAddress, bodyData.count, jsonPtr)
248
+ }
249
+ }
250
+ }
251
+ } else {
252
+ opId = destBytes.withUnsafeBufferPointer { destBuf in
253
+ [UInt8](bodyData).withUnsafeBufferPointer { bodyBuf in
254
+ lxmf_send(destBuf.baseAddress, bodyBuf.baseAddress, bodyData.count, nil)
255
+ }
243
256
  }
244
257
  }
245
258
  return Double(opId)
246
259
  }
247
260
 
248
- AsyncFunction("broadcast") { (destsHex: [String], bodyBase64: String) -> Double in
261
+ AsyncFunction("broadcast") { (destsHex: [String], bodyBase64: String, fieldsJson: String?) -> Double in
249
262
  guard let bodyData = Data(base64Encoded: bodyBase64) else { return -1 }
250
263
 
251
264
  var flatDests = [UInt8]()
@@ -254,9 +267,20 @@ public class LxmfModule: Module {
254
267
  flatDests.append(contentsOf: bytes)
255
268
  }
256
269
 
257
- let opId = flatDests.withUnsafeBufferPointer { destBuf in
258
- [UInt8](bodyData).withUnsafeBufferPointer { bodyBuf in
259
- lxmf_broadcast(destBuf.baseAddress, destsHex.count, bodyBuf.baseAddress, bodyData.count)
270
+ let opId: Int64
271
+ if let json = fieldsJson {
272
+ opId = flatDests.withUnsafeBufferPointer { destBuf in
273
+ [UInt8](bodyData).withUnsafeBufferPointer { bodyBuf in
274
+ json.withCString { jsonPtr in
275
+ lxmf_broadcast(destBuf.baseAddress, destsHex.count, bodyBuf.baseAddress, bodyData.count, jsonPtr)
276
+ }
277
+ }
278
+ }
279
+ } else {
280
+ opId = flatDests.withUnsafeBufferPointer { destBuf in
281
+ [UInt8](bodyData).withUnsafeBufferPointer { bodyBuf in
282
+ lxmf_broadcast(destBuf.baseAddress, destsHex.count, bodyBuf.baseAddress, bodyData.count, nil)
283
+ }
260
284
  }
261
285
  }
262
286
  return Double(opId)
@@ -8,32 +8,32 @@
8
8
  <key>BinaryPath</key>
9
9
  <string>liblxmf_rn.a</string>
10
10
  <key>LibraryIdentifier</key>
11
- <string>ios-arm64</string>
11
+ <string>ios-arm64_x86_64-simulator</string>
12
12
  <key>LibraryPath</key>
13
13
  <string>liblxmf_rn.a</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
17
+ <string>x86_64</string>
17
18
  </array>
18
19
  <key>SupportedPlatform</key>
19
20
  <string>ios</string>
21
+ <key>SupportedPlatformVariant</key>
22
+ <string>simulator</string>
20
23
  </dict>
21
24
  <dict>
22
25
  <key>BinaryPath</key>
23
26
  <string>liblxmf_rn.a</string>
24
27
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_x86_64-simulator</string>
28
+ <string>ios-arm64</string>
26
29
  <key>LibraryPath</key>
27
30
  <string>liblxmf_rn.a</string>
28
31
  <key>SupportedArchitectures</key>
29
32
  <array>
30
33
  <string>arm64</string>
31
- <string>x86_64</string>
32
34
  </array>
33
35
  <key>SupportedPlatform</key>
34
36
  <string>ios</string>
35
- <key>SupportedPlatformVariant</key>
36
- <string>simulator</string>
37
37
  </dict>
38
38
  </array>
39
39
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicred-1/react-native-lxmf",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "LXMF Reticulum mesh networking for React Native + Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",