mirror of
https://github.com/logos-messaging/lab.waku.org.git
synced 2026-01-16 12:43:08 +00:00
chore: move types to a separate file
This commit is contained in:
parent
c02ed0a4f6
commit
3bacf29d01
@ -1,24 +1,5 @@
|
||||
import { type DecodedMessage } from "@waku/sdk";
|
||||
|
||||
const CONTENT_TOPICS = [
|
||||
"/railgun/v2/0-1-fees/json",
|
||||
"/railgun/v2/0-56-fees/json",
|
||||
"/railgun/v2/0-137-fees/json",
|
||||
"/railgun/v2/0-42161-fees/json",
|
||||
"/railgun/v2/0-421$1-transact-response/json",
|
||||
"/railgun/v2/encrypted-metrics-pong/json"
|
||||
] as const;
|
||||
|
||||
interface ServiceWorkerMessage {
|
||||
type: string;
|
||||
message?: string;
|
||||
status?: string;
|
||||
peerId?: string;
|
||||
error?: string;
|
||||
timestamp?: string;
|
||||
contentTopic?: string;
|
||||
topics?: readonly string[];
|
||||
}
|
||||
import { WAKU_CONFIG, type ServiceWorkerMessage } from './types';
|
||||
|
||||
let lastMessageTimestamp: number | null = null;
|
||||
|
||||
@ -184,7 +165,7 @@ class Railgun {
|
||||
|
||||
navigator.serviceWorker.controller.postMessage({
|
||||
type: 'subscribe',
|
||||
payload: { topics: CONTENT_TOPICS }
|
||||
payload: { topics: WAKU_CONFIG.CONTENT_TOPICS }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,45 +1,8 @@
|
||||
import { createDecoder, createEncoder, createLightNode, type LightNode, Protocols } from '@waku/sdk';
|
||||
import { WAKU_CONFIG, type MessagePayload, type ClientMessage, type WakuMessage } from './types';
|
||||
|
||||
declare const self: ServiceWorkerGlobalScope;
|
||||
|
||||
const WAKU_CONFIG = {
|
||||
PUBSUB_TOPIC: "/waku/2/rs/0/1",
|
||||
CONTENT_TOPICS: [
|
||||
"/railgun/v2/0-1-fees/json",
|
||||
"/railgun/v2/0-56-fees/json",
|
||||
"/railgun/v2/0-137-fees/json",
|
||||
"/railgun/v2/0-42161-fees/json",
|
||||
"/railgun/v2/0-421$1-transact-response/json",
|
||||
"/railgun/v2/encrypted-metrics-pong/json"
|
||||
] as const,
|
||||
NETWORK: {
|
||||
CLUSTER_ID: 0,
|
||||
SHARD: 1,
|
||||
RAILGUN_MA: '/dns4/railgun.ivansete.xyz/tcp/8000/wss/p2p/16Uiu2HAmExcXDvdCr2XxfCeQY1jhCoJ1HodgKauRatCngQ9Q1X61'
|
||||
}
|
||||
} as const;
|
||||
|
||||
interface SendMessagePayload {
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface SubscribePayload {
|
||||
topics: readonly string[];
|
||||
}
|
||||
|
||||
type MessagePayload = {
|
||||
type: 'sendMessage';
|
||||
payload: SendMessagePayload;
|
||||
} | {
|
||||
type: 'subscribe';
|
||||
payload: SubscribePayload;
|
||||
};
|
||||
|
||||
type ClientMessage = {
|
||||
type: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
let wakuNode: LightNode | null = null;
|
||||
|
||||
async function notifyClients(message: ClientMessage): Promise<void> {
|
||||
@ -142,7 +105,7 @@ async function subscribeToTopics(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleIncomingMessage(message: { payload: Uint8Array; contentTopic: string }): Promise<void> {
|
||||
async function handleIncomingMessage(message: WakuMessage): Promise<void> {
|
||||
console.log('📨 Message received on topic:', message.contentTopic);
|
||||
const content = new TextDecoder().decode(message.payload);
|
||||
await notifyClients({
|
||||
|
||||
53
examples/experimental/railgun-repro/types.ts
Normal file
53
examples/experimental/railgun-repro/types.ts
Normal file
@ -0,0 +1,53 @@
|
||||
export const WAKU_CONFIG = {
|
||||
PUBSUB_TOPIC: "/waku/2/rs/0/1",
|
||||
CONTENT_TOPICS: [
|
||||
"/railgun/v2/0-1-fees/json",
|
||||
"/railgun/v2/0-56-fees/json",
|
||||
"/railgun/v2/0-137-fees/json",
|
||||
"/railgun/v2/0-42161-fees/json",
|
||||
"/railgun/v2/0-421$1-transact-response/json",
|
||||
"/railgun/v2/encrypted-metrics-pong/json"
|
||||
] as const,
|
||||
NETWORK: {
|
||||
CLUSTER_ID: 0,
|
||||
SHARD: 1,
|
||||
RAILGUN_MA: '/dns4/railgun.ivansete.xyz/tcp/8000/wss/p2p/16Uiu2HAmExcXDvdCr2XxfCeQY1jhCoJ1HodgKauRatCngQ9Q1X61'
|
||||
}
|
||||
} as const;
|
||||
|
||||
export interface SendMessagePayload {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface SubscribePayload {
|
||||
topics: readonly string[];
|
||||
}
|
||||
|
||||
export type MessagePayload = {
|
||||
type: 'sendMessage';
|
||||
payload: SendMessagePayload;
|
||||
} | {
|
||||
type: 'subscribe';
|
||||
payload: SubscribePayload;
|
||||
};
|
||||
|
||||
export type ClientMessage = {
|
||||
type: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export interface ServiceWorkerMessage {
|
||||
type: string;
|
||||
message?: string;
|
||||
status?: string;
|
||||
peerId?: string;
|
||||
error?: string;
|
||||
timestamp?: string;
|
||||
contentTopic?: string;
|
||||
topics?: readonly string[];
|
||||
}
|
||||
|
||||
export interface WakuMessage {
|
||||
payload: Uint8Array;
|
||||
contentTopic: string;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user