Skip to content

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

Description

@Jedi1820

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions