ScrapboxがWebSocketで通信しているobjectの一覧
code:ts
interface SocketIORequest<MethodName extends string, T> {
event: "socket.io-request";
data: {
method: MethodName;
data: T;
};
}
ページの移動
要求
code:ts
interface JoinRoomRequest extends SocketIORequest<
"room:join",
{
pageId: string | null;
projectId: string;
projectUpdatesStream: false;
} | {
pageId: null;
projectId: string;
projectUpdatesStream: true;
}
{};
トップページとstreamへのアクセスはpageId: nullとなる
応答
code:ts
interface JoinRoomResponse {
data: {
success: true;
pageId: string | null;
projectId: string;
};
}
Streamの通知
code:ts
interface ProjectUpdatesStreamCommit {
event: "projectUpdatesStream:commit",
data: {
kind: "page";
id: string;
parentId: string;
projectId: string;
pageId: string;
userId: string;
cursor: null;
freeze: true;
};
}
code:typescript
interface ProjectUpdatesStreamEvent {
event: "projectUpdatesStream:event",
data: {
id: string;
pageId: string;
userId: string;
projectId: string;
created: number;
updated: number;
} & ({
type: "member.join" | "invitation.reset";
} | {
type: "page.delete";
data: {
titleLc: string;
};
} | {
type: "admin.add" | "admin.delete" | "owner.set";
targetUserId: string;
});
}
ページ
同期情報
ページの更新
code:ts
interface CommitResponse {
event: "commit";
data: {
kind: "page";
id: string;
parentId: string;
projectId: string;
pageId: string;
userId: string;
cursor: null;
freeze: true;
};
}
カーソルの移動
code:ts
interface MoveCursor {
event: "cursor";
data: {
user: {
id: string;
displayName: string;
};
pageId: string;
position: {
line: number;
char: number;
};
visible: boolean;
socketId?: string; // 応答にのみ存在
};
}
ページの編集
要求
code:ts
interface CommitRequest extends SocketIORequest<
"commit",
{
kind: "page";
parentId: string;
projectId: string;
pageId: string;
userId: string;
cursor: null;
freeze: true;
}
{};
interface Pin {
pin: number;
}
interface Delete {
delete: true;
}
応答
code:ts
interface PageUpdateResponse {
data: {
commitId: string;
}
}
commitが整合しない時
code:ts
interface PageUpdateResponse {
data: {
commitId: string;
};
error: {
name: "NotFastForwardError";
message: "Not fast-forward";
};
}
リンク情報の更新
code:ts
interface QuickSearchCommit {
event: "quick-search:commit",
data: {
kind: "page",
id: string;
parentId?: string;
projectId: string;
pageId: string;
userId: string;
changes: ({
links: string[];
} | {
title: string;
})[];
cursor: null;
freeze: true;
};
}
code:ts
interface QuickSearchReplaceLink {
event: "quick-search:replace-link",
data: {
from: string;
to: string;
};
}
サムネイル画像の更新
{ image: "https://..."}を送る
Gyazoの場合は{ image: "https://gyazo.com/:gyazoid/raw" }になる
サムネイル画像がなくなったときは{ image: null }を送る