Skip to content

Commit

Permalink
try to bump socket-client
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Jan 2, 2024
1 parent 351ab05 commit 2f92f95
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 171 deletions.
5 changes: 3 additions & 2 deletions excalidraw-app/collab/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import { newElementWith } from "../../packages/excalidraw/element/mutateElement"
import { BroadcastedExcalidrawElement } from "./reconciliation";
import { encryptData } from "../../packages/excalidraw/data/encryption";
import { PRECEDING_ELEMENT_KEY } from "../../packages/excalidraw/constants";
import { Socket } from "socket.io-client";

class Portal {
collab: TCollabClass;
socket: SocketIOClient.Socket | null = null;
socket: typeof Socket | null = null;
socketInitialized: boolean = false; // we don't want the socket to emit any updates until it is fully initialized
roomId: string | null = null;
roomKey: string | null = null;
Expand All @@ -32,7 +33,7 @@ class Portal {
this.collab = collab;
}

open(socket: SocketIOClient.Socket, id: string, key: string) {
open(socket: typeof Socket, id: string, key: string) {
this.socket = socket;
this.roomId = id;
this.roomKey = key;
Expand Down
3 changes: 2 additions & 1 deletion excalidraw-app/data/StorageBackend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Socket } from "socket.io-client";
import { SyncableExcalidrawElement } from ".";
import { ExcalidrawElement, FileId } from "../../packages/excalidraw/element/types";
import { AppState, BinaryFileData } from "../../packages/excalidraw/types";
Expand All @@ -13,7 +14,7 @@ export interface StorageBackend {
loadFromStorageBackend: (
roomId: string,
roomKey: string,
socket: SocketIOClient.Socket | null,
socket: typeof Socket | null,
) => Promise<readonly ExcalidrawElement[] | null>;
saveFilesToStorageBackend: ({
prefix,
Expand Down
9 changes: 5 additions & 4 deletions excalidraw-app/data/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MIME_TYPES } from "../../packages/excalidraw/constants";
import { reconcileElements } from "../collab/reconciliation";
import { getSyncableElements, SyncableExcalidrawElement } from ".";
import { ResolutionType } from "../../packages/excalidraw/utility-types";
import { Socket } from "socket.io-client";

// private
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -140,12 +141,12 @@ const decryptElements = async (
};

class FirebaseSceneVersionCache {
private static cache = new WeakMap<SocketIOClient.Socket, number>();
static get = (socket: SocketIOClient.Socket) => {
private static cache = new WeakMap<typeof Socket, number>();
static get = (socket: typeof Socket) => {
return FirebaseSceneVersionCache.cache.get(socket);
};
static set = (
socket: SocketIOClient.Socket,
socket: typeof Socket,
elements: readonly SyncableExcalidrawElement[],
) => {
FirebaseSceneVersionCache.cache.set(socket, getSceneVersion(elements));
Expand Down Expand Up @@ -287,7 +288,7 @@ export const saveToFirebase = async (
export const loadFromFirebase = async (
roomId: string,
roomKey: string,
socket: SocketIOClient.Socket | null,
socket: typeof Socket | null,
): Promise<readonly ExcalidrawElement[] | null> => {
const firebase = await loadFirestore();
const db = firebase.firestore();
Expand Down
5 changes: 3 additions & 2 deletions excalidraw-app/data/httpStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Inspired and partly copied from https://gitlab.com/kiliandeca/excalidraw-fork
// MIT, Kilian Decaderincourt

import { Socket } from "socket.io-client";
import { getSyncableElements, SyncableExcalidrawElement } from ".";
import { MIME_TYPES } from "../../packages/excalidraw/constants";
import { decompressData } from "../../packages/excalidraw/data/encode";
Expand Down Expand Up @@ -42,7 +43,7 @@ const SCENE_VERSION_LENGTH_BYTES = 4
// to prevent modifying upstream files and ease futur maintenance of this fork

const httpStorageSceneVersionCache = new WeakMap<
SocketIOClient.Socket,
typeof Socket,
number
>();

Expand Down Expand Up @@ -123,7 +124,7 @@ export const saveToHttpStorage = async (
export const loadFromHttpStorage = async (
roomId: string,
roomKey: string,
socket: SocketIOClient.Socket | null,
socket: typeof Socket | null,
): Promise<readonly ExcalidrawElement[] | null> => {
const getResponse = await fetch(
`${httpStorageBackendUrl}/rooms/${roomId}`,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router-dom": "6.21.1",
"socket.io-client": "2.3.1"
"socket.io-client": "4.7.2"
},
"devDependencies": {
"@excalidraw/eslint-config": "1.0.3",
Expand All @@ -27,7 +27,6 @@
"@types/lodash.throttle": "4.1.7",
"@types/react": "18.0.15",
"@types/react-dom": "18.0.6",
"@types/socket.io-client": "1.4.36",
"@vitejs/plugin-react": "3.1.0",
"@vitest/coverage-v8": "0.33.0",
"@vitest/ui": "0.32.2",
Expand Down
Loading

0 comments on commit 2f92f95

Please sign in to comment.