@@ -13,7 +13,7 @@ if (!window.console) {
1313 window . console . log = window . console . log || function ( ) { } ;
1414}
1515
16- function createClearBladeInstance ( window , undefined ) {
16+ function createClearBladeInstance ( window , options ) {
1717 // 'use strict';
1818 var ClearBlade ;
1919 /**
@@ -754,25 +754,7 @@ function createClearBladeInstance (window, undefined) {
754754 httpRequest . send ( body ) ;
755755 } ;
756756
757- ClearBlade . getMessageTopic = function ( destinationName , callbackDict ) {
758- const destArr = destinationName . split ( '/' ) ;
759- for ( const topic in callbackDict ) {
760- const topicArr = topic . split ( '/' ) ;
761- for ( let i = 0 ; i < destArr . length ; i ++ ) {
762- if ( topicArr [ i ] === '#' ) {
763- return topic ;
764- }
765- if ( destArr [ i ] !== topicArr [ i ] && topicArr [ i ] !== '+' ) {
766- break ;
767- }
768- if ( i === destArr . length - 1 ) {
769- return topic ;
770- }
771- }
772- }
773- } ;
774-
775- ClearBlade . request = function ( options , callback ) {
757+ ClearBlade . request = options . request || function ( options , callback ) {
776758 if ( ! options || typeof options !== 'object' ) {
777759 throw new Error ( 'Request: options is not an object or is empty' ) ;
778760 }
@@ -1637,17 +1619,20 @@ function createClearBladeInstance (window, undefined) {
16371619 * }
16381620 * })
16391621 */
1640- code . execute = function ( name , params , callback , id ) {
1622+ code . execute = function ( name , params , callback , options ) {
1623+ if ( typeof options === 'undefined' ) {
1624+ options = { } ;
1625+ }
16411626 var reqOptions = {
16421627 method : 'POST' ,
16431628 endpoint : 'api/v/1/code/' + this . systemKey + '/' + name ,
16441629 body : params ,
16451630 user : this . user ,
16461631 URI : this . URI ,
1647- timeout : this . callTimeout ,
1632+ timeout : options . requestTimeout || this . callTimeout ,
16481633 } ;
1649- if ( id ) {
1650- reqOptions . endpoint = reqOptions . endpoint + '?id=' + id ;
1634+ if ( options . id ) {
1635+ reqOptions . endpoint = reqOptions . endpoint + '?id=' + options . id ;
16511636 }
16521637 if ( typeof callback === 'function' ) {
16531638 ClearBlade . request ( reqOptions , callback ) ;
@@ -2116,7 +2101,7 @@ function createClearBladeInstance (window, undefined) {
21162101 // messageCallbacks from Subscribe() may contain multiple callbacks per topic
21172102 const callbacks = Object . values (
21182103 messageCallbacks [
2119- ClearBlade . getMessageTopic ( message . destinationName , messageCallbacks )
2104+ getMessageTopic ( message . destinationName , messageCallbacks )
21202105 ]
21212106 ) ;
21222107 for ( var theCallback of callbacks ) {
@@ -3732,13 +3717,31 @@ function createClearBladeInstance (window, undefined) {
37323717 } ;
37333718 ClearBlade . request ( reqOptions , callback ) ;
37343719 } ;
3735-
37363720 return ClearBlade ;
37373721}
37383722
3723+ function getMessageTopic ( destinationName , callbackDict ) {
3724+ const destArr = destinationName . split ( '/' ) ;
3725+ for ( const topic in callbackDict ) {
3726+ const topicArr = topic . split ( '/' ) ;
3727+ for ( let i = 0 ; i < destArr . length ; i ++ ) {
3728+ if ( topicArr [ i ] === '#' ) {
3729+ return topic ;
3730+ }
3731+ if ( destArr [ i ] !== topicArr [ i ] && topicArr [ i ] !== '+' ) {
3732+ break ;
3733+ }
3734+ if ( i === destArr . length - 1 ) {
3735+ return topic ;
3736+ }
3737+ }
3738+ }
3739+ }
3740+
37393741module . exports = {
3740- ClearBlade : function ( ) {
3741- const cb = createClearBladeInstance ( window ) ;
3742+ ClearBlade : function ( options ) {
3743+ const cb = createClearBladeInstance ( window , options || { } ) ;
37423744 return new cb ( ) ;
3743- }
3745+ } ,
3746+ getMessageTopic
37443747} ;
0 commit comments