您可以在更改日志中看到以下内容:
client.open('hello', 'text', function(doc, error) {
// ...
});
变成
client.open('hello', 'text', function(error, doc) {
// ...
});
示例仍然包含过时的回调function(doc, error)
。此外,将客户端上的 URL 更改为http://example.com:8000/channel。
在我的情况下,最终版本是:
服务器
var connect = require('./node_modules/connect'),
sharejs = require('./node_modules/share').server;
var server = connect(
connect.logger(),
connect.static(__dirname + '/public')
);
var options = {db:{type:'none'}}; // See docs for options. {type: 'redis'} to enable persistance.
// Attach the sharejs REST and Socket.io interfaces to the server
sharejs.attach(server, options);
server.listen(8000, function () {
console.log('Server running at http://127.0.0.1:8000/');
});
客户
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://ajaxorg.github.com/ace/build/src/ace.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="/channel/bcsocket.js"></script>
<script src="/share/share.js"></script>
<script src="/share/ace.js"></script>
<script>
$(document).ready(function() {
var editor = ace.edit("editor");
sharejs.open('hello', 'text', 'http://localhost:8000/channel', function (error, doc) {
doc.attach_ace(editor);
});
});
</script>
<style>
#editor {
width: 200px;
height: 100px;
}
</style>
</head>
<body>
<div id="editor"></div>
</body>
</html>