-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
34 lines (29 loc) · 1.08 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
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const packageDef = protoLoader.loadSync('todo.proto', {});
const grpcObject = grpc.loadPackageDefinition(packageDef);
const todoPackage = grpcObject.todoPackage;
const text = process.argv[2];
// let text;
const client = new todoPackage.Todo('localhost:3300', grpc.credentials.createInsecure() );
// const input = document.getElementById('input');
// const button = document.getElementById('submit');
// button.addEventListener('click', () => {
// text = input;
// })
// console.log("CLIENT: ", client);
client.createTodo({
"id": -1,
"text": text
}, (err,response) => {
console.log("Received from server " + JSON.stringify(response))
});
client.readTodos({}, (err, response)=> {
console.log("Received from server" + JSON.stringify(response))
response.items.forEach(i => console.log( i.text))
});
const call = client.readTodosStream();
call.on("data", item => {
console.log("received item from server " + JSON.stringify(item))
})
call.on("end", e => console.log("server done!"))