forked from Kieran/snort
fix build
This commit is contained in:
parent
898d8bfe02
commit
53754a5a69
@ -1,22 +1,22 @@
|
||||
/// <reference lib="webworker" />
|
||||
|
||||
import { NostrSystem, NostrsystemProps } from "../nostr-system";
|
||||
import { NostrSystemMessage, NostrSystemCommand } from ".";
|
||||
import { WorkerMessage, WorkerCommand } from ".";
|
||||
|
||||
let system: NostrSystem | undefined;
|
||||
|
||||
function reply<T>(id: string, type: NostrSystemCommand, data: T) {
|
||||
function reply<T>(id: string, type: WorkerCommand, data: T) {
|
||||
globalThis.postMessage({
|
||||
id,
|
||||
type,
|
||||
data,
|
||||
} as NostrSystemMessage<T>);
|
||||
} as WorkerMessage<T>);
|
||||
}
|
||||
function okReply(id: string, message?: string) {
|
||||
reply<string | undefined>(id, NostrSystemCommand.OkResponse, message);
|
||||
reply<string | undefined>(id, WorkerCommand.OkResponse, message);
|
||||
}
|
||||
function errorReply(id: string, message: string) {
|
||||
reply<string>(id, NostrSystemCommand.ErrorResponse, message);
|
||||
reply<string>(id, WorkerCommand.ErrorResponse, message);
|
||||
}
|
||||
function checkInitialized() {
|
||||
if (system === undefined) {
|
||||
@ -25,11 +25,11 @@ function checkInitialized() {
|
||||
}
|
||||
|
||||
globalThis.onmessage = async ev => {
|
||||
const data = ev.data as { id: string; type: NostrSystemCommand };
|
||||
const data = ev.data as { id: string; type: WorkerCommand };
|
||||
try {
|
||||
switch (data.type) {
|
||||
case NostrSystemCommand.Init: {
|
||||
const cmd = ev.data as NostrSystemMessage<NostrsystemProps>;
|
||||
case WorkerCommand.Init: {
|
||||
const cmd = ev.data as WorkerMessage<NostrsystemProps>;
|
||||
if (system === undefined) {
|
||||
system = new NostrSystem(cmd.data);
|
||||
await system.Init();
|
||||
@ -39,9 +39,9 @@ globalThis.onmessage = async ev => {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NostrSystemCommand.ConnectRelay: {
|
||||
case WorkerCommand.ConnectRelay: {
|
||||
checkInitialized();
|
||||
const cmd = ev.data as NostrSystemMessage<[string, { read: boolean; write: boolean }]>;
|
||||
const cmd = ev.data as WorkerMessage<[string, { read: boolean; write: boolean }]>;
|
||||
await system?.ConnectToRelay(cmd.data[0], cmd.data[1]);
|
||||
okReply(data.id, "Connected");
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user