diff --git a/README.md b/README.md index fed435f..9ac7577 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,8 @@ const options: EventSourceOptions = { body: undefined, // Your request body sent on connection. Default: undefined debug: false, // Show console.debug messages for debugging purpose. Default: false pollingInterval: 5000, // Time (ms) between reconnections. If set to 0, reconnections will be disabled. Default: 5000 - lineEndingCharacter: null // Character(s) used to represent line endings in received data. Common values: '\n' for LF (Unix/Linux), '\r\n' for CRLF (Windows), '\r' for CR (older Mac). Default: null (Automatically detect from event) + lineEndingCharacter: null, // Character(s) used to represent line endings in received data. Common values: '\n' for LF (Unix/Linux), '\r\n' for CRLF (Windows), '\r' for CR (older Mac). Default: null (Automatically detect from event) + lastEventId: null // `Last-Event-ID` request header sent on initial connection. Default null. } ``` diff --git a/index.d.ts b/index.d.ts index 4820cc4..f50cf4e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -54,6 +54,7 @@ export interface EventSourceOptions { debug?: boolean; pollingInterval?: number; lineEndingCharacter?: string; + lastEventId?: string; } type BuiltInEventMap = { diff --git a/src/EventSource.js b/src/EventSource.js index 8b2991d..66bff38 100644 --- a/src/EventSource.js +++ b/src/EventSource.js @@ -11,7 +11,6 @@ class EventSource { CR = '\r'; constructor(url, options = {}) { - this.lastEventId = null; this.status = this.CONNECTING; this.eventHandlers = { @@ -30,6 +29,7 @@ class EventSource { this.debug = options.debug || false; this.interval = options.pollingInterval ?? 5000; this.lineEndingCharacter = options.lineEndingCharacter || null; + this.lastEventId = options.lastEventId || null; const defaultHeaders = { Accept: 'text/event-stream',