new ExtensionRequest(extCmd[, params][, room])

Creates a new ExtensionRequest instance. The instance must be passed to the SmartFox.send() method for the request to be executed.

This request is used to send custom commands from the client to a server-side Extension, be it a Zone-level or Room-level Extension. Viceversa, the extensionResponse event is used by the server to send Extension commands/responses to the client.

Read the SmartFoxServer 2X documentation about server-side Extension for more informations.

Example

This example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the EXTENSION_RESPONSE listener (the same command name is used in both the request and the response).

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.EXTENSION_RESPONSE, onExtensionResponse, this);

	// Send two integers to the Zone extension and get their sum in return
	var params = new SFS2X.SFSObject();
	params.putInt("n1", 26);
	params.putInt("n2", 16);

	sfs.send(new SFS2X.ExtensionRequest("add", params));
}

function onExtensionResponse(evtParams)
{
	if (evtParams.cmd == "add")
	{
		var responseParams = evtParams.params;

		// We expect an integer called "sum"
		console.log("The sum is: " + responseParams.getInt("sum"));
	}
}

Parameters

Name Type Optional Description

extCmd

 

 

The name of the command, which identifies an action that should be executed by the server-side Extension.

params

 

Yes

An SFSObject containing custom data to be sent to the Extension. Can be null if no data needs to be sent.

Defaults to null.

room

 

Yes

If null, the specified command is sent to the current Zone server-side Extension; if not null, the command is sent to the server-side Extension attached to the passed Room.

Defaults to null.

See also
SmartFox#send
SFSEvent.EXTENSION_RESPONSE