NumminorihSF / ami-io

Use node.js or io.js to manage Asterisk through AMI
MIT License
30 stars 16 forks source link

How can I create new Actions and events without modifying the original package #3

Closed raarts closed 8 years ago

raarts commented 8 years ago

Also see this stackoverflow question: I've already succeeded in overloading the auth function, how can I overload the Login action (or create a new one), and in general create new Actions and Events?

I do not want to fork the original package for a few lines of code changes.

NumminorihSF commented 8 years ago

You can use:

var AmiIo = require('ami-io');
AmiIo.Action.Login = function NewConstructor(){}; //to override Login action
//new constructor shold extend AmiIo.Action.Action(actionName)
//and also, you can use
AmiIo.Action.SomeNewAction = function SomeNewAction(){};//to create new actuion
//it also should extend AmiIo.Action.Action(actionName);

AmiIo.Action is just an Object. All constructors are fields of it.

To create new events you don't need to do anything, because it is just an object. If server send to you

Event: Armageddon
SomeField: 123

ami-io will create event with name 'Armageddon'.

To override Client#auth() method, you just should do

var AmiIo = require('ami-io');
AmiIo.Client.prototype.auth = function (){};//new function