Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yjsserver 鉴权影响协同,鉴权方法使用了自定义的方法通过fetch调用第三方平台鉴权,但是发现问题,当有一个用户的时候正常,但是超过一个用户之后协同就会失效,只会有一个编辑器可以使用,另一个编辑器页面无法显示出来,但是ws是已经连接上的,请问这是什么问题,大佬帮忙解答一下😂 #174

Open
Jedi1820 opened this issue Apr 9, 2024 · 0 comments
Assignees

Comments

@Jedi1820
Copy link

Jedi1820 commented Apr 9, 2024

server.on("upgrade", (request, socket, head) => {
// You may check auth of request here..
// See https://github.com/websockets/ws#client-authentication
const handleAuth = (ws: WebSocket) => {
const { auth = () => verifyWssUrl(ws, request) } =
SERVER_OPTIONS_WEAKMAP.get(server) ?? {}
auth(request, ws).then((res) => {
if (!res) {
ws.close(1008, undefined)
} else {
wss.emit("connection", ws, request)
}
})
}
wss.handleUpgrade(request, socket, head, handleAuth)
})

const verifyWssUrl = async (
conn: WebSocket.WebSocket,
request: http.IncomingMessage
) => {
const url = request.url
console.log("wss url:" + url)

try {
// @ts-ignore 初始化上下文
conn.context = await context.initContext(url)
// @ts-ignore
console.log(conn.context)
} catch (error: any) {
console.error("初始化上下文失败", error)
return false
}

return true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants