Server Api

97 views
Skip to first unread message

Claude ‘Luke’ Lucas

unread,
Oct 10, 2013, 6:18:47 AM10/10/13
to sha...@googlegroups.com
Hi Everyone,

i am using version 0.6.2 of sharejs.
Forgive the stupid question but I do not understand how to use the API server, in particular I do not understand how to use the call delete (docName, callback).

Someone can help me?

Thanks

Manuel

unread,
Oct 10, 2013, 11:32:15 AM10/10/13
to sha...@googlegroups.com
I have the same problem.

Someone can help us? :)

Wout Mertens

unread,
Oct 11, 2013, 4:18:23 AM10/11/13
to sha...@googlegroups.com

Can you share what you have already?

--
You received this message because you are subscribed to the Google Groups "ShareJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharejs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Claude ‘Luke’ Lucas

unread,
Oct 11, 2013, 7:10:11 AM10/11/13
to sha...@googlegroups.com
Sure.
Server side:

var express = require('express');
var app = express();
var share   = require('share').server;
var options = require('./db/options');
var hbs = require('hbs');

app.configure(function(){
    app.use(express.cookieParser());
    app.use(express.session({secret: 'GGHDIIITL'}));
    app.set('view engine', 'html');
    app.engine('html', hbs.__express);
    app.set('views', __dirname + '/html');
    app.use(express.bodyParser());
    app.use(app.router);
    app.use(express.static(__dirname + '/html'));
});

app.get('/editor.html', function(req, res){
    var titolo = req.body.title;
    share.attach(app, options);
    res.render('editor',{nome:title});
};

app.get('/', function(req, res) {
    DocList = { ... };
    res.render('index',{documents:DocList});
};

Client side:
<html>
    ....
    <div id="editor"></div>
    ....
    <script>
        var editor = ace.edit("editor");
    var docu;

    sharejs.open('{{nome}}', 'text', function(error, doc) {
        doc.attach_ace(editor);
                        docu=doc;
    });
    <script>
    ....
</html>
 
if you need anything else let me know. :)

Claude ‘Luke’ Lucas

unread,
Oct 15, 2013, 10:26:59 AM10/15/13
to sha...@googlegroups.com
Nobody can help me? pls

Joseph Gentle

unread,
Oct 15, 2013, 7:49:06 PM10/15/13
to sha...@googlegroups.com
You are trying to delete something from the server?

var shareServer = share.attach(app, options);

app.get('/editor.html', function(req, res){
var titolo = req.body.title;
res.render('editor',{nome:title});

// ....

shareServer.model['delete']('my docName', function(err) { ... });
};



On Tue, Oct 15, 2013 at 7:26 AM, Claude ‘Luke’ Lucas

Claude ‘Luke’ Lucas

unread,
Oct 21, 2013, 12:09:04 PM10/21/13
to sha...@googlegroups.com
I want the client tells the server to delete a document.

shareServer.model['delete']('my docName', function(err) { ... }); 

it does not work becouse my shareServer object it's like this:

{ domain: null,
  _events: 
   { request: 
      { [Function: app]
        use: [Function],
        handle: [Function],
        listen: [Function],
        setMaxListeners: [Function],
        emit: [Function],
        addListener: [Function],
        on: [Function],
        once: [Function],
        removeListener: [Function],
        removeAllListeners: [Function],
        listeners: [Function],
        route: '/',
        stack: [Object],
        init: [Function],
        defaultConfiguration: [Function],
        engine: [Function],
        param: [Function],
        set: [Function],
        path: [Function],
        enabled: [Function],
        disabled: [Function],
        enable: [Function],
        disable: [Function],
        configure: [Function],
        get: [Function],
        post: [Function],
        put: [Function],
        head: [Function],
        delete: [Function],
        options: [Function],
        trace: [Function],
        copy: [Function],
        lock: [Function],
        mkcol: [Function],
        move: [Function],
        propfind: [Function],
        proppatch: [Function],
        unlock: [Function],
        report: [Function],
        mkactivity: [Function],
        checkout: [Function],
        merge: [Function],
        'm-search': [Function],
        notify: [Function],
        subscribe: [Function],
        unsubscribe: [Function],
        patch: [Function],
        all: [Function],
        del: [Function],
        render: [Function],
        request: [Object],
        response: [Object],
        cache: {},
        settings: [Object],
        engines: {},
        _events: [Object],
        _router: [Object],
        routes: [Object],
        router: [Getter],
        locals: [Object],
        _usedRouter: true,
        model: [Object] },
     connection: [Function: connectionListener],
     clientError: [Function] },
  _maxListeners: 10,
  _connections: 0,
  connections: [Getter/Setter],
  _handle: null,
  _usingSlaves: false,
  _slaves: [],
  allowHalfOpen: true,
  httpAllowHalfOpen: false,
  timeout: 120000 }

  Another question:
   Can i use share.attach(app, options); with different options?
   I would like to use different tables for different documents

Joseph Gentle

unread,
Oct 22, 2013, 8:57:35 PM10/22/13
to sha...@googlegroups.com
On Mon, Oct 21, 2013 at 9:09 AM, Claude ‘Luke’ Lucas
<davi...@gmail.com> wrote:
> I want the client tells the server to delete a document.
>
> shareServer.model['delete']('my docName', function(err) { ... });
>
> it does not work becouse my shareServer object it's like this:

Your 'shareServer' object is a nodejs http server. How are you creating it?

This is the share.attach function:
https://github.com/share/ShareJS/blob/0.6/src/server/index.coffee#L34-L62
- Notice that server.model = model (the thing you want to call methods
on), and at the end it returns the server object. Whats happening for
you? Maybe put your server code in a gist somewhere and I'll take
another look?

> { domain: null,
> _events:
> { request:
> ...
> _maxListeners: 10,
> _connections: 0,
> connections: [Getter/Setter],
> _handle: null,
> _usingSlaves: false,
> _slaves: [],
> allowHalfOpen: true,
> httpAllowHalfOpen: false,
> timeout: 120000 }
>
> Another question:
> Can i use share.attach(app, options); with different options?
> I would like to use different tables for different documents

Sure, though I recommend waiting until sharejs 0.7, which supports
collections (=tables) out of the box.

-J

Claude ‘Luke’ Lucas

unread,
Oct 23, 2013, 6:32:20 AM10/23/13
to sha...@googlegroups.com
First of all thanks for your help. :)
 
Your 'shareServer' object is a nodejs http server. How are you creating it? 

This is the share.attach function: 
https://github.com/share/ShareJS/blob/0.6/src/server/index.coffee#L34-L62 
- Notice that server.model = model (the thing you want to call methods 
on), and at the end it returns the server object. Whats happening for 
you? 

I did some tests, the server object changes at this point:

if! (server instanceof http.Server)
     server = http.createServer server

After the "if" the object becomes a node.js http server

Maybe put your server code in a gist somewhere and I'll take 
another look?

Sure, I load it somewhere and post a link
 
 Another question: 
>    Can i use share.attach(app, options); with different options? 
>    I would like to use different tables for different documents 
 
Sure, though I recommend waiting until sharejs 0.7, which supports 
collections (=tables) out of the box.   

I do not know how to do it because after I called the first time share.attach (app, options) and sharejs.open (....) all the documents that I open then use the same options even if I recall share.attach (app , options) with different options.

Claude ‘Luke’ Lucas

unread,
Oct 23, 2013, 12:08:22 PM10/23/13
to sha...@googlegroups.com

Joseph Gentle

unread,
Oct 23, 2013, 1:40:27 PM10/23/13
to sha...@googlegroups.com

Oh yeah! I don't recognize my own code!

Make a model using share.createModel() and pass the model in to share.attach(app, options, model). Then you can call model.whatever.

-J

Claude ‘Luke’ Lucas

unread,
Oct 23, 2013, 2:10:02 PM10/23/13
to sha...@googlegroups.com
Oh yeah! I don't recognize my own code!

 :)

Make a model using share.createModel() and pass the model in to share.attach(app, options, model). Then you can call model.whatever.

I will do tests and let you know
 
Sure, though I recommend waiting until sharejs 0.7, which supports 
collections (=tables) out of the box.   

I am using the amazon web services and i would like to continue to use version 0.6.2.

Is there an easy way to use different db tables with different documents using this version?

if yes,please could you  show me the sample code?

Thanks

Joseph Gentle

unread,
Oct 23, 2013, 4:02:27 PM10/23/13
to sha...@googlegroups.com
On Wed, Oct 23, 2013 at 11:10 AM, Claude ‘Luke’ Lucas
<davi...@gmail.com> wrote:
>> Oh yeah! I don't recognize my own code!
>
>
> :)
>
>> Make a model using share.createModel() and pass the model in to
>> share.attach(app, options, model). Then you can call model.whatever.
>
>
> I will do tests and let you know
>
>>
>> Sure, though I recommend waiting until sharejs 0.7, which supports
>>
>> collections (=tables) out of the box.
>
>
> I am using the amazon web services and i would like to continue to use
> version 0.6.2.
>
> Is there an easy way to use different db tables with different documents
> using this version?

The best way to do it is to use the document name to encode the table
you want to edit. If you have a users table, make the document
'users.luke' edit the 'luke' document in the 'users' table. To do this
make or adapt one of the 0.6 database backends. For all of the
operations (create, submitOp, etc) split the document name (in this
case on a '.' and use the first part as the table name and the second
part as the document name.

> if yes,please could you show me the sample code?

Sorry to be blunt, but I have more profitable & important things to do
than provide unpaid technical support on an outdated version of
sharejs. The database bindings are here:
https://github.com/share/ShareJS/tree/0.6/src/server/db

-J
Reply all
Reply to author
Forward
0 new messages