Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ICodeEditor } from '@opensumi/ide-monaco';
import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';

import { TextModelBinding } from '../../src/browser/textmodel-binding';
import { ICollaborationService } from '../../src/common';
import { ICollaborationService, COLLABORATION_PORT } from '../../src/common';

const injector = new Injector();

Expand Down Expand Up @@ -48,7 +48,7 @@ describe('TextModelBinding test for yText and TextModel', () => {

beforeEach(() => {
doc = new YDoc();
wsProvider = new WebsocketProvider('ws://127.0.0.1:12345', 'test', doc, { connect: false }); // we don't use wsProvider here
wsProvider = new WebsocketProvider(`ws://127.0.0.1:${COLLABORATION_PORT}`, 'test', doc, { connect: false }); // we don't use wsProvider here
user1 = createBindingWithTextModel(doc, wsProvider.awareness);
user2 = createBindingWithTextModel(doc, wsProvider.awareness);
jest.mock('@opensumi/di');
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('TextModelBinding test for editor', () => {

beforeAll(() => {
doc = new YDoc();
const wsProvider = new WebsocketProvider('ws://127.0.0.1:12345', 'test', doc, { connect: false });
const wsProvider = new WebsocketProvider(`ws://127.0.0.1:${COLLABORATION_PORT}`, 'test', doc, { connect: false });

const {
binding: _binding,
Expand Down
19 changes: 15 additions & 4 deletions packages/collaboration/src/browser/collaboration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,24 @@ export class CollaborationService extends WithEventBus implements ICollaboration
}

initialize() {
/**
* 优先使用 appConfig.collaborationWsPath 配置
* 如果没有该配置才根据 wsPath 去转换端口
*/
const { collaborationWsPath, wsPath } = this.appConfig;
let serverUrl: string | undefined = collaborationWsPath;

if (!serverUrl) {
const path = new URL(wsPath.toString());
path.port = String(COLLABORATION_PORT);

serverUrl = path.toString();
}

this.yDoc = new YDoc();
this.yTextMap = this.yDoc.getMap();

// transform url
const wsPath = new URL(this.appConfig.wsPath.toString());
wsPath.port = String(COLLABORATION_PORT);
this.yWebSocketProvider = new WebsocketProvider(wsPath.toString(), ROOM_NAME, this.yDoc);
this.yWebSocketProvider = new WebsocketProvider(serverUrl.toString(), ROOM_NAME, this.yDoc);

this.yTextMap.observe(this.yMapObserver);

Expand Down
6 changes: 3 additions & 3 deletions packages/collaboration/src/node/y-websocket-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { INodeLogger } from '@opensumi/ide-core-node';
import { FileChangeType, IFileService } from '@opensumi/ide-file-service';
import { FileService } from '@opensumi/ide-file-service/lib/node';

import { IYWebsocketServer, ROOM_NAME } from '../common';
import { COLLABORATION_PORT, IYWebsocketServer, ROOM_NAME } from '../common';

@Injectable()
export class YWebsocketServerImpl implements IYWebsocketServer {
Expand Down Expand Up @@ -52,8 +52,8 @@ export class YWebsocketServerImpl implements IYWebsocketServer {
this.websocketServer.handleUpgrade(req, socket, head, handleAuth);
});

this.server.listen(12345, () => {
this.logger.log('y-websocket server listening on port 12345');
this.server.listen(COLLABORATION_PORT, () => {
this.logger.log(`y-websocket server listening on port ${COLLABORATION_PORT}`);
});

// init
Expand Down
5 changes: 5 additions & 0 deletions packages/core-browser/src/react-providers/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ export interface AppConfig {
* 该配置默认值仅在首次启动时进行同步,后续的更改将不会带来任何效果,即框架本身将不监听 `.vscode` 内的文件变化
*/
useVSCodeWorkspaceConfiguration?: boolean;
/*
* 定义协同模块的通信路径
* 需要带端口号, 默认是 12345,可使用 COLLABORATION_PORT 字段来指定
*/
collaborationWsPath?: string;
}

export const ConfigContext = React.createContext<AppConfig>({
Expand Down