Skip to content

Commit

Permalink
Coalesce eventsource inclusion, drop Node detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed May 22, 2023
1 parent 223cbc2 commit 9701b7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
"dependencies": {
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"detect-node": "^2.0.4",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"stellar-base": "v9.0.0-beta.2",
Expand Down
22 changes: 5 additions & 17 deletions src/call_builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import isNode from "detect-node";
import URI from "urijs";
import URITemplate from "urijs/src/URITemplate";

Expand All @@ -14,29 +13,18 @@ const version = require("../package.json").version;
// query-param.
const JOINABLE = ["transaction"];

type Constructable<T> = new (e: string) => T;

export interface EventSourceOptions<T> {
onmessage?: (value: T) => void;
onerror?: (event: MessageEvent) => void;
reconnectTimeout?: number;
}

let EventSource: Constructable<EventSource>;
const anyGlobal = global as any;

if (anyGlobal.EventSource) {
EventSource = anyGlobal.EventSource;
} else if (isNode) {
/* tslint:disable-next-line:no-var-requires */
EventSource = require("eventsource");
} else if (anyGlobal.window.EventSource) {
EventSource = anyGlobal.window.EventSource;
} else {
// require("eventsource") for React Native environment
/* tslint:disable-next-line:no-var-requires */
EventSource = require("eventsource");
}
type Constructable<T> = new (e: string) => T;
// require("eventsource") for Node and React Native environment
let EventSource: Constructable<EventSource> = anyGlobal.EventSource ??
anyGlobal.window.EventSource ??
require("eventsource");

/**
* Creates a new {@link CallBuilder} pointed to server defined by serverUrl.
Expand Down

0 comments on commit 9701b7a

Please sign in to comment.