Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Constructor for creating a endpoint object with video xapi.
- const util = require('util');
- const EventEmitter = require('events').EventEmitter;
- const jsxapi = require('jsxapi');
- //pass in object
- function TPXapi(endpoint){
- this.endpoint = endpoint;
- this.xapi;
- this.connectedStatus = 'false';
- this.domain = '.webex.com';
- this.mysite = 'mysite';
- this.init();
- }
- util.inherits(TPXapi,EventEmitter);
- TPXapi.prototype.init = function(){
- const self = this;
- return self.connect()
- .then((status) =>{
- console.log(status);
- self.onReady();
- return;
- })
- .catch((err) => {
- console.error(err);
- })
- }
- //connect to ssh service on endpoints
- TPXapi.prototype.connect = function() {
- var self = this;
- return new Promise((resolve, reject) => {
- self.xapi = jsxapi.connect('ssh://' + self.endpoint.ipAddress, {
- username: self.endpoint.username,
- password: self.endpoint.password,
- keepaliveInterval: 4000
- });
- self.onError();
- resolve ("Connection opening..........")
- .catch ((err) => {
- reject (console.error(err));
- });
- });
- }
- //Load event monitoring after connecting via ssh to endpoint
- TPXapi.prototype.onReady = function(){
- const self = this;
- self.xapi.on('ready', () => {
- console.log("connexion successful!");
- self.connectedStatus = "true";
- self.webexMeeting();
- return self;
- })
- };
- //event monitors for webex meetings
- TPXapi.prototype.webexMeeting = function(){
- const self =this;
- self.xapi.event.on('UserInterface Extensions Event PageOpened', (event) => {
- console.log('event', event.PageId);
- if (event.PageId == 'webex_dial') {
- //Intial press of webex button
- self.xapi.command('UserInterface Message TextInput Display', {
- FeedbackId: 'MeetingID_webex',
- InputType: 'Numeric',
- KeyboardState: 'Open',
- Title: 'Join a Webex Meeting',
- Text: 'Enter the Meeting ID',
- Placeholder: 'Meeting ID',
- SubmitText: 'Join'
- });
- }
- });
- //Making calling to webex meeeting once ID is entered.
- self.xapi.event.on('UserInterface Message TextInput Response', (event) => {
- if (event.FeedbackId === 'MeetingID_webex') {
- var ID = event.Text;
- var URI = ID + '@' +self.mysite+ self.domain;
- self.xapi.command('Dial', { Number: URI });
- }
- });
- };
- //track ssh error events and reconnect
- TPXapi.prototype.onError = function(){
- const self = this;
- self.xapi.on('error', (err) => {
- console.error(`connexion failed: ${err}, exiting`);
- setTimeout(function(){
- self.init();
- }, 4000)
- });
- };
- module.exports = TPXapi;
Add Comment
Please, Sign In to add comment