@@ -10,22 +10,37 @@ const ws = require("ws");
10
10
const {
11
11
stroveLiveshareSubscription,
12
12
liveshareActivity,
13
+ focusEditorSubscription,
13
14
} = require ( "./utils/queries" ) ;
14
15
const { websocketEndpoint } = require ( "./utils/endpoints" ) ;
15
16
const { handleLiveshareResponse } = require ( "./utils/handleLiveshareResponse" ) ;
17
+ const { handleFocusEditor } = require ( "./utils/handleFocusEditor" ) ;
16
18
17
19
const environment = process . env . STROVE_ENVIRONMENT ;
18
20
19
21
const client = new SubscriptionClient (
20
22
websocketEndpoint ,
21
23
{
22
24
reconnect : true ,
25
+ connectionParams : ( ) => ( {
26
+ authorization : process . env . STROVE_USER_TOKEN
27
+ ? `Bearer ${ process . env . STROVE_USER_TOKEN } `
28
+ : "" ,
29
+ } ) ,
23
30
} ,
24
31
ws
25
32
) ;
26
33
27
34
const link = new WebSocketLink ( client ) ;
28
35
36
+ ///
37
+ // context = {
38
+ // headers: {
39
+ // Authorization: `Bearer ${user.githubToken}`,
40
+ // 'User-Agent': 'node',
41
+ // },
42
+ // }
43
+
29
44
try {
30
45
const liveshareActivityUpdate = ( data ) => {
31
46
const liveshareActivityOperation = {
72
87
console . log ( "stroveteams extension is active" ) ;
73
88
74
89
// First call to get cursor positions of other users
75
- liveshareActivityInit ( ) ;
90
+ // It doesn't seem to work - my assumption:
91
+ // it gets called before subscription is set up and the info gets lost, hence setTimeout
92
+ setTimeout ( liveshareActivityInit , 1000 ) ;
76
93
77
94
vscode . window . onDidChangeTextEditorSelection (
78
95
( { textEditor, selections } ) => {
@@ -127,16 +144,42 @@ try {
127
144
128
145
handleLiveshareResponse ( stroveLiveshare ) ;
129
146
} ,
130
- error : ( error ) => console . log ( `received error ${ error } ` ) ,
147
+ error : ( error ) =>
148
+ console . log ( `received error in liveshareSubscriber ${ error } ` ) ,
131
149
complete : ( ) => console . log ( `complete` ) ,
132
150
}
133
151
) ;
134
152
153
+ const focusEditorOperation = {
154
+ query : focusEditorSubscription ,
155
+ variables : {
156
+ userId : process . env . STROVE_USER_ID || "123" ,
157
+ projectId : process . env . STROVE_PROJECT_ID || "123abc" ,
158
+ } ,
159
+ } ;
160
+
161
+ const focusEditorSubscriber = execute ( link , focusEditorOperation ) . subscribe ( {
162
+ next : async ( data ) => {
163
+ const {
164
+ data : { focusEditor } ,
165
+ } = data ;
166
+
167
+ handleFocusEditor ( {
168
+ uri : focusEditor . documentPath ,
169
+ userPosition : focusEditor . selections ,
170
+ } ) ;
171
+ } ,
172
+ error : ( error ) =>
173
+ console . log ( `received error in focusEditorSubscriber ${ error } ` ) ,
174
+ complete : ( ) => console . log ( `complete` ) ,
175
+ } ) ;
176
+
135
177
exports . activate = activate ;
136
178
137
179
// this method is called when your extension is deactivated
138
180
function deactivate ( ) {
139
181
liveshareSubscriber . unsubscribe ( ) ;
182
+ focusEditorSubscriber . unsubscribe ( ) ;
140
183
}
141
184
142
185
module . exports = {
0 commit comments