I'm starting on my first javascript GTK app and I want to download a file and track it's progress with a Gtk.ProgressBar. The only docs I can find about http requests are some example code here:
http://developer.gnome.org/gnome-devel-demos/unstable/weatherGeonames.js.html.en
And some confusing Soup reference here:
http://www.roojs.org/seed/gir-1.2-gtk-3.0/gjs/Soup.SessionAsync.html
From what I can gather, I can do something like this:
const Soup = imports.gi.Soup;
var _httpSession = new Soup.SessionAsync();
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault());
var request = Soup.Message.new('GET', url);
_httpSession.queue_message(request, function(_httpSession, message) {
print('download is done');
}
There only seems to be a callback for when the download is done, and I can't find any way to set a callback function for any data events. How can I do this?
This is really easy in node.js:
var req = http.request(url, function(res){
console.log('download starting');
res.on('data', function(chunk) {
console.log('got a chunk of '+chunk.length+' bytes');
});
});
req.end();