Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Resolve IP addresses to geo coordinates

  • Loading branch information...
commit a1aaa7eb3b4358c419ceff1a2936a4e096b85f36 1 parent 5cfed2c
Ole André Vadla Ravnås oleavr authored
Showing with 16 additions and 0 deletions.
  1. +16 0 geoshark.qml
16 geoshark.qml
View
@@ -79,6 +79,22 @@ ApplicationWindow {
}
onMessage: {
messages.append(JSON.stringify(object) + "\n");
+ if (object.type === "send") {
+ var stanza = object.payload;
+ if (stanza.name === "new-ip-address") {
+ var ip = stanza.payload;
+ var xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function () {
+ if (xhr.readyState === XMLHttpRequest.DONE) {
+ var location = JSON.parse(xhr.responseText);
+ messages.append("Resolved " + ip +
+ " to " + JSON.stringify(location) + "\n");
+ }
+ };
+ xhr.open("GET", "http://freegeoip.net/json/" + ip);
+ xhr.send();
+ }
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.