Commit 027d4e8d authored by nanahira's avatar nanahira

no send after disconnect

parent 2ffbaaf2
......@@ -19,6 +19,7 @@ import { I18nService } from './i18n';
import { Chnroute } from './chnroute';
import YGOProDeck from 'ygopro-deck-encode';
import PQueue from 'p-queue';
import { ClientRoomField } from '../utility/decorators';
export abstract class Client {
protected abstract _send(data: Buffer): Promise<void>;
......@@ -72,7 +73,10 @@ export abstract class Client {
return this;
}
disconnected = false;
disconnect(): undefined {
this.disconnected = true;
this.disconnectSubject.next();
this.disconnectSubject.complete();
this._disconnect().then();
......@@ -82,6 +86,9 @@ export abstract class Client {
private sendQueue = new PQueue({ concurrency: 1 });
async send(data: YGOProStocBase) {
if (this.disconnected) {
return;
}
return this.sendQueue.add(async () => {
try {
await this._send(Buffer.from(data.toFullPayload()));
......@@ -139,10 +146,15 @@ export abstract class Client {
established = false;
// in room
@ClientRoomField()
roomName?: string;
@ClientRoomField()
isHost = false;
@ClientRoomField()
pos = -1;
@ClientRoomField()
deck?: YGOProDeck;
@ClientRoomField()
startDeck?: YGOProDeck;
async sendTypeChange() {
......
......@@ -8,3 +8,6 @@ export interface RoomMethodOptions {
export const RoomMethod = (options: RoomMethodOptions = {}): MethodDecorator =>
Metadata.set('roomMethod', options, 'roomMethodKeys');
export const ClientRoomField = (): PropertyDecorator =>
Metadata.set('clientRoomField', true, 'clientRoomFieldKeys');
......@@ -3,6 +3,7 @@ import type { RoomMethodOptions } from './decorators';
interface MetadataMap {
roomMethod: RoomMethodOptions;
clientRoomField: true;
}
type MetadataArrayMap = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment