Difference between revisions of "Crossfire Tools API"

From FirebugWiki
Jump to: navigation, search
m (Changed code blocks to use syntax highlighting)
m (Examples)
Line 75: Line 75:
== Examples ==
== Examples ==
=== Console Tool ===
=== Console Tool ===
=== DOM Tool ===
=== Inspector Tool ===
=== Inspector Tool ===

Revision as of 16:39, 29 May 2011

The Tools API provides a simple way for extensions to be notified when a Crossfire client or server connects to another host, and allows extensions to use this connection to send and receive custom requests and events over the Crossfire connection.

Using the Crossfire Tools API

In order to use the Tools API, you need to implement a listener object for your tool, and register it with Crossfire.

Creating a Tool listener

A Tool listener is a Javascript object that should contain a string property, toolName, and implements the following functions:

handleEvent: function( event) {}           

handleRequest: function( request) {}            

handleResponse: function( response) {}

onTransportCreated: function( transport) {}            

onTransportDestroyed: function() {}            

onRegistered: function() {            

onUnregistered: function() {}            

onConnectionStatusChanged: function( status) {}

Specifying Events and Commands for your tool

The simplest way to specify which commands and events your listener supports is to list the names in an array. Crossfire will check for a commands and an events array as properties of your listener.

Alternatively, your listener can optionally implement the supportsRequest() and/or supportsEvent() methods.

Registering a Tool Listener

In order for your listener to start receiving callbacks and events/requests, you must register it with the Crossfire module. This is accomplished by calling the registerTool method:

CrossfireModule.registerTool( toolName, toolListener);

If you wish to stop receiving events, you call the unregisterTool method:

CrossfireModule.unregisterTool( toolName);

The toolName argument should be a string that matches a property named toolName in your listener object. Crossfire will add this string as a header to packets sent to your listener, in order to route packets appropriately to various tools.

Crossfire Transport API

Connection Status




The Crossfire client may send a comma-separated list of tools to be activated immediately following the handshake string, followed by "\r\n"

A Crossfire server should send a comma-separated list of available tools immediately after the handshake string, followed by "\r\n"



Tool Headers

Packets which contain a command that is intended for a specific tool should include a "tool:" header with the intended tool's name.



Console Tool

DOM Tool

Inspector Tool

Net Tool