Ajax Messaging Library

Peer to peer-like web browser networking using JavaScript and php

Documentation

This document contains more in-depth documentation not covered in the quick introduction or installation instructions.

The options object

The function Messenger.Create takes an object with options as its third argument. The following options are available:

NameTypeDescription
dispatchfunction

Specifies the callback function to call when a message is received.

dispatch: function(senderId, msg, delay) { }. senderId is a unique numeric identifier for the sender of the message. msg is the message string. delay is the approximate number of seconds ago the message was sent.

censusfunction

Specifies the callback function to call when a new census (number of people connected) is received. A census is always received when the connection is established, and a new one is gathered at regular intervals after that.

census: function(active, passive) { }. active is the number of active (i.e. sending) peers. passive is the number of passive (i.e. not currently sending, but receiving) peers.

feedbackbooleanSpecifies that the messages you send should be dispatched to the function specified in the dispatch option. This can be convenient sometimes. Default is that your own messages are not dispatched. The callback to the dispatch function will be made at the time when the message is sent.
immediateFeedbackbooleanSpecifies that the feedback of messages you send should be done immediately when the send function is called, and not at the time when the message is sent.
initialintegerThe number of old messages to get initially, i.e. when the connection to the server is established. Default is specified on the server (default is 10).
errorfunctionCallback function to call when an internal error occurs. Useful only for debugging. Parameter is a string. error: alert will display the error as an alert.
maxAgeintegerThe maximum age in seconds of initial messages, i.e. messages fetched when the connection is established. Default is specified on the server (default is 7 days). If you're only interested in recent messages, it makes sense to set this low.
scriptFileNamestringSpecifies the name of the script on the server. Default is "message.php".
shortUrlsbooleanSpecifies that the URLs to access on the server are in the form "/directory/service/action" instead of the default "/directory/message.php?service=service&action=action", which is, arguably, more web 2.0. You can use the .htaccess file supplied in the zip to enable this on the server side.