Skip to content

emilkm/enyo-amf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

enyo-amf

AMF Remoting for Enyo

Enyo-AMF is an Enyo AMF 3 Client library plugin.

Enyo-AMF mimics the Enyo Ajax package which includes amf xhr (Amfx) functionality, and an implementation of amf xhr as a Component (AmfService).

A basic example

This example is based on the enyo bootplate application

enyo.kind({
	name: "App",
	kind: "FittableRows",
	fit: true,
    create: function() {
        this.inherited(arguments);
        enyo.amf.init("amfphp", "http://127.0.0.1/server/gateway.php");
    },
	components:[
		{kind: "onyx.Toolbar", content: "Hello World"},
		{kind: "enyo.Scroller", fit: true, components: [
			{name: "main", classes: "nice-padding", allowHtml: true}
		]},
		{kind: "onyx.Toolbar", components: [
			{kind: "onyx.Button", content: "Tap me", ontap: "helloWorldTap"}
		]}
	],
	helloWorldTap: function(inSender, inEvent) {
		this.$.main.addContent("ping<br/>");
        var amfx = new enyo.Amfx({
            source: "test",
            operation: "ping"
        });
        amfx.response(this, "processResponse");
        amfx.error(this, "processError");
		amfx.go();
    },
    processResponse: function(inSender, inResponse) {
        this.$.main.addContent(inResponse.data + "<br/>");
    },
    processError: function(inSender, inResponse) {
        this.$.main.addContent(inResponse.data);
    }
});
enyo.amf.init("amfphp", "http://127.0.0.1/server/gateway.php");

enyo.amf.init sets the destination and endpoint of the AMF Client.

var amfx = new enyo.Amfx({
	source: "test",
	operation: "ping"
});
amfx.response(this, "processResponse");
amfx.error(this, "processError");
amfx.go();

Sends and AMF request to the test service, invoking the ping method with no parameters.

processResponse: function(inSender, inResponse) {
	this.$.main.addContent(inResponse.data + "<br/>");
},
processError: function(inSender, inResponse) {
	this.$.main.addContent(inResponse.data);
}

The processResponse and processError display the response data depending on the outcome of the operation.

The PHP service is very simple and looks like this.

<?php
class test
{
    public function ping()
	{
		return 'pong';
	}
}
?>

If the AMF Client has not been assigned a clientId by the server, a flex.messaging.messages.CommandMessage with a CLIENT_PING_OPERATION will be sent to the server first, in order to test connectivity over the current channel to the remote endpoint, and get a clientId assigned.

About

AMF Remoting for Enyo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published