Difference between revisions of "Crossfire Tools API"

From FirebugWiki
Jump to: navigation, search
m (Changed code blocks to use syntax highlighting)
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
+
#REDIRECT [https://github.com/firebug-crossfire/crossfire/wiki/Crossfire%20Tools%20API Crossfire Tools API on Github]
 
+
== 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, <code>toolName</code>, and implements the following functions:
+
<syntaxHighlight lang="javascript">
+
handleEvent: function( event) {}         
+
 
+
handleRequest: function( request) {}           
+
 
+
handleResponse: function( response) {}
+
 
+
onTransportCreated: function( transport) {}           
+
 
+
onTransportDestroyed: function() {}           
+
 
+
onRegistered: function() {           
+
 
+
onUnregistered: function() {}           
+
 
+
onConnectionStatusChanged: function( status) {}           
+
</syntaxHighlight>
+
 
+
=== 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 <code>commands</code> and an <code>events</code> array as properties of your listener.
+
 
+
Alternatively, your listener can optionally implement the <code>supportsRequest()</code> and/or <code>supportsEvent()</code> 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:
+
 
+
<syntaxHighlight lang="javascript">
+
CrossfireModule.registerTool( toolName, toolListener);
+
</syntaxHighlight>
+
 
+
If you wish to stop receiving events, you call the unregisterTool method:
+
 
+
<syntaxHighlight lang="javascript">
+
CrossfireModule.unregisterTool( toolName);
+
</syntaxHighlight>
+
 
+
The <code>toolName</code> argument should be a string that matches a property named <code>toolName</code> 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 ====
+
 
+
==== sendEvent ====
+
 
+
==== sendResponse ====
+
 
+
== Handshake ==
+
 
+
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"
+
 
+
Example:
+
    CrossfireHandshake
+
    \r\n
+
    console,inspector,net
+
    \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.
+
 
+
Example:
+
 
+
== Examples ==
+
=== Console Tool ===
+
 
+
=== Inspector Tool ===
+
 
+
=== Net Tool ===
+
 
+
[[Category:Crossfire]]
+

Latest revision as of 19:49, 14 May 2012

  1. REDIRECT Crossfire Tools API on Github