Skip to content

Commit

Permalink
feat(sse_middleware): SSE functions are void now
Browse files Browse the repository at this point in the history
  • Loading branch information
toverux committed May 28, 2017
1 parent 0fa831f commit 1d6c99b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sse_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ISseFunctions {
* @param data The event data1
* @param id The event ID, useful for replay thanks to the Last-Event-ID header
*/
data(data: fmt.SSEValue, id?: string): boolean;
data(data: fmt.SSEValue, id?: string): void;

/**
* Writes a standard SSE message (with named event) on the socket.
Expand All @@ -28,15 +28,15 @@ export interface ISseFunctions {
* @param data The event data (mandatory!)
* @param id The event ID, useful for replay thanks to the Last-Event-ID header
*/
event(event: string, data: fmt.SSEValue, id?: string): boolean;
event(event: string, data: fmt.SSEValue, id?: string): void;

/**
* Writes a standard SSE comment on the socket.
* Comments are informative and useful for debugging. There are discarded by EventSource on the browser.
*
* @param comment The comment message (not serialized)
*/
comment(comment: string): boolean;
comment(comment: string): void;
}

/**
Expand All @@ -48,8 +48,8 @@ export interface ISseResponse extends Response {
}

/**
* SSE middleware that configures an Express response for an SSE session,
* and installs sse() and sseComment() functions on the Response object
* SSE middleware that configures an Express response for an SSE session, and installs the `sse.*` functions
* on the Response object.
*
* @param options An ISseMiddlewareOptions to configure the middleware's behaviour.
*/
Expand All @@ -60,13 +60,13 @@ export function sse(options: Partial<ISseMiddlewareOptions> = {}): Handler {
//=> Install the sse*() functions on Express' Response
(res as ISseResponse).sse = {
data(data: fmt.SSEValue, id?: string) {
return res.write(fmt.message(null, data, id, serializer));
res.write(fmt.message(null, data, id, serializer));
},
event(event: string, data: fmt.SSEValue, id?: string) {
return res.write(fmt.message(event, data, id, serializer));
res.write(fmt.message(event, data, id, serializer));
},
comment(comment: string) {
return res.write(fmt.comment(comment));
res.write(fmt.comment(comment));
}
};

Expand Down

0 comments on commit 1d6c99b

Please sign in to comment.