Skip to content

Commit

Permalink
maxim pr
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Sep 18, 2024
1 parent 36fd416 commit 3f34f81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions rpc/js/src/BaseStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ let MaxMessageSize = 1 << 25;

export class BaseStream {
protected readonly grpcStream: Stream;
private readonly onDone: (id: number) => void;
private readonly onDone: (id: bigint) => void;
protected closed: boolean = false;
private readonly packetBuf: Array<Uint8Array> = [];
private packetBufSize = 0;

constructor(grpcStream: Stream, onDone: (id: number) => void) {
constructor(grpcStream: Stream, onDone: (id: bigint) => void) {
this.grpcStream = grpcStream;
this.onDone = onDone;
}
Expand All @@ -20,7 +20,7 @@ export class BaseStream {
return;
}
this.closed = true;
this.onDone(Number(this.grpcStream.id));
this.onDone(this.grpcStream.id);
}

protected processPacketMessage(msg: PacketMessage): Uint8Array | undefined {
Expand Down
14 changes: 7 additions & 7 deletions rpc/js/src/ClientChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface activeClienStream {

export class ClientChannel extends BaseChannel implements Transport {
private streamIDCounter = 0;
private readonly streams: Record<number, activeClienStream> = {};
private readonly streams: Record<string, activeClienStream> = {};

constructor(pc: RTCPeerConnection, dc: RTCDataChannel) {
super(pc, dc);
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ClientChannel extends BaseChannel implements Transport {
}

const { id } = stream;
const activeStream = this.streams[Number(id)];
const activeStream = this.streams[id.toString()];
if (activeStream === undefined) {
console.error('no stream for id; discarding', 'id', id);
return;
Expand All @@ -95,22 +95,22 @@ export class ClientChannel extends BaseChannel implements Transport {
new ConnectionClosedError('connection closed')
);
}
let activeStream = this.streams[Number(stream.id)];
let activeStream = this.streams[stream.id.toString()];
if (activeStream === undefined) {
if (Object.keys(this.streams).length > MaxStreamCount) {
return new FailingClientStream(new Error('stream limit hit'));
}
const clientStream = new ClientStream(this, stream, (id: number) =>
const clientStream = new ClientStream(this, stream, (id: bigint) =>
this.removeStreamByID(id)
);
activeStream = { cs: clientStream };
this.streams[Number(stream.id)] = activeStream;
this.streams[stream.id.toString()] = activeStream;
}
return activeStream.cs;
}

private removeStreamByID(id: number) {
delete this.streams[id];
private removeStreamByID(id: bigint) {
delete this.streams[id.toString()];
}

public writeHeaders(stream: Stream, headers: RequestHeaders) {
Expand Down
2 changes: 1 addition & 1 deletion rpc/js/src/ClientStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ClientStream extends BaseStream implements Transport {
constructor(
channel: ClientChannel,
stream: Stream,
onDone: (id: number) => void
onDone: (id: bigint) => void
) {
super(stream, onDone);
this.channel = channel;
Expand Down

0 comments on commit 3f34f81

Please sign in to comment.