11"use strict" ;
22
3- var Promise = require ( 'bluebird' ) ;
4- var Nexmo = require ( 'nexmo' ) ;
3+ const Nexmo = require ( 'nexmo' ) ;
54
65/**
76 * Create a new VoiceProxy
87 */
9- var VoiceProxy = function ( config ) {
8+ const VoiceProxy = function ( config ) {
109 this . config = config ;
1110
1211 this . nexmo = new Nexmo ( {
@@ -34,7 +33,7 @@ VoiceProxy.prototype.provisionVirtualNumbers = function() {
3433 console . error ( err ) ;
3534 }
3635 else {
37- var numbers = res . numbers ;
36+ const numbers = res . numbers ;
3837
3938 // For demo purposes:
4039 // - Assume that at least two numbers will be available
@@ -63,7 +62,7 @@ VoiceProxy.prototype.rentNumber = function(number) {
6362 * Configure the number to be associated with the Voice Proxy application.
6463 */
6564VoiceProxy . prototype . configureNumber = function ( number ) {
66- var options = {
65+ const options = {
6766 voiceCallbackType : 'app' ,
6867 voiceCallbackValue : this . config . NEXMO_APP_ID ,
6968 } ;
@@ -104,34 +103,44 @@ VoiceProxy.prototype.createConversation = function(userANumber, userBNumber, cb)
104103/**
105104 * Ensure the given numbers are valid and which country they are associated with.
106105 */
107- VoiceProxy . prototype . checkNumbers = function ( userANumber , userBNumber ) {
108- var niGetPromise = Promise . promisify ( this . nexmo . numberInsight . get , { context : this . nexmo . numberInsight } ) ;
109- var userAGet = niGetPromise ( { level : 'basic' , number : userANumber } ) ;
110- var userBGet = niGetPromise ( { level : 'basic' , number : userBNumber } ) ;
111-
106+ VoiceProxy . prototype . checkNumbers = function ( userANumber , userBNumber ) {
107+ const niGetPromise = ( number ) => new Promise ( ( resolve ) => {
108+ this . nexmo . numberInsight . get ( number , ( error , result ) => {
109+ if ( error ) {
110+ console . error ( 'error' , error ) ;
111+ }
112+ else {
113+ return resolve ( result ) ;
114+ }
115+ } )
116+ } ) ;
117+
118+ const userAGet = niGetPromise ( { level : 'basic' , number : userANumber } ) ;
119+ const userBGet = niGetPromise ( { level : 'basic' , number : userBNumber } ) ;
120+
112121 return Promise . all ( [ userAGet , userBGet ] ) ;
113122} ;
114123
115124/**
116125 * Store the conversation information.
117126 */
118127VoiceProxy . prototype . saveConversation = function ( results ) {
119- var userAResult = results [ 0 ] ;
120- var userANumber = {
128+ const userAResult = results [ 0 ] ;
129+ const userANumber = {
121130 msisdn : userAResult . international_format_number ,
122131 country : userAResult . country_code
123132 } ;
124133
125- var userBResult = results [ 1 ] ;
126- var userBNumber = {
134+ const userBResult = results [ 1 ] ;
135+ const userBNumber = {
127136 msisdn : userBResult . international_format_number ,
128137 country : userBResult . country_code
129138 } ;
130139
131140 // Create conversation object - for demo purposes:
132141 // - Use first indexed LVN for user A
133142 // - Use second indexed LVN for user B
134- var conversation = {
143+ const conversation = {
135144 userA : {
136145 realNumber : userANumber ,
137146 virtualNumber : this . provisionedNumbers [ 0 ]
@@ -169,11 +178,11 @@ VoiceProxy.prototype.sendSMS = function(conversation) {
169178 return conversation ;
170179} ;
171180
172- var fromUserAToUserB = function ( from , to , conversation ) {
181+ const fromUserAToUserB = function ( from , to , conversation ) {
173182 return ( from === conversation . userA . realNumber . msisdn &&
174183 to === conversation . userB . virtualNumber . msisdn ) ;
175184} ;
176- var fromUserBToUserA = function ( from , to , conversation ) {
185+ const fromUserBToUserA = function ( from , to , conversation ) {
177186 return ( from === conversation . userB . realNumber . msisdn &&
178187 to === conversation . userA . virtualNumber . msisdn ) ;
179188} ;
@@ -182,14 +191,14 @@ var fromUserBToUserA = function(from, to, conversation) {
182191 * Work out real number to virual number mapping between users.
183192 */
184193VoiceProxy . prototype . getProxyRoute = function ( from , to ) {
185- var proxyRoute = null ;
186- var conversation ;
187- for ( var i = 0 , l = this . conversations . length ; i < l ; ++ i ) {
194+ let proxyRoute = null ;
195+ let conversation ;
196+ for ( let i = 0 , l = this . conversations . length ; i < l ; ++ i ) {
188197 conversation = this . conversations [ i ] ;
189198
190199 // Use to and from to determine the conversation
191- var fromUserA = fromUserAToUserB ( from , to , conversation ) ;
192- var fromUserB = fromUserBToUserA ( from , to , conversation ) ;
200+ const fromUserA = fromUserAToUserB ( from , to , conversation ) ;
201+ const fromUserB = fromUserBToUserA ( from , to , conversation ) ;
193202
194203 if ( fromUserA || fromUserB ) {
195204 proxyRoute = {
@@ -209,25 +218,25 @@ VoiceProxy.prototype.getProxyRoute = function(from, to) {
209218 */
210219VoiceProxy . prototype . getProxyNCCO = function ( from , to ) {
211220 // Determine how the call should be routed
212- var proxyRoute = this . getProxyRoute ( from , to ) ;
221+ const proxyRoute = this . getProxyRoute ( from , to ) ;
213222
214223 if ( proxyRoute === null ) {
215- var errorText = 'No conversation found' +
224+ const errorText = 'No conversation found' +
216225 ' from: ' + from +
217226 ' to: ' + to ;
218227 throw new Error ( errorText ) ;
219228 }
220229
221230 // Build the NCCO
222- var ncco = [ ] ;
231+ let ncco = [ ] ;
223232
224- var textAction = {
233+ const textAction = {
225234 action : 'talk' ,
226235 text : 'Please wait whilst we connect your call'
227236 } ;
228237 ncco . push ( textAction ) ;
229238
230- var connectAction = {
239+ const connectAction = {
231240 action : 'connect' ,
232241 from : proxyRoute . from . virtualNumber . msisdn ,
233242 endpoint : [ {
0 commit comments