@@ -34,8 +34,10 @@ class CozyRealtime {
34
34
* @param {CozyClient } options.client A cozy-client instance
35
35
* @param {Function } [options.createWebSocket] The function used to create WebSocket instances
36
36
* @param {object } [options.logger] A custom logger
37
+ * @param {string } [options.sharedDriveId] - The ID of the shared drive to connect to
37
38
*/
38
39
constructor ( options ) {
40
+ this . sharedDriveId = options . sharedDriveId
39
41
this . client = getCozyClientFromOptions ( options )
40
42
this . createWebSocket = options . createWebSocket || createWebSocket
41
43
this . logger = options . logger || defaultLogger
@@ -83,7 +85,7 @@ class CozyRealtime {
83
85
this . revokeWebSocket ( )
84
86
}
85
87
this . logger . info ( 'creating a new websocket…' )
86
- const url = getUrl ( this . client )
88
+ const url = getUrl ( this . client , this . sharedDriveId )
87
89
try {
88
90
this . websocket = this . createWebSocket ( url , protocol )
89
91
this . websocket . authenticated = false
@@ -295,7 +297,7 @@ class CozyRealtime {
295
297
const has = this . subscriptions . hasSameTypeAndId ( sub )
296
298
this . subscriptions . add ( sub )
297
299
// send to the server if there wasn't any subscription with that type & id before
298
- if ( ! has && this . isWebSocketAuthenticated ( ) ) {
300
+ if ( ! this . sharedDriveId && ! has && this . isWebSocketAuthenticated ( ) ) {
299
301
this . sendSubscription ( sub . type , sub . id )
300
302
}
301
303
}
@@ -316,7 +318,7 @@ class CozyRealtime {
316
318
// if there is no more subscription of this type & id
317
319
// then unsubscribe to the server
318
320
const has = this . subscriptions . hasSameTypeAndId ( sub )
319
- if ( ! has && this . isWebSocketAuthenticated ( ) ) {
321
+ if ( ! this . sharedDriveId && ! has && this . isWebSocketAuthenticated ( ) ) {
320
322
this . sendUnsubscription ( sub . type , sub . id )
321
323
}
322
324
// if this was the last subscription, stop the realtime
0 commit comments