Skip to content

Latest commit

History

76 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

libamf

An Action Message Format library for node.js.

DependenciesLicense

Usage

Parser/Serializer

constlibamf=require('libamf');constdata=libamf.serialize(5,libamf.ENCODING.AMF3);constint=libamf.deserialize(data,libamf.ENCODING.AMF3);

Server

const{Server, Service}=require('libamf');classPizzaServiceextendsService{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){constid=pizza.id;return{status: 1,message: 'Order '+id+' has been cancelled successfully.'};}asyncMethod(message){returnnewPromise((resolve,reject)=>{resolve('this will be sent as a response');});}}constserver=newServer();// You can also just do thisserver.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');constclient=newClient();client.connect('http://localhost:8080/');client.call('pizza-service.order',{type: 'cheese'}).then(res=>{console.log(res);});

SOL

constfs=require('fs');constlibamf=require('libamf');fs.readFile('path/to/file.sol',(err,data)=>{console.log(libamf.SOL.read(data));constnewObj=newlibamf.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

TypeReadWriteNote
Null
Undefined
String
Long String
Number
Boolean
Reference
Strict Array
ECMA Array
Typed Object
Date
AVMPLUS
XML

AMF3

TypeReadWriteNote
Undefined
Null
String
Double
Integer
Boolean
Date
Array
Dictionary
Vector
Byte Array
Custom object
XML

TODO

  • Better documentation
  • Better tests
  • Better TODO

About

Action Message Format library for node.js.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages