Skip to content

Commit 20fa36e

Browse files
committed
lint: lib/realtime/realtimeClientConnection
- add socket type - add user status and cursor data
1 parent c9ce7f4 commit 20fa36e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/realtime/realtimeClientConnection.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
'use strict'
22

33
import {get} from "lodash";
4+
import {Socket} from "socket.io";
45

56
import config from "../config";
67
import {Note} from "../models";
78
import {logger} from "../logger";
89

10+
export type CursorData = Record<string, string>
11+
12+
export interface UserStatus {
13+
type: string
14+
idle: boolean
15+
}
16+
917
export class RealtimeClientConnection {
10-
private socket: any;
18+
private socket: Socket;
1119
private realtime: any;
1220

13-
constructor(socket) {
21+
constructor(socket: Socket) {
1422
this.socket = socket
1523
this.realtime = require('./realtime')
1624
}
@@ -87,7 +95,7 @@ export class RealtimeClientConnection {
8795
return this.realtime.getNoteFromNotePool(this.socket.noteId)
8896
}
8997

90-
getNoteChannel() {
98+
getNoteChannel(): Socket {
9199
return this.socket.broadcast.to(this.socket.noteId)
92100
}
93101

@@ -139,7 +147,7 @@ export class RealtimeClientConnection {
139147
})
140148
}
141149

142-
userStatusEventHandler(data) {
150+
userStatusEventHandler(data: UserStatus): void {
143151
if (!this.isNoteAndUserExists()) return
144152
const user = this.getCurrentUser()
145153
if (config.debug) {
@@ -177,15 +185,15 @@ export class RealtimeClientConnection {
177185
})
178186
}
179187

180-
cursorFocusEventHandler(data) {
188+
cursorFocusEventHandler(data: CursorData): void {
181189
if (!this.isNoteAndUserExists()) return
182190
const user = this.getCurrentUser()
183191
user.cursor = data
184192
const out = this.realtime.buildUserOutData(user)
185193
this.getNoteChannel().emit('cursor focus', out)
186194
}
187195

188-
cursorActivityEventHandler(data) {
196+
cursorActivityEventHandler(data: CursorData): void {
189197
if (!this.isNoteAndUserExists()) return
190198
const user = this.getCurrentUser()
191199
user.cursor = data

0 commit comments

Comments
 (0)