Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/dataChannel/browser/dataChannelService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Emitter } from '../../../../base/common/event.js';
7
import { Disposable } from '../../../../base/common/lifecycle.js';
8
import { IDataChannelService, CoreDataChannel, IDataChannelEvent } from '../../../../platform/dataChannel/common/dataChannel.js';
9
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
10
11
export class DataChannelService extends Disposable implements IDataChannelService {
12
declare readonly _serviceBrand: undefined;
13
14
private readonly _onDidSendData = this._register(new Emitter<IDataChannelEvent>());
15
readonly onDidSendData = this._onDidSendData.event;
16
17
constructor() {
18
super();
19
}
20
21
getDataChannel<T>(channelId: string): CoreDataChannel<T> {
22
return new CoreDataChannelImpl<T>(channelId, this._onDidSendData);
23
}
24
}
25
26
class CoreDataChannelImpl<T> implements CoreDataChannel<T> {
27
constructor(
28
private readonly channelId: string,
29
private readonly _onDidSendData: Emitter<IDataChannelEvent>
30
) { }
31
32
sendData(data: T): void {
33
this._onDidSendData.fire({
34
channelId: this.channelId,
35
data
36
});
37
}
38
}
39
40
registerSingleton(IDataChannelService, DataChannelService, InstantiationType.Delayed);
41
42