I am trying to setup YSocketIo with Nextjs Tiptap and hocuspocus/server and everything works…, until I want to add socket routes and I get nothing back. I dont event get “User connected…” when connection although the collaboration works and no errors. What is happening to my logs?
Server code
import express from "express";
import { Server } from "@hocuspocus/server";
import { createServer } from "http";
import { Server as SocketServer } from "socket.io";
import { YSocketIO } from 'y-socket.io/dist/server'
const host = "localhost"
const port = "1234"
const app = express();
const httpServer = createServer(app);
const io = new SocketServer(httpServer);
const collaborationServer = Server.configure({
onConnect: (context) => {
console.log("User connected", context.user);
}
});
const ysocketio = new YSocketIO(io)
ysocketio.initialize()
// Listen for Socket.IO connections
io.on("connection", (socket) => {
console.log("Socket.IO connection established");
socket.on("disconnect", () => {
console.log("Socket.IO connection disconnected");
});
socket.on("test", () => {
console.log("test");
});
collaborationServer.handleConnection(socket, null, context);
});
httpServer.listen(port, host, undefined, () => console.log(`Server running on port ${port}`))
Nextjs Page
import Collaboration from "@tiptap/extension-collaboration";
import StarterKit from "@tiptap/starter-kit";
import { EditorContent, useEditor } from "@tiptap/react";
import React, { useEffect } from "react";
import { HocuspocusProvider } from "@hocuspocus/provider";
import CollaborationCursor from "@tiptap/extension-collaboration-cursor";
import Paragraph from "@tiptap/extension-paragraph";
import Document from "@tiptap/extension-document";
import Placeholder from "@tiptap/extension-placeholder";
import Text from "@tiptap/extension-text";
import * as Y from "yjs";
import { SocketIOProvider } from 'y-socket.io';
const doc = new Y.Doc()
const provider = new SocketIOProvider('http://localhost:1234', 'room-name', doc, {
autoConnect: true,
resyncInterval: 5000,
disableBc: false
});
const TipTapEditor = () => {
const editor = useEditor({
extensions: [
StarterKit.configure({
history: false,
}),
// Register the document with Tiptap
Collaboration.configure({
document: doc,
}),
CollaborationCursor.configure({
provider,
user: {
name: "Cyndi",
color: "#f783ac",
},
}),
Placeholder.configure({
placeholder:
"Write something … Itll be shared with everyone else looking at this example.",
}),
],
});
const handleEmit = () => {
console.log('emitting test');
provider.emit('test', []);
}
return (
<>
<button onClick={handleEmit}>
Test Emit
</button>
<EditorContent editor={editor} />
</>
);
};
export default TipTapEditor;
Please help,
Thanks in advanced!