Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Determine real-time HTTP connected status #3335

Merged
merged 4 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/api/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('api/Api', () => {
});

describe('interface', () => {
const api = new Api(new Api.Transport.Http(TEST_HTTP_URL));
const api = new Api(new Api.Transport.Http(TEST_HTTP_URL, -1));

Object.keys(ethereumRpc).sort().forEach((endpoint) => {
describe(endpoint, () => {
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/contract/contract.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Api from '../api';
import Contract from './contract';
import { isInstanceOf, isFunction } from '../util/types';

const transport = new Api.Transport.Http(TEST_HTTP_URL);
const transport = new Api.Transport.Http(TEST_HTTP_URL, -1);
const eth = new Api(transport);

describe('api/contract/Contract', () => {
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/db/db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http';
import Db from './db';

const instance = new Db(new Http(TEST_HTTP_URL));
const instance = new Db(new Http(TEST_HTTP_URL, -1));

describe('api/rpc/Db', () => {
let scope;
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/eth/eth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
import Http from '../../transport/http';
import Eth from './eth';

const instance = new Eth(new Http(TEST_HTTP_URL));
const instance = new Eth(new Http(TEST_HTTP_URL, -1));

describe('rpc/Eth', () => {
const address = '0x63Cf90D3f0410092FC0fca41846f596223979195';
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/net/net.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
import Http from '../../transport/http';
import Net from './net';

const instance = new Net(new Http(TEST_HTTP_URL));
const instance = new Net(new Http(TEST_HTTP_URL, -1));

describe('api/rpc/Net', () => {
describe('peerCount', () => {
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/parity/parity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
import Http from '../../transport/http';
import Parity from './parity';

const instance = new Parity(new Http(TEST_HTTP_URL));
const instance = new Parity(new Http(TEST_HTTP_URL, -1));

describe('api/rpc/parity', () => {
describe('accountsInfo', () => {
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/personal/personal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http';
import Personal from './personal';

const instance = new Personal(new Http(TEST_HTTP_URL));
const instance = new Personal(new Http(TEST_HTTP_URL, -1));

describe('rpc/Personal', () => {
const account = '0x63cf90d3f0410092fc0fca41846f596223979195';
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/trace/trace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http';
import Trace from './trace';

const instance = new Trace(new Http(TEST_HTTP_URL));
const instance = new Trace(new Http(TEST_HTTP_URL, -1));

describe('api/rpc/Trace', () => {
let scope;
Expand Down
2 changes: 1 addition & 1 deletion js/src/api/rpc/web3/web3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http';
import Web3 from './web3';

const instance = new Web3(new Http(TEST_HTTP_URL));
const instance = new Web3(new Http(TEST_HTTP_URL, -1));

describe('api/rpc/Web3', () => {
let scope;
Expand Down
18 changes: 17 additions & 1 deletion js/src/api/transport/http/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import JsonRpcBase from '../jsonRpcBase';

/* global fetch */
export default class Http extends JsonRpcBase {
constructor (url) {
constructor (url, connectTimeout = 1000) {
super();

this._connected = true;
this._url = url;
this._connectTimeout = connectTimeout;

this._pollConnection();
}

_encodeOptions (method, params) {
Expand Down Expand Up @@ -77,4 +80,17 @@ export default class Http extends JsonRpcBase {
return response.result;
});
}

_pollConnection = () => {
if (this._connectTimeout <= 0) {
return;
}

const nextTimeout = () => setTimeout(this._pollConnection, this._connectTimeout);

this
.execute('net_listening')
.then(nextTimeout)
.catch(nextTimeout);
}
}
2 changes: 1 addition & 1 deletion js/src/api/transport/http/http.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from './http';

const transport = new Http(TEST_HTTP_URL);
const transport = new Http(TEST_HTTP_URL, -1);

describe('api/transport/Http', () => {
describe('instance', () => {
Expand Down