From 2f49511e43b3c60afe1d405be7fadb99cd66ff3f Mon Sep 17 00:00:00 2001 From: jinpill Date: Fri, 30 Aug 2024 02:45:46 +0900 Subject: [PATCH] fix: resolve the error caused by named import To resolve an error that occurs when importing the setup method in an mjs file, the way of importing the protobuf module has been modified. --- src/core/client.ts | 6 +++--- src/core/utils/parser.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/client.ts b/src/core/client.ts index 95e75cf..0fd6077 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -3,7 +3,7 @@ import Long from 'long'; import path from 'path'; import tls from 'tls'; import net from 'net'; -import { load, Root } from 'protobufjs'; +import protobuf from 'protobufjs'; import { EVENTS } from './events.d.js'; import { checkIn, type CheckInOptions } from './gcm/index.js'; @@ -15,7 +15,7 @@ const HOST = 'mtalk.google.com'; const PORT = 5228; const MAX_RETRY_TIMEOUT = 15; -let proto: Root | null = null; +let proto: protobuf.Root | null = null; export interface Credentials { gcm: { @@ -45,7 +45,7 @@ export class Client extends EventEmitter { if (proto) { return; } - proto = await load(path.resolve(__dirname, 'utils', 'mcs.proto')); + proto = await protobuf.load(path.resolve(__dirname, 'utils', 'mcs.proto')); } constructor(credentials: Credentials, persistentIds: string[]) { diff --git a/src/core/utils/parser.ts b/src/core/utils/parser.ts index 246083a..ccebf82 100644 --- a/src/core/utils/parser.ts +++ b/src/core/utils/parser.ts @@ -1,6 +1,6 @@ import EventEmitter from 'events'; import path from 'path'; -import { load, BufferReader, Root } from 'protobufjs'; +import protobuf from 'protobufjs'; import { ProcessingState, kVersionPacketLen, @@ -13,7 +13,7 @@ import { const DEBUG_ENABLED = false; const DEBUG = DEBUG_ENABLED ? console.log : (log: string): void => {}; -let proto: Root | null = null; +let proto: protobuf.Root | null = null; // Parser parses wire data from gcm. // This takes the role of WaitForData in the chromium connection handler. @@ -39,7 +39,7 @@ export default class Parser extends EventEmitter { if (proto) { return; } - proto = await load(path.resolve(__dirname, 'mcs.proto')); + proto = await protobuf.load(path.resolve(__dirname, 'mcs.proto')); } constructor(socket: any) { @@ -149,7 +149,7 @@ export default class Parser extends EventEmitter { private _onGotMessageSize(): void { let incompleteSizePacket = false; - const reader = new BufferReader(this._data); + const reader = new protobuf.BufferReader(this._data); try { this._messageSize = reader.int32();