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 streams signatures #497

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
6 changes: 2 additions & 4 deletions dist/metacom.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ class Metacom extends EventEmitter {

createStream(name, size) {
const id = ++this.streamId;
const initData = { type: 'stream', id, name, size };
const transport = this;
return new MetaWritable(transport, initData);
return new MetaWritable(id, name, size, transport);
}

createBlobUploader(blob) {
Expand Down Expand Up @@ -123,8 +122,7 @@ class Metacom extends EventEmitter {
if (stream) {
console.error(new Error(`Stream ${name} is already initialized`));
} else {
const streamData = { id, name, size };
const stream = new MetaReadable(streamData);
const stream = new MetaReadable(id, name, size);
this.streams.set(id, stream);
}
} else if (!stream) {
Expand Down
8 changes: 4 additions & 4 deletions dist/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class MetaReadable extends EventEmitter {
}

class MetaWritable extends EventEmitter {
constructor(transport, options = {}) {
constructor(id, name, size, transport) {
super();
this.id = id;
this.name = name;
this.size = size;
this.transport = transport;
this.id = options.id;
this.name = options.name;
this.size = options.size;
this.init();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Metacom extends EventEmitter {

createStream(name, size) {
const id = ++this.streamId;
return new MetaWritable(this, { id, name, size });
return new MetaWritable(id, name, size, this);
}

createBlobUploader(blob) {
Expand Down
5 changes: 2 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class Client extends EventEmitter {
if (!name) throw new Error('Stream name is not provided');
if (!size) throw new Error('Stream size is not provided');
const id = --this.#streamId;
const packet = { id, name, size };
const stream = new MetaWritable(this.#transport, packet);
const stream = new MetaWritable(id, name, size, this.#transport);
this.streams.set(id, stream);
return stream;
}
Expand Down Expand Up @@ -296,7 +295,7 @@ class Server {
if (!valid) throw new Error('Stream packet structure error');
if (stream) throw new Error(`Stream ${tag} is already initialized`);
{
const stream = new MetaReadable({ id, name, size });
const stream = new MetaReadable(id, name, size);
client.streams.set(id, stream);
this.console.log(`${client.ip}\tstream ${tag} init`);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class MetaReadable extends EventEmitter {
}

class MetaWritable extends EventEmitter {
constructor(transport, options = {}) {
constructor(id, name, size, transport) {
super();
this.id = id;
this.name = name;
this.size = size;
this.transport = transport;
this.id = options.id;
this.name = options.name;
this.size = options.size;
this.init();
}

Expand Down
2 changes: 1 addition & 1 deletion test/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const createWritable = (id, name, size) => {
send: (packet) => writeBuffer.push(JSON.stringify(packet)),
write: (data) => writeBuffer.push(data),
};
const stream = new MetaWritable(transport, { id, name, size });
const stream = new MetaWritable(id, name, size, transport);
return [stream, writeBuffer];
};

Expand Down
Loading