|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 | 3 | import {get} from "lodash";
|
| 4 | +import {Socket} from "socket.io"; |
4 | 5 |
|
5 | 6 | import config from "../config";
|
6 | 7 | import {Note} from "../models";
|
7 | 8 | import {logger} from "../logger";
|
8 | 9 |
|
| 10 | +export type CursorData = Record<string, string> |
| 11 | + |
| 12 | +export interface UserStatus { |
| 13 | + type: string |
| 14 | + idle: boolean |
| 15 | +} |
| 16 | + |
9 | 17 | export class RealtimeClientConnection {
|
10 |
| - private socket: any; |
| 18 | + private socket: Socket; |
11 | 19 | private realtime: any;
|
12 | 20 |
|
13 |
| - constructor(socket) { |
| 21 | + constructor(socket: Socket) { |
14 | 22 | this.socket = socket
|
15 | 23 | this.realtime = require('./realtime')
|
16 | 24 | }
|
@@ -87,7 +95,7 @@ export class RealtimeClientConnection {
|
87 | 95 | return this.realtime.getNoteFromNotePool(this.socket.noteId)
|
88 | 96 | }
|
89 | 97 |
|
90 |
| - getNoteChannel() { |
| 98 | + getNoteChannel(): Socket { |
91 | 99 | return this.socket.broadcast.to(this.socket.noteId)
|
92 | 100 | }
|
93 | 101 |
|
@@ -139,7 +147,7 @@ export class RealtimeClientConnection {
|
139 | 147 | })
|
140 | 148 | }
|
141 | 149 |
|
142 |
| - userStatusEventHandler(data) { |
| 150 | + userStatusEventHandler(data: UserStatus): void { |
143 | 151 | if (!this.isNoteAndUserExists()) return
|
144 | 152 | const user = this.getCurrentUser()
|
145 | 153 | if (config.debug) {
|
@@ -177,15 +185,15 @@ export class RealtimeClientConnection {
|
177 | 185 | })
|
178 | 186 | }
|
179 | 187 |
|
180 |
| - cursorFocusEventHandler(data) { |
| 188 | + cursorFocusEventHandler(data: CursorData): void { |
181 | 189 | if (!this.isNoteAndUserExists()) return
|
182 | 190 | const user = this.getCurrentUser()
|
183 | 191 | user.cursor = data
|
184 | 192 | const out = this.realtime.buildUserOutData(user)
|
185 | 193 | this.getNoteChannel().emit('cursor focus', out)
|
186 | 194 | }
|
187 | 195 |
|
188 |
| - cursorActivityEventHandler(data) { |
| 196 | + cursorActivityEventHandler(data: CursorData): void { |
189 | 197 | if (!this.isNoteAndUserExists()) return
|
190 | 198 | const user = this.getCurrentUser()
|
191 | 199 | user.cursor = data
|
|
0 commit comments