Package: jarn.xmpp.collaboration
Introductionjarn.xmpp.collaborationdefines a protocol to do real-time collaborative editing through XMPP and provides:a generic overridable implementation of the server component.a Plone-specific implementation (server component and javascript client).adapters for basic Plone content types (Pages and News Items).It is part of a suite of packages aiming to provide XMPP services to Plone. The other two packages arejarn.xmpp.twisted, provides XMPP-specific protocol implementation for twisted.jarn.xmpp.coreprovides facilities for presence, messaging, chatting and microblogging.RequirementsPlease seejarn.xmpp.corefor details on setting up your Plone site and XMPP server. If you are not using the recipe included injarn.xmpp.buildoutyou will need to configure your ejabberd to allow connections from the collaboration component. Forejabberdthis is done by including the following in your config file:{{5347, {0,0,0,0} }, ejabberd_service, [
  {access, all},
  {shaper_rule, fast},
  {ip, {127, 0, 0, 1}},
  {hosts, ["collaboration.localhost"],
   [{password, "secret"}]
  }
 ]},The instance that is going to be running the xmpp component should include thecomponent.zcml. You can do this in your buildout:zcml-additional =
  <configure xmlns="http://namespaces.zope.org/zope">
      <include package="jarn.xmpp.twisted" file="reactor.zcml" />
      <include package="jarn.xmpp.collaboration" file="component.zcml" />
  </configure>Finally you will need to “activate” the product in the Plone control panel. After doing so, please edit the registry settings and in particular:jarn.xmpp.collaborationJIDis the Jabber id of the collaborative editing service component. Essentially ifmyserveris your XMPP domaincollaboration.myserveris a good name. This should match the name you gave toejabberd, see above. Default iscollaboration.localhost.jarn.xmpp.collaborationPasswordis the password the component will use to connect to your xmpp server, see above. Default issecret.jarn.xmpp.collaborationPortis the port that your XMPP server allows components to connect to, see above. Default is5347.UsageUsingjarn.xmpp.collaborationis easy once you have gotten over setting it up. There are no special views to use when you collaboratively edit content. If an adapter toICollaborativelyEditableexists for your content then accessing its edit form will allow multiple users to edit simultaneously.Out of the box there exist adapters for archetypes as well as dexterity-based content types. For AT content types, fields that implementIStringFieldorITextFieldwill automatically get collaborative editing support. For Dexterity the fields that will be automatically included are those that provideITextLine,ITextorIRichTextregardless of thebehaviorby which they are defined. Note that the javascript client assumes that TinyMCE is used. Collaboration on rich text fields will not work with Kupu.Protocol specification.InitializationIn order to initiate a collaborative editing session, the party sends apresencestanza to the server component indicating on which node he wishes to work on. The party MUST specify thenodeattribute in thequeryelement:<presence from='foo@example.com/work' to='collaboration.example.com'>
    <query xmlns='http://jarn.com/ns/collaborative-editing' node='collab-node'/>
</presence>Upon receipt amessagestanza is sent to anyone else who might be editing the same node notifying them of the new participant:<message from='collaboration.example.com' to='bar@example.com/home'>
    <x xmlns='http://jarn.com/ns/collaborative-editing'>
        <item action='user-joined' node='collab-node' user='foo@example.com/work'/>
    </x>
</message>The newly joined user also receives a similar notification about existing users<message from='collaboration.example.com' to='foo@example.com/home'>
    <x xmlns='http://jarn.com/ns/collaborative-editing'>
        <item action='user-joined' node='collab-node' user='bar@example.com/work'/>
    </x>
</message>To complete the initialization the new party MUST request the current version of the node from the server:<iq id='123' from='foo@example.com/work' to='collaboration.example.com' type='get'>
    <shadowcopy xmlns='http://jarn.com/ns/collaborative-editing' node='collab-node'/>
</iq>To which the server replies providing his current copy of the text:<iq id='123' from='collaboration.example.com' to='foo@example.com/work'  type='result'>
     <shadowcopy xmlns='http://jarn.com/ns/collaborative-editing' node='collab-node'>Hello world</shadowcopy>
 </iq>In case the node does not exist, or the user has no privileges granting him access, the server MUST reply with an error, for instance:<iq id='123' from='collaboration.example.com' to='foo@example.com/work' type='error'>
    <error xmlns='http://jarn.com/ns/collaborative-editing'>Unauthorized</error>
</iq>Editing cycleWhen a party edits the text, it notifies the server by sending aniqstanza of typeset. The stanza contains onepatchelement which MUST specify thenodethey apply to, and in their body contain the patch created by the Diff-Match-Patch algorithm in text format. For instance if the text changed from “Hello world” to “Hello world, have a nice day!” the message would be:<iq id='234' from='foo@example.com/work' to='collaboration.example.com' type='set'>
    <patch xmlns='http://jarn.com/ns/collaborative-editing' node='collab-node' digest='b9e8241b3cc82c43af870641078ee03f'>
        @@ -4,8 +4,26 @@\n lo world\n+, have a nice day!\n
    </patch>
</iq>If the server succeeds to apply the patch to its shadow copy, it replies with asuccessresult:<iq id='234' from='collaboration.example.com' to='foo@example.com/work' type='result'>
    <success xmlns='http://jarn.com/ns/collaborative-editing'/>
</iq>Additionally the server MUST broadcast the patch to all other parties who are present on the node:<iq id='345' from='collaboration.example.com' to='bar@example.com/home' type='set'>
    <patch xmlns='http://jarn.com/ns/collaborative-editing' node='collab-node'>
        @@ -4,8 +4,26 @@\n lo world\n+, have a nice day!\n
    </patch>
</iq>The parties  MUST apply it to their text.
If applying the patch fails, the server (or client) MUST reply with aniqstanza of typeerror. For instance if a patch was sent to the server and for some reason it was not possible to apply it to the shadow copy, the server would reply:<iq id='234' from='collaboration.example.com' to='foo@example.com/work' type='error'>
    <error xmlns='http://jarn.com/ns/collaborative-editing'>
        Patch @@ -4,8 +4,26 @@\n lo world\n+, have a nice day!\n could not be applied.
    </error>
</iq>In that case the client SHOULD sync again the current copy by sending aniqstanza of typeget`requesting the shadow copy, see the `Initializationsection above.Finally, apatchelement MAY have thedigestattribute. In that case, the server SHOULD check the checksum and if there is a mismatch, reply with an error stanza if appropriate. Note that currently the checksum algorithm is not negotiated and is assumed to be MD5 hex digest.FocusingIn an environment where multiple nodes are edited in the same time (for instance in a context where the content has more than one collaboratively editable field) the client CAN send a notification specifying which particular node he is currently editing:<message from='foo@example.com/work' to='collaboration.example.com'>
    <x xmlns='http://jarn.com/ns/collaborative-editing'>
        <item node='collab-node' action='focus' user='foo@example.com/work'/>
    </x>
</message>The server MUST propagate the message to all other users that are currently collaborating on the node:<message from='collaboration.example.com' to='bar@example.com/home'>
    <x xmlns='http://jarn.com/ns/collaborative-editing'>
        <item node='collab-node' action='focus' user='foo@example.com/work'/>
    </x>
</message>SavingAt any point a party can request a save. This is done by sending a message whoseitemMUST indicate the node and its action must be set tosave:<message from='foo@example.com/work' to='collaboration.example.com'>
    <x xmlns='http://jarn.com/ns/collaborative-editing'>
        <item node='collab-node' action='save'></item>
    </x>
</message>It is up to the server component to enforce any security considerations on saving.TerminationThe session is terminated when the party sends anunavailablepresence:<presence from='foo@example.com/work' type='unavailable' />Upon receipt, the server notifies any party that might still be editing the node:<message from='collaboration.example.com' to='bar@example.com/home'>
    <x xmlns='http://jarn.com/ns/collaborative-editing'>
        <item action='user-left' node='collab-node' user='foo@example.com/work'/>
    </x>
</message>CreditsMost of this work was done using the 10% time available toJarn ASemployees for the development of open-source projects.David Glick (davisagli) for dexterity support and general awesomeness.jarn.xmpp.collaborationrelies on the wonderfulDiff-Match-Patchfrom Neil Fraser at Google. It is distributed under the Apache License 2.0.Changelog0.1b3 - 2011-11-26Fix checksum bug preventing the shadow text to be applied if an error ever
occured.
[ggozad]0.1b2 - 2011-10-01Perform checksum checks on every patch. Deal with potential errors due to
network lag.
[ggozad]Use TinyMCE’s raw instead of processed text. Improved reliability.
[ggozad]0.1b1 - 2011-09-18Major protocol update. Instead of sending message stanzas around, now iq
stanzas are used. This makes it possible to check for errors and synchronize
in certain edge cases. It also makes the protocol more in line with XMPP
conventions.
[ggozad]Reorganized and cleaned js code. The client protocol implementation is now
separate from the plone-specific parts allowing code reuse and improving
readability.
[ggozad]Notify user when others are joining/leaving the node.
[ggozad]0.1a4 - 2011-09-07Documentation updates.
[ggozad]Fix js error when user has left collaborative editing.
[ggozad]0.1a3 - 2011-09-01Simplified configuration and fixed confusing typos in the registry
[ggozad]0.1a2 - 2011-06-06Configure the component/server password and connection port in p.a.registry.
[ggozad]Dexterity content type support.
[davisagli, ggozad]Generalized ATContentTypes support.
[ggozad]Provide visual feedback when a user updates a node.
[ggozad]JS cleanup.
[ggozad]Test coverage.
[ggozad]0.1a1 2011-05-09Initial release
[ggozad]