Skip to content

Commit

Permalink
Remove unused chat feature (#346)
Browse files Browse the repository at this point in the history
* Remove unused chat feature

* Review
  • Loading branch information
davidbrochart authored Sep 9, 2024
1 parent 1492678 commit 0754bc7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 80 deletions.
53 changes: 1 addition & 52 deletions packages/docprovider/src/awareness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@
import { User } from '@jupyterlab/services';

import { IDisposable } from '@lumino/disposable';
import { IStream, Stream } from '@lumino/signaling';

import { IAwareness } from '@jupyter/ydoc';

import * as decoding from 'lib0/decoding';
import * as encoding from 'lib0/encoding';
import { WebsocketProvider } from 'y-websocket';

import { MessageType } from './utils';
import { IAwarenessProvider } from './tokens';

export interface IContent {
type: string;
body: string;
}

export interface IChatMessage {
sender: string;
timestamp: number;
content: IContent;
}

/**
* A class to provide Yjs synchronization over WebSocket.
*
Expand All @@ -36,7 +24,7 @@ export interface IChatMessage {
*/
export class WebSocketAwarenessProvider
extends WebsocketProvider
implements IAwarenessProvider, IDisposable
implements IDisposable
{
/**
* Construct a new WebSocketAwarenessProvider
Expand All @@ -55,33 +43,12 @@ export class WebSocketAwarenessProvider
.then(() => this._onUserChanged(this._user))
.catch(e => console.error(e));
this._user.userChanged.connect(this._onUserChanged, this);

this._messageStream = new Stream(this);

this.messageHandlers[MessageType.CHAT] = (
encoder,
decoder,
provider,
emitSynced,
messageType
) => {
const content = decoding.readVarString(decoder);
const data = JSON.parse(content) as IChatMessage;
this._messageStream.emit(data);
};
}

get isDisposed(): boolean {
return this._isDisposed;
}

/**
* A signal to subscribe for incoming messages.
*/
get messageStream(): IStream<this, IChatMessage> {
return this._messageStream;
}

dispose(): void {
if (this._isDisposed) {
return;
Expand All @@ -92,31 +59,13 @@ export class WebSocketAwarenessProvider
this.destroy();
}

/**
* Send a message to every collaborator.
*
* @param msg message
*/
sendMessage(msg: string): void {
const data: IContent = {
type: 'text',
body: msg
};
const encoder = encoding.createEncoder();
encoding.writeVarUint(encoder, MessageType.CHAT);
encoding.writeVarString(encoder, JSON.stringify(data));
this.ws!.send(encoding.toUint8Array(encoder));
}

private _onUserChanged(user: User.IManager): void {
this._awareness.setLocalStateField('user', user.identity);
}

private _isDisposed = false;
private _user: User.IManager;
private _awareness: IAwareness;

private _messageStream: Stream<this, IChatMessage>;
}

/**
Expand Down
20 changes: 0 additions & 20 deletions packages/docprovider/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { DocumentChange, IAwareness, YDocument } from '@jupyter/ydoc';
import { Contents } from '@jupyterlab/services';

import { Token } from '@lumino/coreutils';
import { IStream } from '@lumino/signaling';

import { IChatMessage } from './awareness';

/**
* The collaborative drive.
Expand Down Expand Up @@ -56,20 +53,3 @@ export interface ISharedModelFactory extends Contents.ISharedFactory {
factory: SharedDocumentFactory
): void;
}

/**
* A provider interface for global awareness features.
*/
export interface IAwarenessProvider {
/**
* A signal to subscribe for incoming messages.
*/
readonly messageStream: IStream<this, IChatMessage>;

/**
* Send a message to every collaborator.
*
* @param msg message
*/
sendMessage(msg: string): void;
}
8 changes: 0 additions & 8 deletions packages/docprovider/src/utils.ts

This file was deleted.

0 comments on commit 0754bc7

Please sign in to comment.