Guest User

Untitled

a guest
Aug 3rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. //Constructor for creating a endpoint object with video xapi.
  2. const util = require('util');
  3. const EventEmitter = require('events').EventEmitter;
  4. const jsxapi = require('jsxapi');
  5.  
  6. //pass in object
  7. function TPXapi(endpoint){
  8. this.endpoint = endpoint;
  9. this.xapi;
  10. this.connectedStatus = 'false';
  11. this.domain = '.webex.com';
  12. this.mysite = 'mysite';
  13. this.init();
  14. }
  15. util.inherits(TPXapi,EventEmitter);
  16. TPXapi.prototype.init = function(){
  17. const self = this;
  18. return self.connect()
  19. .then((status) =>{
  20. console.log(status);
  21. self.onReady();
  22. return;
  23. })
  24. .catch((err) => {
  25. console.error(err);
  26. })
  27. }
  28. //connect to ssh service on endpoints
  29. TPXapi.prototype.connect = function() {
  30. var self = this;
  31. return new Promise((resolve, reject) => {
  32. self.xapi = jsxapi.connect('ssh://' + self.endpoint.ipAddress, {
  33. username: self.endpoint.username,
  34. password: self.endpoint.password,
  35. keepaliveInterval: 4000
  36. });
  37. self.onError();
  38. resolve ("Connection opening..........")
  39. .catch ((err) => {
  40. reject (console.error(err));
  41. });
  42. });
  43. }
  44. //Load event monitoring after connecting via ssh to endpoint
  45. TPXapi.prototype.onReady = function(){
  46. const self = this;
  47. self.xapi.on('ready', () => {
  48. console.log("connexion successful!");
  49. self.connectedStatus = "true";
  50. self.webexMeeting();
  51. return self;
  52. })
  53. };
  54. //event monitors for webex meetings
  55. TPXapi.prototype.webexMeeting = function(){
  56. const self =this;
  57. self.xapi.event.on('UserInterface Extensions Event PageOpened', (event) => {
  58. console.log('event', event.PageId);
  59. if (event.PageId == 'webex_dial') {
  60. //Intial press of webex button
  61. self.xapi.command('UserInterface Message TextInput Display', {
  62. FeedbackId: 'MeetingID_webex',
  63. InputType: 'Numeric',
  64. KeyboardState: 'Open',
  65. Title: 'Join a Webex Meeting',
  66. Text: 'Enter the Meeting ID',
  67. Placeholder: 'Meeting ID',
  68. SubmitText: 'Join'
  69. });
  70. }
  71. });
  72. //Making calling to webex meeeting once ID is entered.
  73. self.xapi.event.on('UserInterface Message TextInput Response', (event) => {
  74. if (event.FeedbackId === 'MeetingID_webex') {
  75. var ID = event.Text;
  76. var URI = ID + '@' +self.mysite+ self.domain;
  77. self.xapi.command('Dial', { Number: URI });
  78. }
  79. });
  80. };
  81. //track ssh error events and reconnect
  82. TPXapi.prototype.onError = function(){
  83. const self = this;
  84. self.xapi.on('error', (err) => {
  85. console.error(`connexion failed: ${err}, exiting`);
  86. setTimeout(function(){
  87. self.init();
  88. }, 4000)
  89. });
  90.  
  91. };
  92. module.exports = TPXapi;
Add Comment
Please, Sign In to add comment