Skip to content

drakeman/amfjs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

amfjs

AMFJS is an AMF 3 Client JavaScript library

It is based on Surrey's R-AMF (AMF 99) implementation https://code.google.com/p/r-amf/

Why no AMF 0

The library does enough AMF 0 to be able to send and receive packet headers.

Basic Example

Here is a AMFJS Ping Pong example:

<!doctype html>
<html>
<head>
    <title>AMFJS</title>
    <script src="amf.js" type="text/javascript"></script>
</head>
<body>
    <script type="text/javascript">
        var amfClient = new amf.Client("amfphp", "http://127.0.0.1/server/gateway.php");
        amfClient.invoke("test", "ping", [],
            function(data) {
                console.log(data);
            },
            function(data) {
                console.log("ping errror");
            }
        );
    </script>
</body>
</html>

This example loads amf.js, which makes the amf global object available.

var amfClient = amf.Client("amfphp", "http://127.0.0.1/server/gateway.php");

A new AMF Client instance is created, and initialized with the desired destination and endpoint.

amfClient.invoke("test", "ping", [],
    function(data) {
        console.log(data);
    },
    function(data) {
        console.log("ping errror");
    }
);

Sends and AMF request to the test service, invoking the ping method with no parameters. onResult and onStatus callback functions are also passed to the the invoke method.

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.

Framework Integration

  1. EnyoJs plugin

About

A JavaScript AMF 3 Client library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%