relayproxy.mx raw

   1  //go:build !wasm
   2  //:build !wasm
   3  
   4  // Package relayproxy is the bridge for the smesh relay-proxy worker boundary.
   5  // Two function sets in one package, used in different contexts:
   6  //
   7  //   - Worker-internal (used only inside relay-proxy.wasm):
   8  //     OnMessage, Post.
   9  //
  10  //   - Consumer-side (used only inside app.wasm):
  11  //     Send, OnMessage (consumer variant; route differs from worker variant).
  12  //
  13  // Functions called only from one context are dead-code-eliminated by the
  14  // linker for the other context, so the two function sets do not pollute
  15  // each other's wasm imports.
  16  //
  17  // Wire format on both directions: JSON-array MW-shape strings.
  18  // e.g. ["REQ","sub-1",{"kinds":[1],"limit":50},["wss://relay.damus.io"]]
  19  // e.g. ["EVENT","sub-1",{<event-json>}]
  20  package relayproxy
  21  
  22  // === Consumer-side (app.wasm) ===
  23  
  24  // Send dispatches a JSON-array message to the relay-proxy worker via the
  25  // supervisor. The worker decodes and acts on it.
  26  func Send(msg string) { panic("jsbridge") }
  27  
  28  // OnMessage registers a handler for messages from the relay-proxy worker.
  29  // fn receives the raw JSON-array string; the consumer parses it.
  30  func OnMessage(fn func(msg string)) { panic("jsbridge") }
  31  
  32  // === Worker-internal (relay-proxy.wasm) ===
  33  
  34  // WorkerOnMessage registers a handler for inbound messages on the worker
  35  // side. JSON-array strings posted by the supervisor (originating from
  36  // app.wasm or from internal sources) are delivered here.
  37  func WorkerOnMessage(fn func(msg string)) { panic("jsbridge") }
  38  
  39  // WorkerPost sends a JSON-array message back to the supervisor over the
  40  // worker's natural postMessage channel. The supervisor forwards to app.wasm.
  41  func WorkerPost(msg string) { panic("jsbridge") }
  42  
  43  // WorkerSetTimeout schedules fn to run after ms milliseconds. Returns a
  44  // handle for WorkerClearTimeout.
  45  func WorkerSetTimeout(ms int32, fn func()) (n int32) { panic("jsbridge") }
  46  
  47  // WorkerClearTimeout cancels a pending timeout by handle.
  48  func WorkerClearTimeout(handle int32) { panic("jsbridge") }
  49  
  50  // WorkerNowSeconds returns the current Unix time in seconds via Date.now().
  51  func WorkerNowSeconds() (n int64) { panic("jsbridge") }
  52