-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
125 lines (101 loc) · 4.22 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// es6 style
import L, { map } from "leaflet"
import "./node_modules/l.movemarker"
const { EmptyMessage, FileTransferInput, FileTransferOutput } = require('./fuse_service/fuseservice_pb.js');
const { FuseClient, FusePromiseClient } = require('./fuse_service/fuseservice_grpc_web_pb.js');
// common js. why const ? // TODO: Common js syntax does not work
// const {L} = require("./node_modules/leaflet")
var mainMap;
window.addEventListener('DOMContentLoaded', function(event) {
console.log("Dom Content loaded")
});
window.addEventListener('load', async function(event) {
console.log("Loaded everything")
mainMap = L.map('map', {
center: L.latLng(0, 30),
zoom: 3,
minZoom: 3,
maxZoom: 3
});
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(mainMap);
getBuckets()
.then(buckets => {
buckets.forEach(bucket => {
console.log(bucket.getName())
var location = bucket.getLocation()
console.log(location.getLatitude())
console.log(location.getLongitude())
var bucketIcon = L.icon({
iconUrl: 'aws-s3.svg',
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
L.marker([location.getLatitude(), location.getLongitude()], {icon: bucketIcon}).addTo(mainMap);
})
})
.catch(err => {
console.log("Err: ", err)
})
mainMap.on('click', function(e) {
console.log("Click on map")
var client = new FuseClient('http://localhost:8080');
var transferInput = new FileTransferInput()
transferInput.setSourcepath("/home/zboon/satya.mkv")
transferInput.setDestinationpath("/home/zboon/buckets/b2/satya.mkv")
var stream = client.copyFile(transferInput, {})
var totalBytesTransferred = 0
var opts = {
duration: 100000 // start at a slow speed
}
var latLngs = [[36.87962060502676, -99.140625], [20.632784250388028, 78.92578125000001]]
var motionInstance = L.motionMarker(latLngs, opts)
var polyLine = L.polyline(latLngs)
motionInstance.addTo(mainMap)
polyLine.addTo(mainMap)
stream.on('data', (response) => {
var bytesTransferred = response.getBytestransferred()
console.log('response from server ', bytesTransferred)
totalBytesTransferred += bytesTransferred
console.log(totalBytesTransferred)
if (totalBytesTransferred > 20000000) {
var duration = response.getTimerequired()
duration = duration * 1000 // convert to milliseconds
var options = {
duration: duration
}
var nextLatLng = [20.632784250388028, 78.92578125000001]
var currentLatLng = [motionInstance.getLatLng().lat, motionInstance.getLatLng().lng]
motionInstance._prevLatLng = currentLatLng
motionInstance.moveTo(nextLatLng, options)
}
});
stream.on('status', (status) => {
console.log(status.code)
});
stream.on('error', (err) => {
console.log("error while reading stream ", err)
});
stream.on('end', (end) => {
console.log('stream reached eof')
stream.cancel()
});
});
});
async function getBuckets() {
// const { EmptyMessage, Buckets } = require('./fuse_service/fuseservice_pb.js');
// const { FuseClient, FusePromiseClient } = require('./fuse_service/fuseservice_grpc_web_pb.js');
// TODO: can the same be done without using the promise client ?
var client = new FusePromiseClient('http://localhost:8080');
var emptyMessage = new EmptyMessage();
try {
const response = await client.listBuckets(emptyMessage, {})
return response.getAllbucketsList()
} catch(err) {
console.log("Err: ", err)
}
}