@eth-sdk/query
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -5,2 +5,3 @@ import { BehaviorSubject } from 'rxjs'; | ||
private endpoint; | ||
private static detectFetch; | ||
private readonly fetch; | ||
@@ -7,0 +8,0 @@ constructor(endpoint: string, options?: HttpProvider.IOptions); |
@@ -7,8 +7,19 @@ "use strict"; | ||
this.endpoint = endpoint; | ||
this.fetch = typeof fetch !== 'undefined' | ||
? fetch | ||
: options.fetch; | ||
if (!this.fetch) { | ||
this.fetch = HttpProvider.detectFetch(options.fetch); | ||
} | ||
static detectFetch(option = null) { | ||
let result; | ||
if (option) { | ||
result = option; | ||
} | ||
else { | ||
result = (typeof window !== 'undefined' && | ||
typeof window.fetch !== 'undefined') | ||
? window.fetch.bind(window) | ||
: null; | ||
} | ||
if (!result) { | ||
new Error('fetch not found. Please use `node-fetch` via options.fetch'); | ||
} | ||
return result; | ||
} | ||
@@ -15,0 +26,0 @@ get connected$() { |
@@ -7,2 +7,3 @@ import { BehaviorSubject } from 'rxjs'; | ||
static DEFAULT_REQUEST_TIMEOUT: number; | ||
private static detectWebSocketConstructor; | ||
connected$: BehaviorSubject<boolean>; | ||
@@ -9,0 +10,0 @@ notification$: BehaviorSubject<IProvider.INotification>; |
@@ -16,8 +16,3 @@ "use strict"; | ||
this.reconnectTimeout = null; | ||
this.webSocketConstructor = typeof WebSocket !== 'undefined' | ||
? WebSocket | ||
: options.webSocketConstructor; | ||
if (!this.webSocketConstructor) { | ||
throw new Error('please setup options.webSocketConstructor'); | ||
} | ||
this.webSocketConstructor = WebSocketProvider.detectWebSocketConstructor(options.webSocketConstructor); | ||
this.options = Object.assign(Object.assign({ connect: false, reconnectTime: WebSocketProvider.DEFAULT_RECONNECT_TIME, requestTimeout: WebSocketProvider.DEFAULT_REQUEST_TIMEOUT }, options), { webSocketConstructor: null }); | ||
@@ -45,2 +40,17 @@ this | ||
} | ||
static detectWebSocketConstructor(option = null) { | ||
let result; | ||
if (option) { | ||
result = option; | ||
} | ||
else { | ||
result = (typeof WebSocket !== 'undefined') | ||
? WebSocket | ||
: null; | ||
} | ||
if (!result) { | ||
throw new Error('please setup options.webSocketConstructor'); | ||
} | ||
return result; | ||
} | ||
get connected() { | ||
@@ -47,0 +57,0 @@ return this.state === WebSocketProvider.States.Connected; |
{ | ||
"name": "@eth-sdk/query", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Eth sdk query", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
77632
1292
0