6
6
import { User } from '@jupyterlab/services' ;
7
7
8
8
import { IDisposable } from '@lumino/disposable' ;
9
- import { IStream , Stream } from '@lumino/signaling' ;
10
9
11
10
import { IAwareness } from '@jupyter/ydoc' ;
12
11
13
- import * as decoding from 'lib0/decoding' ;
14
- import * as encoding from 'lib0/encoding' ;
15
12
import { WebsocketProvider } from 'y-websocket' ;
16
13
17
- import { MessageType } from './utils' ;
18
- import { IAwarenessProvider } from './tokens' ;
19
-
20
14
export interface IContent {
21
15
type : string ;
22
16
body : string ;
23
17
}
24
18
25
- export interface IChatMessage {
26
- sender : string ;
27
- timestamp : number ;
28
- content : IContent ;
29
- }
30
-
31
19
/**
32
20
* A class to provide Yjs synchronization over WebSocket.
33
21
*
@@ -36,7 +24,7 @@ export interface IChatMessage {
36
24
*/
37
25
export class WebSocketAwarenessProvider
38
26
extends WebsocketProvider
39
- implements IAwarenessProvider , IDisposable
27
+ implements IDisposable
40
28
{
41
29
/**
42
30
* Construct a new WebSocketAwarenessProvider
@@ -55,33 +43,12 @@ export class WebSocketAwarenessProvider
55
43
. then ( ( ) => this . _onUserChanged ( this . _user ) )
56
44
. catch ( e => console . error ( e ) ) ;
57
45
this . _user . userChanged . connect ( this . _onUserChanged , this ) ;
58
-
59
- this . _messageStream = new Stream ( this ) ;
60
-
61
- this . messageHandlers [ MessageType . CHAT ] = (
62
- encoder ,
63
- decoder ,
64
- provider ,
65
- emitSynced ,
66
- messageType
67
- ) => {
68
- const content = decoding . readVarString ( decoder ) ;
69
- const data = JSON . parse ( content ) as IChatMessage ;
70
- this . _messageStream . emit ( data ) ;
71
- } ;
72
46
}
73
47
74
48
get isDisposed ( ) : boolean {
75
49
return this . _isDisposed ;
76
50
}
77
51
78
- /**
79
- * A signal to subscribe for incoming messages.
80
- */
81
- get messageStream ( ) : IStream < this, IChatMessage > {
82
- return this . _messageStream ;
83
- }
84
-
85
52
dispose ( ) : void {
86
53
if ( this . _isDisposed ) {
87
54
return ;
@@ -92,31 +59,13 @@ export class WebSocketAwarenessProvider
92
59
this . destroy ( ) ;
93
60
}
94
61
95
- /**
96
- * Send a message to every collaborator.
97
- *
98
- * @param msg message
99
- */
100
- sendMessage ( msg : string ) : void {
101
- const data : IContent = {
102
- type : 'text' ,
103
- body : msg
104
- } ;
105
- const encoder = encoding . createEncoder ( ) ;
106
- encoding . writeVarUint ( encoder , MessageType . CHAT ) ;
107
- encoding . writeVarString ( encoder , JSON . stringify ( data ) ) ;
108
- this . ws ! . send ( encoding . toUint8Array ( encoder ) ) ;
109
- }
110
-
111
62
private _onUserChanged ( user : User . IManager ) : void {
112
63
this . _awareness . setLocalStateField ( 'user' , user . identity ) ;
113
64
}
114
65
115
66
private _isDisposed = false ;
116
67
private _user : User . IManager ;
117
68
private _awareness : IAwareness ;
118
-
119
- private _messageStream : Stream < this, IChatMessage > ;
120
69
}
121
70
122
71
/**
0 commit comments