forked from blockchain-it-hr/ink-remix-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws-client-build.js
36 lines (29 loc) · 910 Bytes
/
ws-client-build.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
const WebSocket = require('ws');
const fs = require('fs');
//file_name="test_build_input.file"
//url="wss://server.staging.ink-remix.blockchain-it.hr/new"
const file_name="test_build_input.file";
const url = "wss://server.staging.ink-remix.blockchain-it.hr/build";
const client = new WebSocket(url);
console.time("duration");
client.on('open', (res) => {
//console.log(`Response: ${res}`);
let fileContent = readFile();
console.log("Opening");
client.send(fileContent);
});
client.on('message', (res) => {
//console.log(`Response: ${res}`);
let parsedResponse = JSON.parse(res);
if (parsedResponse.type === "build") {
console.log("Closing");
console.timeEnd('duration');
client.close();
}
});
client.on('error', (error) => {
//console.log(`Error: ${error}`);
});
function readFile() {
return fs.readFileSync(__dirname + `/${file_name}`);
}