Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamie Knight
committed
Nov 7, 2014
0 parents
commit f87b065
Showing
8 changed files
with
6,719 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Created by .gitignore support plugin (hsz.mobi) | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Commenting this out is preferred by some people, see | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Users Environment Variables | ||
.lock-wscript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
Node API/Library | ||
================ | ||
This module is a wrapper for the [ipcortex PABX API](https://tech.ipcortex.co.uk/api). | ||
|
||
Installation | ||
------------ | ||
To install, simply run: | ||
``` | ||
npm install <GIT_REPO_URL> | ||
``` | ||
|
||
However use this module you will need to download api.js from the PABX you are trying to connect against. A script is included (updateAPI.js) to handle this for you - just provide the HTTP host for it download it from. Otherwise, download the file from http://pabx/api/api.js and place it in lib/api.js - where "pabx" is your PABX's hostname. | ||
|
||
After that, you should be ready to include it in your project. | ||
|
||
Example | ||
------- | ||
```javascript | ||
var ipcAPI = require('./index.js'); | ||
|
||
var IPCortex = ipcAPI('10.0.0.1', 'http'); | ||
|
||
IPCortex.PBX.Auth.login('202t28', '202t28', true, authCB); | ||
|
||
function authCB(ok) { | ||
if ( ok ) { | ||
/* Request the poller starts and initial PABX | ||
* config information is fetched and cached. | ||
* 'go' and 'error' are success/fail callbacks. | ||
* 'error' will be called on any error event. | ||
*/ | ||
IPCortex.PBX.startPoll(go, error); | ||
} | ||
} | ||
function error(n, m) { | ||
console.log('We got an error number: '+n+' Text: '+m); | ||
} | ||
function go() { | ||
console.log('Realtime feed callback says we\'re going'); | ||
|
||
/* Once initialised, request all our owned lines are returned */ | ||
IPCortex.PBX.getLines(linesCB, true); | ||
} | ||
function linesCB(l) { | ||
/* Lines are returned in a list - Hook them all */ | ||
while ( l.length ) { | ||
var line = l.shift(); | ||
var line_id = line.get('line') ; | ||
var line_name = line.get('name'); | ||
|
||
/* In this example we allow the line to go out of scope once hooked | ||
* this is OK as a reference is passed with the callback | ||
*/ | ||
line.hook(lineEvent); | ||
console.log('Got a line: ' + line_id + ' (' + line_name + ')'); | ||
} | ||
} | ||
function lineEvent(f, h, l) { | ||
console.log('Got an event for line: ' + | ||
l.get('line') + ' (' + l.get('name') + ')'); | ||
/* A useful thing to know about a line is it's call info */ | ||
var calls = l.get('calls'); | ||
for ( var x in calls ) { | ||
if ( calls[x].get('state') != 'dead' ) | ||
console.log(calls[x].get('state')); | ||
} | ||
} | ||
``` | ||
|
||
Licence | ||
------- | ||
Copyright (c) 2014, IP Cortex Ltd. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of ipcortex nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var fs = require('fs'); | ||
var vm = require('vm'); | ||
var nodeUtil = require('util'); | ||
|
||
var self = this; | ||
|
||
var Class = require('./lib/class.js'); | ||
var Utils = require('./lib/utils.js'); | ||
|
||
var apiFile = __dirname + '/lib/api.js'; | ||
|
||
/** | ||
* This wraps api.js so it's compatible with the node environment. You should be able to use the api.js from your PABX's | ||
* software version. | ||
* @param locationHost {string} | ||
* @param locationProto {string} | ||
* @returns {IPCortex} | ||
*/ | ||
module.exports = function(locationHost, locationProto) { | ||
var location = { | ||
protocol: locationProto + ':', | ||
host: locationHost | ||
}; | ||
if(!fs.existsSync(apiFile)) { | ||
throw new Error('api.js does not exist! (Have you downloaded it using updateAPI.js?)'); | ||
} | ||
var IPCortex = {}; | ||
IPCortex.Utils = Utils; | ||
IPCortex.XHR = Utils.XHR; | ||
var contextVars = nodeUtil._extend(GLOBAL, { | ||
location: location, | ||
Class: Class, | ||
Utils: Utils, | ||
console: console, | ||
IPCortex: IPCortex | ||
}); | ||
var context = vm.createContext(contextVars); | ||
var api = fs.readFileSync(apiFile, 'utf8'); | ||
vm.runInContext(api, context, apiFile); | ||
IPCortex.PBX.Auth.setHost(locationHost); | ||
return IPCortex; | ||
}; |
Oops, something went wrong.