更新最新代码

This commit is contained in:
2024-03-21 20:32:50 +08:00
parent 1ec018ca90
commit 7d756bcfa4
52 changed files with 38968 additions and 51 deletions
+49
View File
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Collaborative Editing</title>
<style>
#editor {
width: 100%;
height: 400px;
border: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
font-family: monospace;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const ws = new WebSocket('ws://localhost:6789');
const editor = document.getElementById('editor');
ws.onopen = function(event) {
console.log('Connection established!');
};
ws.onmessage = function(event) {
// 当接收到消息时,更新编辑器的内容
const message = JSON.parse(event.data);
editor.value = message; // 假设消息直接是编辑内容
};
ws.onclose = function(event) {
console.log('Connection closed!');
};
editor.oninput = function(event) {
// 当编辑器内容发生变化时,发送消息
const message = {
type: 'edit',
content: editor.value
};
ws.send(JSON.stringify(message));
};
});
</script>
</head>
<body>
<textarea id="editor" placeholder="Start editing..."></textarea>
</body>
</html>