.
├── Prototype
│ ├── Core
│ │ └── WebBroadcast.js
│ └── index.html
├── README.md
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Web player prototype</title>
<script src="Core/WebBroadcast.js"></script>
</head>
<body>
<div>
<button type="button" onclick="webConnection.connectToServer()">Connect</button>
<button type="button" onclick="webConnection.disconnectFromServer()">Disconnect</button>
</div>
<canvas id="webPlayer" width="640" height="480" style="border:1px solid #000000;"></canvas>
<script>
webConnection = WebConnection("ws://192.168.33.30/jpeg/1/jpeg_stream.websock", "admin", "admin", "webPlayer");
</script>
</body>
</html>
function WebConnection(address, userName, userPassword) {
console.log("add: " + address + " name: " + userName + " pwd: " + userPassword)
}
WebConnection.prototype.connectToServer = function () {
console.log("connect")
}
WebConnection.prototype.disconnectFromServer = function () {
console.log("disconnect")
}
add: ws://192.168.33.30/jpeg/1/jpeg_stream.websock name: admin pwd: admin
connect
add: ws://192.168.33.30/jpeg/1/jpeg_stream.websock name: admin pwd: admin
onclick Uncaught TypeError: Cannot read property 'connectToServer' of undefined
这是我第一次尝试javascript项目。 我需要你们的帮助。
答案 0 :(得分:0)
伙计们我发现了这个问题。
webConnection = WebConnection("ws://192.168.33.30/jpeg/1/jpeg_stream.websock", "admin", "admin", "webPlayer");
webConnection = new WebConnection("ws://192.168.33.30/jpeg/1/jpeg_stream.websock", "admin", "admin", "webPlayer");
由new