Path: blob/main/src/vs/workbench/services/dataChannel/browser/dataChannelService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Emitter } from '../../../../base/common/event.js';6import { Disposable } from '../../../../base/common/lifecycle.js';7import { IDataChannelService, CoreDataChannel, IDataChannelEvent } from '../../../../platform/dataChannel/common/dataChannel.js';8import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';910export class DataChannelService extends Disposable implements IDataChannelService {11declare readonly _serviceBrand: undefined;1213private readonly _onDidSendData = this._register(new Emitter<IDataChannelEvent>());14readonly onDidSendData = this._onDidSendData.event;1516constructor() {17super();18}1920getDataChannel<T>(channelId: string): CoreDataChannel<T> {21return new CoreDataChannelImpl<T>(channelId, this._onDidSendData);22}23}2425class CoreDataChannelImpl<T> implements CoreDataChannel<T> {26constructor(27private readonly channelId: string,28private readonly _onDidSendData: Emitter<IDataChannelEvent>29) { }3031sendData(data: T): void {32this._onDidSendData.fire({33channelId: this.channelId,34data35});36}37}3839registerSingleton(IDataChannelService, DataChannelService, InstantiationType.Delayed);404142