@@ -15,6 +15,7 @@ import { logger } from '../helpers/logger.js'
1515import type { ShallowRef } from 'vue'
1616import type { InitialData , Connection } from '../composables/useConnection.js'
1717import { close } from '../apis/Connect.js'
18+ import { push } from '../apis/Sync.js'
1819
1920/**
2021 * Timeout after which the editor will consider a document without changes being synced as idle
@@ -51,7 +52,7 @@ const ERROR_TYPE = {
5152/*
5253 * Step as what we expect to be returned from the server right now.
5354 */
54- interface Step {
55+ export interface Step {
5556 data : string [ ]
5657 version : number
5758 sessionId : number
@@ -109,7 +110,7 @@ export declare type EventTypes = {
109110}
110111
111112class SyncService {
112- # connection: ShallowRef < Connection | undefined >
113+ connection : ShallowRef < Connection | undefined >
113114 sessionConnection ?: SessionConnection
114115 version = - 1
115116 pushError = 0
@@ -120,24 +121,16 @@ class SyncService {
120121 #openConnection: ( ) => Promise < InitialData >
121122 #lastStepPush = Date . now ( )
122123 #sending = false
123- #filePath?: string
124- #shareToken?: string
125124
126125 constructor ( {
127126 connection,
128127 openConnection,
129- filePath,
130- shareToken,
131128 } : {
132129 connection : ShallowRef < Connection | undefined >
133130 openConnection : ( ) => Promise < InitialData >
134- filePath ?: string
135- shareToken ?: string
136131 } ) {
137- this . # connection = connection
132+ this . connection = connection
138133 this . #openConnection = openConnection
139- this . #filePath = filePath
140- this . #shareToken = shareToken
141134 }
142135
143136 get isReadOnly ( ) {
@@ -152,7 +145,10 @@ class SyncService {
152145 return this . sessionConnection ?. session . guestName
153146 }
154147
155- hasActiveConnection ( ) : this is { sessionConnection : SessionConnection } {
148+ hasActiveConnection ( ) : this is {
149+ sessionConnection : SessionConnection
150+ connection : ShallowRef < Connection >
151+ } {
156152 return ! ! this . sessionConnection && ! this . sessionConnection . isClosed
157153 }
158154
@@ -165,8 +161,10 @@ class SyncService {
165161 // Error was already emitted above
166162 return
167163 }
168- const options = { shareToken : this . #shareToken, filePath : this . #filePath }
169- this . sessionConnection = new SessionConnection ( { data } , options )
164+ this . sessionConnection = new SessionConnection ( {
165+ data,
166+ connection : this . connection . value ,
167+ } )
170168 this . backend = new PollingBackend ( this , this . sessionConnection )
171169 this . version = this . sessionConnection . docStateVersion
172170 this . emit ( 'opened' , this . sessionConnection . state )
@@ -226,8 +224,10 @@ class SyncService {
226224 if ( ! this . hasActiveConnection ( ) ) {
227225 return
228226 }
229- return this . sessionConnection
230- . push ( { ...sendable , version : this . version } )
227+ return push ( this . connection , {
228+ version : this . version ,
229+ ...sendable ,
230+ } )
231231 . then ( ( response ) => {
232232 this . #outbox. clearSentData ( sendable )
233233 const { steps, documentState } = response . data as {
@@ -350,8 +350,8 @@ class SyncService {
350350 async close ( ) {
351351 // Make sure to leave no pending requests behind.
352352 this . backend ?. disconnect ( )
353- if ( this . # connection. value ) {
354- close ( this . # connection. value )
353+ if ( this . connection . value ) {
354+ close ( this . connection . value )
355355 // Log and ignore possible network issues.
356356 . catch ( ( e ) => {
357357 logger . info ( 'Failed to close connection.' , { e } )
0 commit comments