Code Monkey home page Code Monkey logo

Comments (6)

emilkm avatar emilkm commented on August 26, 2024

espinaca,

You can use this library but with some limitations. As it was designed mainly with mobile development in mind, a great deal of effort was spent in removing all "unnecessary" functionality. You may also notice that only the bare minimum fields in all remoting objects are sent/received. This was done with the intention to reduce the amount of data transferred while still being able to use the AMF protocol.

I know that Adobe have an AMF Client library specifically designed for HTML5/Javascript with full support for ChannelsSets, Channels, etc. If you are after the smoothest ride your best bet is try that library.

Using amfjs would require some additional work on the server as well as the client. I have primarily worked against a modified AMFPHP server. Also tested against a bare minimum BlazeDS server, but only to verify packets are encoded and decoded correctly.

davidef forked this library at https://github.com/davidef/amfjs, and, I think, is using it with BlazeDS sever. He may be able to help you better with BlazeDS.

Kind Regards
Emil

from amfjs.

espinaca avatar espinaca commented on August 26, 2024

Mr Emil, thank you very much for your quick response, I comment that it had previously reviewed the API Adobe specifically "Lc DS" which contains a javascript AMF client, but I never work for me :(

Your library works fine, the problem is that in the "body" of the message was sending a NULL that caused this exception.

Have a great day.

espinaca.

from amfjs.

emilkm avatar emilkm commented on August 26, 2024

Great to hear you have figured out the problem and that the library works for you.

I had left the body of the CommandMessage with its default value of empty array commented out as an indication.

Good luck with rewriting your application in HTML5. I hope it isn't a big business app :)

I would be interested to know what other JavaScript frameworks you are using.

Cheers
Emil

from amfjs.

Sjafari avatar Sjafari commented on August 26, 2024

Hi @espinaca and @emilkm,

I am also struggling to create an amf client which communicates with a BlazeDS server.
I would love to use your library but is there any examples or tutorials that I can refer to?
Atleast the basics like sending request/recieving response of a simple comand & remoting message. Creating custom remoting message etc.

Any help will be much appreciated.
Thanks

from amfjs.

collinforrester avatar collinforrester commented on August 26, 2024

@emilkm Could you put some example code in here on how you were able to replicate the ChannelSet.login functionality? The source link you provided now requires authentication.

I'm able to make regular AMF calls if they're not secured. But all other calls require me to auth with ChannelSet first.

from amfjs.

emilkm avatar emilkm commented on August 26, 2024

Hi,

The source link was provided by @espinaca

Howerver, BlazeDS is open source and it was contributed to Apache. A Mirror of Apache Flex BlazeDS can be found here https://github.com/apache/flex-blazeds

An example that works with https://github.com/emilkm/efxphp can be found here https://github.com/emilkm/efxphp-bootplate/blob/master/public/amfjssaucer.html

holdQueue can be used to hold the queue while you setup a session for example.

var endpoint = window.location.href.substr(0, window.location.href.lastIndexOf('/')) + "/server/index.php";
var amfClient = new amf.Client("efxphp", endpoint);
amfClient.invoke("myapp.server.MyService", "init", [],
    function(response, token) {
        console.log(response.data);
        amfClient.setSessionId(response.data);
        amfClient.releaseQueue();
    },
    function(error, token) {
        console.log("init error");
    },
    "init",
    true
);

amfClient.invoke("myapp.server.MyService", "publicMethodNoParams", [],
        function (response, token) {
            console.log(response.data);
        },
        function (response) {
            console.log("publicMethodNoParams error");
        }
);
amfClient.invoke("myapp.server.MyService", "publicMethodOptionalParam", [],
        function (response, token) {
            console.log(response.data);
        },
        function (error, token) {
            console.log("publicMethodOptionalParam error");
        }
);
amfClient.invoke("myapp.server.MyService", "publicMethodMandatoryParam", [1],
        function (response) {
            console.log(response.data);
        },
        function (error, token) {
            console.log("publicMethodMandatoryParam error");
        }
);

Lets say the server will return an error for all requests that do not have a valid session. You want to avoid making such requests.
You can first invoke an init method, setups a session, telling the library to hold the queue until you release it. Then without having to structure your code in such as to wait for the session to be setup, you continue with further requests. These would be held in the queue until you release the queue by executing releaseQueue();

You can pass any credentials to the init method.

The only supported command message is CLIENT_PING_OPERATION. That is sent automatically by the library before the first request.

I do not work with BlazeDS, but think it may be possibly to establish a session manually. I think that the way ChannelSet.login works is that it will create a session and pass it back to client telling it to appendToGatewayUrl. Subsequent requests then have the sessionId as part of the URL.

Assuming I am correct, you can achieve the same result with the above example.

amfClient.setSessionId('sessionidvalue');

Sets the session id. Here is what the method looks like

amf.Client.prototype.setSessionId = function(value, releaseQueue) {
    this.sessionId = value;

    if (this.sidPropagation == "header") {
        this.addHeader('sID', this.sessionId);
    } else {
        this.endpoint += '?sID=' + this.sessionId;
    }

    if (releaseQueue === true) {
        this.releaseQueue();
    }
};

One may need to change the session variable name to 'jsessionid', or whatever BlazeDS expects

The session is propagated in one of the two currently supported ways

  • AMF header
  • Query String

I have never had the need to customize the RemotingMessage before. It really depends on what the server is expecting. Sure, I have removed properties from the Command Message

CommandMessage: function() {
        return {
            _explicitType: "flex.messaging.messages.CommandMessage",
            destination: "",
            operation: 5,
            //body: [],
            //headers: {DSId:"nil"},
            clientId: null
        };
    },

knowing that my server never uses those, and does not break if they are not present.

If BlazeDS or any other server insists on having those, then they should be part of the message.

If you do want to customize the RemotingMessage, you could simply change the library a bit, by adding, removing, or modifying properties in the RemotingMessage

RemotingMessage: function() {
        return {
            _explicitType: "flex.messaging.messages.RemotingMessage",
            destination: "",
            source: "",
            operation: "",
            body: [],
            headers: {DSId: "nil"},
            clientId: null
        };
    },

Hope this helps.

from amfjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.