Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

libamf

1.3.2 • Public • Published

libamf

An Action Message Format library for node.js.

Dependencies License

Usage

Parser/Serializer

const libamf = require('libamf');
 
const data = libamf.serialize(5, libamf.ENCODING.AMF3);
const int = libamf.deserialize(data, libamf.ENCODING.AMF3);

Server

const {Server, Service} = require('libamf');
 
class PizzaService extends Service {
    constructor() {
        super('pizza');
        
        this.register('order', 'handleOrder');
        this.register('cancelOrder', this.cancelOrder.bind(this));
        this.register('asyncMethod', 'asyncMethod');
    }
    
    handleOrder(pizza, message) {
        message.respond({ status: 1, message: pizza.type + ' pizza ordered!'});
    }
    
    cancelOrder(pizza, message) {
        const id = pizza.id;
        
        return { status: 1, message: 'Order ' + id + ' has been cancelled successfully.'};
    }
 
    asyncMethod(message) {
        return new Promise((resolve, reject) => {
            resolve('this will be sent as a response');
        });
    }
}
 
const server = new Server();
 
// You can also just do this
server.on('data', packet => {
    console.log(packet);
});
 
server.registerService(pizzaService);
server.listen(8080, () => {
    console.log('Listening on port 8080');
});

You can stop services from enforcing the -service suffix to the name by doing:

libamf.Service.ForceSuffix = false;

You can also allow any service method to be used without registration by doing:

libamf.Service.RequireRegistration = false;

If you wish to return other values in your service methods, you can disable responding with return values using:

libamf.Service.ReturnResponses = false;

To write whole numbers as integers, use this:

libamf.AMF3.AssumeIntegers = true;

To disable the default homepage, use:

libamf.Server.DisableDefaultHome = true;

Client

const {Client} = require('libamf');
const client = new Client();
 
client.connect('http://localhost:8080/');
client.call('pizza-service.order', { type: 'cheese' }).then(res => {
    console.log(res);
});

SOL

const fs = require('fs');
const libamf = require('libamf');
 
fs.readFile('path/to/file.sol', (err, data) => {
    console.log(libamf.SOL.read(data));
 
    const newObj = new libamf.SOL.LSO({
        allow: false,
        always: false,
        allowsecure: false,
        alwayssecure: false,
        klimit: 100,
        hstsEnabled: false,
        hstsMaxAge: '0',
        hstsIncSubDomain: false,
        hstsStartTime: '0'
    });
    newObj.filename = 'domain/settings';
    newObj.version = 0;
 
    console.log(newObj.write());
});

Supported types

AMF0

Type Read Write Note
Null
Undefined
String
Long String
Number
Boolean
Reference
Strict Array
ECMA Array
Typed Object
Date
AVMPLUS
XML

AMF3

Type Read Write Note
Undefined
Null
String
Double
Integer
Boolean
Date
Array
Dictionary
Vector
Byte Array
Custom object
XML

TODO

  • Better documentation
  • Better tests
  • Better TODO

Install

npm i libamf

DownloadsWeekly Downloads

6

Version

1.3.2

License

MIT

Unpacked Size

92.6 kB

Total Files

30

Last publish

Collaborators

  • avatar