0
你好我正在我的node.js服務器上使用websockets來建立WebRTC連接。但是,當我結束連接的節點服務器控制檯給了我以下錯誤:關閉websocket連接錯誤
conn.otherName = null;
^
TypeError: Cannot set property 'otherName' of undefined
其他名稱是其他同行和I'ts在這樣的連接設置好的了名字: 情況下,「優惠」: // for ex。 UserA想要調用UserB console.log(「發送offer:」,data.name);
//if UserB exists then send him offer details
var conn = users[data.name];
if(conn != null) {
//setting that UserA connected with UserB
connection.otherName = data.name;
sendTo(conn, {
type: "offer",
offer: data.offer,
name: connection.name
});
}
break;
case "answer":
console.log("Sending answer to: ", data.name);
//for ex. UserB answers UserA
var conn = users[data.name];
if(conn != null) {
connection.otherName = data.name;
sendTo(conn, {
type: "answer",
answer: data.answer
});
}
後來我關閉這樣的連接:
connection.on("close", function() {
if(connection.name) {
delete users[connection.name];
if(connection.otherName) {
console.log("Disconnecting from ", connection.otherName);
var conn = users[connection.otherName];
conn.otherName = null;
if(conn != null) {
sendTo(conn, {
type: "leave"
});
}
}
}
});
我怎樣才能改變它能夠關閉不崩潰我的節點服務器的連接?
即使這樣,仍然無法正常工作:/ –
你的意思是不工作? – Mikkel
無論如何,它會崩潰,問題是,當我點擊兩次發送「關閉」消息的按鈕。由於它已經關閉,它返回undefined,所以它崩潰顯示相同的錯誤日誌。 –