From 0b10cbd713faf56240f3da6940c58c17159849a9 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 28 Oct 2014 16:53:31 +0100 Subject: http renamed to httprpc --- http.js | 69 ------------------------------------------------------------- httprpc.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 2 +- 3 files changed, 71 insertions(+), 70 deletions(-) delete mode 100644 http.js create mode 100644 httprpc.js diff --git a/http.js b/http.js deleted file mode 100644 index 768d7c1ff..000000000 --- a/http.js +++ /dev/null @@ -1,69 +0,0 @@ -(function () { - var HttpProvider = function (host) { - this.handlers = []; - this.host = host; - }; - - function formatJsonRpcObject(object) { - return { - jsonrpc: '2.0', - method: object.call, - params: object.args, - id: object._id - } - }; - - function formatJsonRpcMessage(message) { - var object = JSON.parse(message); - - return { - _id: object.id, - data: object.result - }; - }; - - HttpProvider.prototype.sendRequest = function (payload, cb) { - var data = formatJsonRpcObject(payload); - - var request = new XMLHttpRequest(); - request.open("POST", this.host, true); - request.send(JSON.stringify(data)); - request.onreadystatechange = function () { - if (request.readyState === 4 && cb) { - cb(request); - } - } - }; - - HttpProvider.prototype.send = function (payload) { - var self = this; - this.sendRequest(payload, function (request) { - self.handlers.forEach(function (handler) { - handler.call(self, formatJsonRpcMessage(request.responseText)); - }); - }); - }; - - HttpProvider.prototype.poll = function (payload, id) { - var self = this; - this.sendRequest(payload, function (request) { - var parsed = JSON.parse(request.responseText); - if (!parsed.result) { - return; - } - self.handlers.forEach(function (handler) { - handler.call(self, {_event: "messages", data: id}); - }); - }); - }; - - Object.defineProperty(HttpProvider.prototype, "onmessage", { - set: function (handler) { - this.handlers.push(handler); - } - }); - - if (typeof(web3) !== "undefined" && web3.providers !== undefined) { - web3.providers.HttpProvider = HttpProvider; - } -})(); diff --git a/httprpc.js b/httprpc.js new file mode 100644 index 000000000..50674ec94 --- /dev/null +++ b/httprpc.js @@ -0,0 +1,70 @@ +(function () { + var HttpRpcProvider = function (host) { + this.handlers = []; + this.host = host; + }; + + function formatJsonRpcObject(object) { + return { + jsonrpc: '2.0', + method: object.call, + params: object.args, + id: object._id + } + }; + + function formatJsonRpcMessage(message) { + var object = JSON.parse(message); + + return { + _id: object.id, + data: object.result + }; + }; + + HttpRpcProvider.prototype.sendRequest = function (payload, cb) { + var data = formatJsonRpcObject(payload); + + var request = new XMLHttpRequest(); + request.open("POST", this.host, true); + request.send(JSON.stringify(data)); + request.onreadystatechange = function () { + if (request.readyState === 4 && cb) { + cb(request); + } + } + }; + + HttpRpcProvider.prototype.send = function (payload) { + var self = this; + this.sendRequest(payload, function (request) { + self.handlers.forEach(function (handler) { + handler.call(self, formatJsonRpcMessage(request.responseText)); + }); + }); + }; + + HttpRpcProvider.prototype.poll = function (payload, id) { + var self = this; + this.sendRequest(payload, function (request) { + var parsed = JSON.parse(request.responseText); + if (!parsed.result) { + return; + } + self.handlers.forEach(function (handler) { + handler.call(self, {_event: "messages", data: id}); + }); + }); + }; + + Object.defineProperty(HttpRpcProvider.prototype, "onmessage", { + set: function (handler) { + this.handlers.push(handler); + } + }); + + if (typeof(web3) !== "undefined" && web3.providers !== undefined) { + web3.providers.HttpRpcProvider = HttpRpcProvider; + } +})(); + diff --git a/index.html b/index.html index 70f788d0d..2b3f50a14 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - +