1.0.5 • Published 1 year ago

rxjs-ws v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Ping/Pong example:

const client = new RXSocketClient({ url: 'ws://localhost:3000' });
const pingEvent = client.event('ping');
pingEvent.subscribe((response) => pingEvent.send());

const server = new RXSocketServer();
const pingEvent = server.event('ping');
pingEvent.subscribe((response) => {
	console.log('Pong from ', response.socket);
});
setInterval(() => {
	console.log('Ping everyone');
	pingEvent.send();
}, 1000);

Send for result example:

const client = new RXSocketClient({ url: 'ws://localhost:3000' }));
const helloEvent = client.event('hello');
(async () => {
	let result = await helloEvent.sendForResult('Hello!');
	console.log(result.data); // 'Hi!'
	result = await result.replyForResult('How are you?');
	console.log(result.data);
})();

const server = new RXSocketServer();
const helloEvent = server.event('hello');
helloEvent.subscribe(async (message) => {
	console.log(message.data); // 'Hello!'
	let result = await message.replyForResult('Hi!');
	console.log(result.data); // 'How are you?'
	result.reply('I\'m good, thanks.');
});

Subscription example:

const client = new RXSocketClient({ url: 'ws://localhost:3000' });
const pingEvent = client.event('ping');
// pingEvent.subscribe();

const server = new RXSocketServer();
const pingEvent = server.event('ping');
setInterval(() => {
	pingEvent.send(); // will not send the event, because there is no subscribers
}, 1000);
1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago