ShareJS example not working

1.5k Views Asked by At

I'm trying make a collaborative text editor using Sharejs but I'm running into some problems right at the outset.

I started with the "getting started" page. I ran npm install share and then ran the example server using ./node_modules/share/bin/exampleserver. This works fine.

However then I tried creating my own small application by following the steps in the "Running a server" section. I wrote the app.js file and the html that is suggested and when I tried running this, the browser console gives a 404 error saying it couldn't find socket.io.js:

GET http://localhost:8000/socket.io/socket.io.js 404 (Not Found)

and then I get this error repeatedly:

GET http://localhost:8000/test?VER=8&MODE=init&zx=ktil5643g6cw&t=1 404 (Not Found) 

Does anybody have any suggestions or ideas what is causing this? I know that it can work because the preconfigured example works great locally as I mentioned previously, it's just that I must not be configuring something right when I'm trying to create a new app.

Thanks.

1

There are 1 best solutions below

2
On

I the changelog you can see following:

client.open('hello', 'text', function(doc, error) {
  // ...
});

becomes

client.open('hello', 'text', function(error, doc) {
  // ...
});

Example still contains outdated callback function(doc, error). Besides, change URL on the client to http://example.com:8000/channel.

In my case final version is:

SERVER

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/');
});

CLIENT

<!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>