Skip to content
Open
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: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface EventSourceOptions {
debug?: boolean;
pollingInterval?: number;
lineEndingCharacter?: string;
autoConnect?: boolean;
}

type BuiltInEventMap = {
Expand All @@ -77,6 +78,7 @@ declare class EventSource<E extends string = never> {
removeEventListener<T extends EventType<E>>(type: T, listener: EventSourceListener<E, T>): void;
removeAllEventListeners<T extends EventType<E>>(type?: T): void;
dispatch<T extends EventType<E>>(type: T, data: EventSourceEvent<T>): void;
isConnected : boolean;
}

export default EventSource;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-sse",
"version": "1.2.1",
"version": "1.2.2",
"description": "EventSource implementation for React Native. Server-Sent Events (SSE) for iOS and Android.",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/EventSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EventSource {
this.debug = options.debug || false;
this.interval = options.pollingInterval ?? 5000;
this.lineEndingCharacter = options.lineEndingCharacter || null;
this.autoConnect = options.autoConnect ?? true;

const defaultHeaders = {
Accept: 'text/event-stream',
Expand All @@ -56,7 +57,7 @@ class EventSource {
this.url = url;
}

this._pollAgain(this.timeoutBeforeConnection, true);
if(this.autoConnect) this._pollAgain(this.timeoutBeforeConnection, true);
}

_pollAgain(time, allowZero) {
Expand Down Expand Up @@ -328,6 +329,9 @@ class EventSource {
this._xhr.abort();
}
}
get isConnected() {
return this.status === this.OPEN;
}
}

export default EventSource;