Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SSE data reporting #1298

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions packages/binding-http/src/subscription-protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ export class SSESubscription implements InternalSubscription {
};
this.eventSource.onmessage = (event) => {
debug(`HttpClient received ${JSON.stringify(event)} from ${this.form.href}`);
const output = new Content(
this.form.contentType ?? ContentSerdes.DEFAULT,
Readable.from(JSON.stringify(event))
);
const output = new Content(this.form.contentType ?? ContentSerdes.DEFAULT, Readable.from(event.data));
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved
next(output);
};
this.eventSource.onerror = function (event) {
Expand Down
5 changes: 4 additions & 1 deletion packages/binding-http/test/http-client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as http from "http";
import { Content, DefaultContent, ContentSerdes, createLoggers, ProtocolServer } from "@node-wot/core";

import { Readable } from "stream";
import { text } from "node:stream/consumers";

import HttpClient from "../src/http-client";
import { HttpForm } from "../src/http";
Expand Down Expand Up @@ -463,7 +464,9 @@ class HttpClientTest2 {
};

client
.subscribeResource(form, (data) => {
.subscribeResource(form, async (data) => {
const str = await text(data.body); // SHOULD be "Test event"
str.should.eql("Test event");
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved
client.unlinkResource(form);
server.close();
clock.uninstall();
Expand Down
Loading