Search code examples
javascriptmeteorsharejs

Setting up ShareJS in Meteor


I am having trouble in setting up meteor-share.js.

Basically I followed their README.

{{> sharejsAce docid=docid id="editor"}}

What is the second docid here? I guess it's a helper function of the template that contains the unique name of the document that I want to synchronize?

What's the first docid? is this keyword for meteor-share.js?

Once I include this in a html (or template), what do I need to do in the js side (client/server?)? Is there anything I should do make the template (sharejsAce) to share text?

I do not maintain multiple editors in a page so I am not sure what I should include and exclude from the demo.

I wonder if this is simply a bug in the API. when I changed to codemirror editor it just worked. The error was saying:

Uncaught TypeError: Cannot read property 'range' of undefined


Solution

  • I assume you are using version 1.2.0. If this is the case, you need to force a downgrade to version 1.1.9.

    You can do this by running the following command: meteor add mizzao:sharejs-ace@=1.1.9 or by changing the version manually in the .meteor/versions file: mizzao:[email protected].

    Read more about this issue on GitHub.


    What is the second docid here? I guess it's a helper function of the template that contains the unique name of the document that I want to synchronize?

    The docid parameter in {{> sharejsAce docid=docid id="editor"}} is used to specify the document which should be displayed in the editor. So, the second docid is the name of the helper function which simply returns the document's _id that has been selected:

    Template.docItem.events =
      "click a": (e) ->
       e.preventDefault()
       Session.set("document", @_id)
    
    
    Template.editor.helpers
      docid: -> Session.get("document")
    

    Once I include this in a html (or template), what do I need to do in the js side (client/server?)? Is there anything I should do make the template (sharejsAce) to share text?

    If you want to mirror ShareJS data with a Meteor collection and use the ShareJS user access control, you need to create a settings file, like in the demo:

    {
      "sharejs": {
        "options": {
          "accounts_auth": {
            "authorize": {
                "collection": "documents",
                "token_validations": {
                  "or": {
                    "invitedUsers": "is_in_array",
                    "userId": "is_equal"
                  }
                },
                "apply_on": [
                  "read",
                  "update",
                  "create",
                  "delete"
                ]
            },
            "authenticate": {
                "collection": "users",
                "token_validations": {
                  "_id": "is_equal"
                }
            }
          }
        }
      }
    }