diff --git a/packages/connection/src/browser/connect.ts b/packages/connection/src/browser/connect.ts deleted file mode 100644 index d0077453be3..00000000000 --- a/packages/connection/src/browser/connect.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type net from 'net'; - -import { - SocketMessageReader, - SocketMessageWriter, - createMessageConnection, -} from '@opensumi/vscode-jsonrpc/lib/node/main'; - -/** - * 由于 `@opensumi/vscode-jsonrpc/lib/browser/main` 下对于 RAL(runtime abstraction layer) - * 的消息传递时会忽略 `options.charset !== 'utf-8'` 的消息,故导致 WS 等消息收发异常 - * 该逻辑受加载时序影响,原有的逻辑会导致在 `packages/core-browser/src/bootstrap/connection.ts` 执行的情况下 - * 导致首次消息收发异常 - */ -export function createSocketConnection(socket: net.Socket) { - return createMessageConnection(new SocketMessageReader(socket), new SocketMessageWriter(socket)); -} diff --git a/packages/connection/src/browser/index.ts b/packages/connection/src/browser/index.ts index dc7fe4c0618..6b1bce253ce 100644 --- a/packages/connection/src/browser/index.ts +++ b/packages/connection/src/browser/index.ts @@ -1,2 +1 @@ export * from './ws-channel-handler'; -export * from './connect'; diff --git a/packages/connection/src/common/message.ts b/packages/connection/src/common/message.ts index d01ec2f1bb6..8ebea52c856 100644 --- a/packages/connection/src/common/message.ts +++ b/packages/connection/src/common/message.ts @@ -6,6 +6,12 @@ import { import { Disposable } from '@opensumi/vscode-jsonrpc/lib/common/disposable'; import { MessageReader, DataCallback } from '@opensumi/vscode-jsonrpc/lib/common/messageReader'; import { MessageWriter } from '@opensumi/vscode-jsonrpc/lib/common/messageWriter'; +/** + * 由于 `createMessageConnection` 方法隐式依赖了 `@opensumi/vscode-jsonrpc/lib/browser/main` 或 `@opensumi/vscode-jsonrpc/lib/node/main` + * 的初始化 `RIL.install()` 初始化代码,而 `browser/main` 中仅支持浏览器使用 + * 故需要保证提前引入或执行一次 `@opensumi/vscode-jsonrpc/lib/node/main` 代码才能保证逻辑正常执行 + */ +import '@opensumi/vscode-jsonrpc/lib/node/main'; export class WebSocketMessageReader extends AbstractMessageReader implements MessageReader { protected state: 'initial' | 'listening' | 'closed' = 'initial'; diff --git a/packages/core-browser/src/bootstrap/connection.ts b/packages/core-browser/src/bootstrap/connection.ts index c6bf6385c1c..e1fb3629a50 100644 --- a/packages/core-browser/src/bootstrap/connection.ts +++ b/packages/core-browser/src/bootstrap/connection.ts @@ -1,6 +1,6 @@ import { Injector, Provider } from '@opensumi/di'; import { RPCServiceCenter, initRPCService, RPCMessageConnection } from '@opensumi/ide-connection'; -import { createSocketConnection, WSChannelHandler } from '@opensumi/ide-connection/lib/browser'; +import { WSChannelHandler } from '@opensumi/ide-connection/lib/browser'; import { createWebSocketConnection } from '@opensumi/ide-connection/lib/common/message'; import { getDebugLogger, @@ -63,13 +63,6 @@ export async function createClientConnection2( bindConnectionService(injector, modules, createWebSocketConnection(channel)); } -/** - * electron 环境下不要调用这个函数,该函数的 createSocketConnection 是 browser 环境下的 - */ -export async function createNetClientConnection(injector: Injector, modules: ModuleConstructor[], connection: any) { - bindConnectionService(injector, modules, createSocketConnection(connection)); -} - export async function bindConnectionService( injector: Injector, modules: ModuleConstructor[],