LiveMessage

From Facebook Developer Wiki

Jump to: navigation, search

This feature is currently in beta.

This feature allows developers to send JSON-encoded "messages" directly to a user's browser, via either an API or FBJS call. It can be used, for example, to update a game board without requiring a user to refresh the page. Messages are received via an FBJS callback, and can be handled on both canvas pages and within a profile box (the user must first interact with the profile box, in the latter case).

When registering your FBJS callback, you must specify an "event name", which is a string that identifies which messages your handler is interested in receiving. When sending a message, you also specify an event name, and it will be delivered if a callback has been registered for that event.

Sample Code

To register a callback handler (for receiving messages):

// listen for messages sent with the "game_move" event name var livemessage = new LiveMessage('game_move', function(data)) { // successfully received a message - "data" is a JSON object. });


To send a message:

var data = { from : from_uid, msg : message_text }; livemessage.send(recipient_uid, data); // Where livemessage is a registered callback

Currently, sending livemessages in FBJS requires registering a callback handler.

To see a complete example in FBJS, check out the LiveMessage Example.

Documentation

Notes/Limitations

  • An app is only allowed to register one callback handler per event name.
  • Messages can only be sent and received for users who have signed the TOS for your application.
  • LiveMessage is unsupported in IE6. We'll fix that before we take it out of beta.
  • Messages can be no longer than 1024 bytes, and event names can be no longer than 128 bytes.
reference