mxSession

Session for sharing an mxGraphModel with other parties via a backend that acts as a multicaster for all changes.

Diagram Sharing

The diagram sharing is a mechanism where each atomic change of the model is encoded into XML using mxCodec and then transmitted to the server by the mxSession object.  On the server, the XML data is dispatched to each listener on the same diagram (except the sender), and the XML is decoded back into atomic changes on the client side, which are then executed on the model and stored in the command history.

The mxSession.significantRemoteChanges specifies how these changes are treated with respect to undo: The default value (true) will undo the last change regardless of whether it was a remote or a local change.  If the switch is false, then an undo will go back until the last local change, silently undoing all remote changes up to that point.  Note that these changes will be added as new remote changes to the history of the other clients.

Summary
mxSessionSession for sharing an mxGraphModel with other parties via a backend that acts as a multicaster for all changes.
Events
mxEvent.CONNECTFires after the session has been started, that is, after the response to the initial request was received and the session goes into polling mode.
mxEvent.SUSPENDFires after suspend was called an the session was not already in suspended state.
mxEvent.RESUMEFires after the session was resumed in resume.
mxEvent.DISCONNECTFires after the session was stopped in stop.
mxEvent.NOTIFYFires after a notification was sent in notify.
mxEvent.GETFires after a response was received in get.
mxEvent.FIREDFires after an array of edits has been executed on the model.
mxEvent.RECEIVEFires after an XML node was received in receive.
Functions
mxSessionConstructs a new session using the given mxGraphModel and URLs to communicate with the backend.
Variables
modelReference to the enclosing mxGraphModel.
urlInitURL to initialize the session.
urlPollURL for polling the backend.
urlNotifyURL to send changes to the backend.
codecReference to the mxCodec used to encoding and decoding changes.
linefeedUsed for encoding linefeeds.
escapePostDataSpecifies if the data in the post request sent in notify should be converted using encodeURIComponent.
significantRemoteChangesWhether remote changes should be significant in the local command history.
sentTotal number of sent bytes.
receivedTotal number of received bytes.
debugSpecifies if the session should run in debug mode.
connected
send
polling
Functions
start
suspendSuspends the polling.
resumeResumes the session if it has been suspended.
stopStops the session and fires a disconnect event.
pollSends an asynchronous GET request to urlPoll.
notifySends out the specified XML to urlNotify and fires a notify event.
getSends an asynchronous get request to the given URL, fires a get event and invokes the given onLoad function when a response is received.
isValidResponseReturns true if the response data in the given mxXmlRequest is valid.
encodeChangesReturns the XML representation for the given array of changes.
receiveProcesses the given node by applying the changes to the model.
processStateProcesses the given state node which contains the current state of the remote model.
processDeltaProcesses the given delta node which contains a sequence of edits which in turn map to one transaction on the remote model each.
processEditProcesses the given edit by executing its changes and firing the required events via the model.
createUndoableEditCreates a new mxUndoableEdit that implements the notify function to fire a <change> and notify event via the model.
decodeChangesDecodes and executes the changes represented by the children in the given node.
cellRemovedAdds removed cells to the codec object lookup for references to the removed cells after this point in time.

Events

mxEvent.CONNECT

Fires after the session has been started, that is, after the response to the initial request was received and the session goes into polling mode.  This event has no properties.

mxEvent.SUSPEND

Fires after suspend was called an the session was not already in suspended state.  This event has no properties.

mxEvent.RESUME

Fires after the session was resumed in resume.  This event has no properties.

mxEvent.DISCONNECT

Fires after the session was stopped in stop.  The <code>reason</code> property contains the optional exception that was passed to the stop method.

mxEvent.NOTIFY

Fires after a notification was sent in notify.  The <code>url</code> property contains the URL and the <code>xml</code> property contains the XML data of the request.

mxEvent.GET

Fires after a response was received in get.  The <code>url</code> property contains the URL and the <code>request</code> is the mxXmlRequest that contains the response.

mxEvent.FIRED

Fires after an array of edits has been executed on the model.  The <code>changes</code> property contains the array of changes.

mxEvent.RECEIVE

Fires after an XML node was received in receive.  The <code>node</code> property contains the node that was received.

Functions

mxSession

function mxSession(model,
urlInit,
urlPoll,
urlNotify)

Constructs a new session using the given mxGraphModel and URLs to communicate with the backend.

Parameters

modelmxGraphModel that contains the data.
urlInitURL to be used for initializing the session.
urlPollURL to be used for polling the backend.
urlNotifyURL to be used for sending changes to the backend.

Variables

model

mxSession.prototype.model

Reference to the enclosing mxGraphModel.

urlInit

mxSession.prototype.urlInit

URL to initialize the session.

urlPoll

mxSession.prototype.urlPoll

URL for polling the backend.

urlNotify

mxSession.prototype.urlNotify

URL to send changes to the backend.

codec

mxSession.prototype.codec

Reference to the mxCodec used to encoding and decoding changes.

linefeed

mxSession.prototype.linefeed

Used for encoding linefeeds.  Default is ‘&#xa;’.

escapePostData

mxSession.prototype.escapePostData

Specifies if the data in the post request sent in notify should be converted using encodeURIComponent.  Default is true.

significantRemoteChanges

mxSession.prototype.significantRemoteChanges

Whether remote changes should be significant in the local command history.  Default is true.

sent

mxSession.prototype.sent

Total number of sent bytes.

received

mxSession.prototype.received

Total number of received bytes.

debug

mxSession.prototype.debug

Specifies if the session should run in debug mode.  In this mode, no connection is established.  The data is written to the console instead.  Default is false.

connected

mxSession.prototype.connected

send

polling

mxSession.prototype.polling

Functions

start

mxSession.prototype.start = function()

suspend

mxSession.prototype.suspend = function()

Suspends the polling.  Use resume to reactive the session.  Fires a suspend event.

resume

mxSession.prototype.resume = function(type,
attr,
value)

Resumes the session if it has been suspended.  Fires a resume-event before starting the polling.

stop

mxSession.prototype.stop = function(reason)

Stops the session and fires a disconnect event.  The given reason is passed to the disconnect event listener as the second argument.

poll

mxSession.prototype.poll = function()

Sends an asynchronous GET request to urlPoll.

notify

mxSession.prototype.notify = function(xml,
onLoad,
onError)

Sends out the specified XML to urlNotify and fires a notify event.

get

mxSession.prototype.get = function(url,
onLoad,
onError)

Sends an asynchronous get request to the given URL, fires a get event and invokes the given onLoad function when a response is received.

isValidResponse

mxSession.prototype.isValidResponse = function(req)

Returns true if the response data in the given mxXmlRequest is valid.

encodeChanges

mxSession.prototype.encodeChanges = function(changes,
invert)

Returns the XML representation for the given array of changes.

receive

mxSession.prototype.receive = function(node)

Processes the given node by applying the changes to the model.  If the nodename is state, then the namespace is used as a prefix for creating Ids in the model, and the child nodes are visited recursively.  If the nodename is delta, then the changes encoded in the child nodes are applied to the model.  Each call to the receive function fires a receive event with the given node as the second argument after processing.  If changes are processed, then the function additionally fires a mxEvent.FIRED event before the mxEvent.RECEIVE event.

processState

mxSession.prototype.processState = function(node)

Processes the given state node which contains the current state of the remote model.

processDelta

mxSession.prototype.processDelta = function(node)

Processes the given delta node which contains a sequence of edits which in turn map to one transaction on the remote model each.

processEdit

mxSession.prototype.processEdit = function(node)

Processes the given edit by executing its changes and firing the required events via the model.

createUndoableEdit

mxSession.prototype.createUndoableEdit = function(changes)

Creates a new mxUndoableEdit that implements the notify function to fire a <change> and notify event via the model.

decodeChanges

mxSession.prototype.decodeChanges = function(node)

Decodes and executes the changes represented by the children in the given node.  Returns an array that contains all changes.

cellRemoved

mxSession.prototype.cellRemoved = function(cell,
codec)

Adds removed cells to the codec object lookup for references to the removed cells after this point in time.

Extends mxEventSource to implement a graph model.
mxSession.prototype.suspend = function()
Suspends the polling.
mxSession.prototype.resume = function(type,
attr,
value)
Resumes the session if it has been suspended.
mxSession.prototype.stop = function(reason)
Stops the session and fires a disconnect event.
mxSession.prototype.notify = function(xml,
onLoad,
onError)
Sends out the specified XML to urlNotify and fires a notify event.
mxSession.prototype.get = function(url,
onLoad,
onError)
Sends an asynchronous get request to the given URL, fires a get event and invokes the given onLoad function when a response is received.
mxSession.prototype.receive = function(node)
Processes the given node by applying the changes to the model.
function mxSession(model,
urlInit,
urlPoll,
urlNotify)
Constructs a new session using the given mxGraphModel and URLs to communicate with the backend.
mxSession.prototype.model
Reference to the enclosing mxGraphModel.
mxSession.prototype.urlInit
URL to initialize the session.
mxSession.prototype.urlPoll
URL for polling the backend.
mxSession.prototype.urlNotify
URL to send changes to the backend.
mxSession.prototype.codec
Reference to the mxCodec used to encoding and decoding changes.
XML codec for JavaScript object graphs.
mxSession.prototype.linefeed
Used for encoding linefeeds.
mxSession.prototype.escapePostData
Specifies if the data in the post request sent in notify should be converted using encodeURIComponent.
mxSession.prototype.significantRemoteChanges
Whether remote changes should be significant in the local command history.
mxSession.prototype.sent
Total number of sent bytes.
mxSession.prototype.received
Total number of received bytes.
mxSession.prototype.debug
Specifies if the session should run in debug mode.
mxSession.prototype.connected
mxSession.prototype.polling
mxSession.prototype.start = function()
mxSession.prototype.poll = function()
Sends an asynchronous GET request to urlPoll.
mxSession.prototype.isValidResponse = function(req)
Returns true if the response data in the given mxXmlRequest is valid.
XML HTTP request wrapper.
mxSession.prototype.encodeChanges = function(changes,
invert)
Returns the XML representation for the given array of changes.
mxSession.prototype.processState = function(node)
Processes the given state node which contains the current state of the remote model.
mxSession.prototype.processDelta = function(node)
Processes the given delta node which contains a sequence of edits which in turn map to one transaction on the remote model each.
mxSession.prototype.processEdit = function(node)
Processes the given edit by executing its changes and firing the required events via the model.
mxSession.prototype.createUndoableEdit = function(changes)
Creates a new mxUndoableEdit that implements the notify function to fire a change and notify event via the model.
Implements a composite undoable edit.
mxSession.prototype.decodeChanges = function(node)
Decodes and executes the changes represented by the children in the given node.
mxSession.prototype.cellRemoved = function(cell,
codec)
Adds removed cells to the codec object lookup for references to the removed cells after this point in time.
Fires after an array of edits has been executed on the model.
Fires after an XML node was received in receive.
Close