-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.js
52 lines (44 loc) · 1.26 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const {RSocketClient} = require('rsocket-core');
const RSocketWebsocketClient = require('rsocket-websocket-client').default;
const WebSocket = require("ws");
const {Flowable, Single} = require('rsocket-flowable');
const transportOptions = {
url: 'ws://localhost:7777',
wsCreator: (url) => {
return new WebSocket(url);
}
};
const setup = {
keepAlive: 60000,
lifetime: 180000,
dataMimeType: 'text/plain',
metadataMimeType: 'text/plain',
};
const transport = new RSocketWebsocketClient(transportOptions);
const client = new RSocketClient({setup, transport});
client.connect().subscribe({
onComplete: socket => {
console.log('Client connected to the RSocket server');
let clientRequests = ['a', 'b', 'c', 'd', 'e', 'f'];
clientRequests = clientRequests.map(req => {
return {
data: req
};
});
let subscription;
socket.requestChannel(Flowable.just(...clientRequests))
.subscribe({
onSubscribe: sub => {
subscription = sub;
console.log(`Client is establishing a channel`);
subscription.request(0x7fffffff);
},
onNext: response => {
console.log(response);
},
onComplete: () => {
console.log(`Client received end of server stream`);
}
});
}
});