Skip to content

Commit

Permalink
Fix streams signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
tshemsedinov committed Mar 26, 2024
1 parent 47d3b35 commit e33d146
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
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

0 comments on commit e33d146

Please sign in to comment.