const client = new Wormhole.default(connectionUrl: string, options: WormholeClientOptions)
interface WormholeClientOptions {
connectionOptions: WebsocketConnectionOptions;
}
interface WebsocketConnectionOptions {
reconnect: boolean = true;
maxReconnects: number = Infinity;
reconnectTimeout: number = 1000;
}
const client = new Wormhole('ws://localhost:7532', {
connectionOptions: {
reconnect: true,
maxReconnects: 5
}
});
client.connect()
.on('connect', () => {
console.log('connection established');
})
.on('disconnect', () => {
console.log('connection lost');
})
.on('error', () => {
console.log('connection error');
})
client.remote.Greeter.Hello({
Message: "test",
CallableRef: () => {
console.log("CallableRef");
},
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
}).finally(() => {
console.log("call end");
});
try {
const payload = {
Message: "test",
CallableRef: () => {
console.log("CallableRef");
},
};
const result = await client.remote.Greeter.Hello(payload);
console.log("result", result);
} catch (error) {
console.log(error);
}
client.remote.Greeter.Hello({
Message: "test",
});
client.provide(name: string, methods: Object)
client.provide('Greeter', {
Hello: () => {
return 'Hello'
}
})
const client = new WormholeClient(options);
try {
const result = await client.remote.Greeter.Hello({
Message: "test",
});
} catch (error) {
console.log("error", error);
}