Skip to content

Commit e8b161a

Browse files
committed
fix: lint & tsc errors
1 parent bb50871 commit e8b161a

File tree

7 files changed

+63
-63
lines changed

7 files changed

+63
-63
lines changed

src/server.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class YWebsocketServer {
2020
/**
2121
* @param {uws.TemplatedApp} app
2222
*/
23-
constructor(app) {
23+
constructor (app) {
2424
this.app = app
2525
}
2626

27-
async destroy() {
27+
async destroy () {
2828
this.app.close()
2929
}
3030
}
@@ -40,7 +40,7 @@ export const createYWebsocketServer = async ({
4040
redisPrefix = 'y',
4141
port,
4242
store,
43-
checkPermCallbackUrl,
43+
checkPermCallbackUrl
4444
}) => {
4545
checkPermCallbackUrl += checkPermCallbackUrl.slice(-1) !== '/' ? '/' : ''
4646
const app = uws.App({})
@@ -72,7 +72,7 @@ export const createYWebsocketServer = async ({
7272
return {
7373
hasWriteAccess: perm.yaccess === 'rw',
7474
room,
75-
userid: perm.yuserid || '',
75+
userid: perm.yuserid || ''
7676
}
7777
} catch (e) {
7878
console.error('Failed to pull permissions from', { permUrl })
@@ -106,7 +106,7 @@ export const createYWebsocketServer = async ({
106106
export const createYSocketIOServer = async ({
107107
redisPrefix = 'y',
108108
port,
109-
store,
109+
store
110110
}) => {
111111
const httpServer = http.createServer((req, res) => {
112112
res.writeHead(200, { 'Content-Type': 'application/json' })
@@ -117,7 +117,7 @@ export const createYSocketIOServer = async ({
117117
const server = await registerYSocketIOServer(io, store, {
118118
redisPrefix,
119119
authenticate: async (socket) => {
120-
const token = socket.handshake.query['yauth']
120+
const token = socket.handshake.query.yauth
121121
if (!token) return null
122122
// verify that the user has a valid token
123123
const { payload: userToken } = await jwt.verifyJwt(
@@ -126,7 +126,7 @@ export const createYSocketIOServer = async ({
126126
)
127127
if (!userToken.yuserid) return null
128128
return { userid: userToken.yuserid }
129-
},
129+
}
130130
})
131131

132132
httpServer.listen(port, undefined, undefined, () => {

src/socketio.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import * as api from './api.js'
2-
import * as logging from 'lib0/logging'
31
import { YSocketIO } from './y-socket-io/y-socket-io.js'
4-
import { randomUUID } from 'crypto'
5-
6-
const log = logging.createModuleLogger('@y/redis/ws')
72

83
/**
94
* how to sync
@@ -20,16 +15,16 @@ const log = logging.createModuleLogger('@y/redis/ws')
2015
class YSocketIOServer {
2116
/**
2217
* @param {YSocketIO} app
23-
* @param {api.Api} client
18+
* @param {import('./api.js').Api} client
2419
* @param {import('./subscriber.js').Subscriber} subscriber
2520
*/
26-
constructor(app, client, subscriber) {
21+
constructor (app, client, subscriber) {
2722
this.app = app
2823
this.subscriber = subscriber
2924
this.client = client
3025
}
3126

32-
async destroy() {
27+
async destroy () {
3328
this.subscriber.destroy()
3429
await this.client.destroy()
3530
}

src/y-socket-io/client.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as Y from 'yjs'
22
import * as bc from 'lib0/broadcastchannel'
33
import * as AwarenessProtocol from 'y-protocols/awareness'
44
import { Observable } from 'lib0/observable'
5-
import { io, Socket } from 'socket.io-client'
5+
import { io } from 'socket.io-client'
6+
7+
/**
8+
* @typedef {import('socket.io-client').Socket} ClientSocket
9+
*/
610

711
/**
812
* @typedef ProviderConfiguration
@@ -59,7 +63,7 @@ export class SocketIOProvider extends Observable {
5963
_broadcastChannel
6064
/**
6165
* The socket connection
62-
* @type {Socket}
66+
* @type {ClientSocket}
6367
* @public
6468
*/
6569
socket
@@ -116,7 +120,7 @@ export class SocketIOProvider extends Observable {
116120
* @param {ProviderConfiguration=} options Configuration options to the SocketIOProvider
117121
* @param {Partial<import('socket.io-client').ManagerOptions & import('socket.io-client').SocketOptions>=} socketIoOptions optional overrides for socket.io
118122
*/
119-
constructor(
123+
constructor (
120124
url,
121125
roomName,
122126
doc = new Y.Doc(),
@@ -125,7 +129,7 @@ export class SocketIOProvider extends Observable {
125129
awareness = new AwarenessProtocol.Awareness(doc),
126130
resyncInterval = -1,
127131
disableBc = false,
128-
auth = {},
132+
auth = {}
129133
} = {},
130134
socketIoOptions = undefined
131135
) {
@@ -146,8 +150,8 @@ export class SocketIOProvider extends Observable {
146150
autoConnect: false,
147151
transports: ['websocket'],
148152
forceNew: true,
149-
auth: auth,
150-
...socketIoOptions,
153+
auth,
154+
...socketIoOptions
151155
})
152156
this._socketIoOptions = socketIoOptions
153157

@@ -176,30 +180,30 @@ export class SocketIOProvider extends Observable {
176180
* Broadcast channel room getter
177181
* @type {string}
178182
*/
179-
get broadcastChannel() {
183+
get broadcastChannel () {
180184
return this._broadcastChannel
181185
}
182186

183187
/**
184188
* URL getter
185189
* @type {string}
186190
*/
187-
get url() {
191+
get url () {
188192
return this._url
189193
}
190194

191195
/**
192196
* Synchronized state flag getter
193197
* @type {boolean}
194198
*/
195-
get synced() {
199+
get synced () {
196200
return this._synced
197201
}
198202

199203
/**
200204
* Synchronized state flag setter
201205
*/
202-
set synced(state) {
206+
set synced (state) {
203207
if (this._synced !== state) {
204208
this._synced = state
205209
this.emit('synced', [state])
@@ -272,17 +276,14 @@ export class SocketIOProvider extends Observable {
272276
* @readonly
273277
*/
274278
initSystemListeners = () => {
275-
if (typeof window !== 'undefined')
276-
window.addEventListener('beforeunload', this.beforeUnloadHandler)
277-
else if (typeof process !== 'undefined')
278-
process.on('exit', this.beforeUnloadHandler)
279+
if (typeof window !== 'undefined') { window.addEventListener('beforeunload', this.beforeUnloadHandler) } else if (typeof process !== 'undefined') { process.on('exit', this.beforeUnloadHandler) }
279280
}
280281

281282
/**
282283
* Connect provider's socket
283284
* @type {() => void}
284285
*/
285-
connect() {
286+
connect () {
286287
if (!this.socket.connected) {
287288
this.emit('status', [{ status: 'connecting' }])
288289
this.socket.connect()
@@ -313,7 +314,7 @@ export class SocketIOProvider extends Observable {
313314
this.socket.emit(
314315
'awareness-update',
315316
AwarenessProtocol.encodeAwarenessUpdate(this.awareness, [
316-
this.doc.clientID,
317+
this.doc.clientID
317318
])
318319
)
319320
}
@@ -335,7 +336,7 @@ export class SocketIOProvider extends Observable {
335336
* Disconnect provider's socket
336337
* @type {() => void}
337338
*/
338-
disconnect() {
339+
disconnect () {
339340
if (this.socket.connected) {
340341
this.disconnectBc()
341342
this.socket.disconnect()
@@ -346,7 +347,7 @@ export class SocketIOProvider extends Observable {
346347
* This function runs when the socket is disconnected and emits the socket event `awareness-update`
347348
* which removes this client from awareness.
348349
* @private
349-
* @param {Socket.DisconnectReason} event The reason of the socket disconnection
350+
* @param {import('socket.io-client').Socket.DisconnectReason} event The reason of the socket disconnection
350351
* @readonly
351352
*/
352353
onSocketDisconnection = (event) => {
@@ -375,13 +376,10 @@ export class SocketIOProvider extends Observable {
375376
* Destroy the provider. This method clears the document, awareness, and window/process listeners and disconnects the socket.
376377
* @type {() => void}
377378
*/
378-
destroy() {
379+
destroy () {
379380
if (this.resyncInterval != null) clearInterval(this.resyncInterval)
380381
this.disconnect()
381-
if (typeof window !== 'undefined')
382-
window.removeEventListener('beforeunload', this.beforeUnloadHandler)
383-
else if (typeof process !== 'undefined')
384-
process.off('exit', this.beforeUnloadHandler)
382+
if (typeof window !== 'undefined') { window.removeEventListener('beforeunload', this.beforeUnloadHandler) } else if (typeof process !== 'undefined') { process.off('exit', this.beforeUnloadHandler) }
385383
this.awareness.off('update', this.awarenessUpdate)
386384
this.awareness.destroy()
387385
this.doc.off('update', this.onUpdateDoc)
@@ -404,7 +402,7 @@ export class SocketIOProvider extends Observable {
404402
this._broadcastChannel,
405403
{
406404
type: 'sync-update',
407-
data: update,
405+
data: update
408406
},
409407
this
410408
)
@@ -442,7 +440,7 @@ export class SocketIOProvider extends Observable {
442440
data: AwarenessProtocol.encodeAwarenessUpdate(
443441
this.awareness,
444442
changedClients
445-
),
443+
)
446444
},
447445
this
448446
)
@@ -495,8 +493,8 @@ export class SocketIOProvider extends Observable {
495493
{
496494
type: 'awareness-update',
497495
data: AwarenessProtocol.encodeAwarenessUpdate(this.awareness, [
498-
this.doc.clientID,
499-
]),
496+
this.doc.clientID
497+
])
500498
},
501499
this
502500
)
@@ -517,7 +515,7 @@ export class SocketIOProvider extends Observable {
517515
this.awareness,
518516
[this.doc.clientID],
519517
new Map()
520-
),
518+
)
521519
},
522520
this
523521
)
@@ -542,7 +540,7 @@ export class SocketIOProvider extends Observable {
542540
this._broadcastChannel,
543541
{
544542
type: 'sync-step-2',
545-
data: Y.encodeStateAsUpdate(this.doc, message.data),
543+
data: Y.encodeStateAsUpdate(this.doc, message.data)
546544
},
547545
this
548546
)
@@ -564,7 +562,7 @@ export class SocketIOProvider extends Observable {
564562
data: AwarenessProtocol.encodeAwarenessUpdate(
565563
this.awareness,
566564
Array.from(this.awareness.getStates().keys())
567-
),
565+
)
568566
},
569567
this
570568
)

src/y-socket-io/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export class User {
33
* @param {string} room
44
* @param {string} userid identifies the user globally.
55
*/
6-
constructor(room, userid) {
6+
constructor (room, userid) {
77
this.room = room
88
/**
99
* @type {string}

0 commit comments

Comments
 (0)