dist/functions.js
/**
 * Displays the current time once a second.
 * @customfunction CONNECT_TO_SIGNALR
 * @param channel channel to connect to
 */
Displays the current time once a second.
@customfunction CONNECT_TO_SIGNALR
@param channel channel to connect to
Displays the current time once a second . @customfunction CONNECT_TO_SIGNALR @param channel channel to connect to
function initSignalR(channel, invocation) {
  return __awaiter(this, void 0, void 0, function () {
    var res, response, options, connection, error_1;
    var _this = this;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          _a.trys.push([0, 4,, 5]);
          return [4
          , getSignalRInfo()];
        case 1:
          res = _a.sent();
          if (!(typeof res === "string")) return [3
          , 3];
          response = JSON.parse(res);
          options = {
            accessTokenFactory: function () {
              return response.accessToken;
            }
          };
          connection = new signalr_1.HubConnectionBuilder().withUrl(response.url, options).build();
          connection.on(channel, function (message) {
            console.log(message);
            invocation.setResult("Message received: " + message);
          });
          invocation.onCanceled = function () {
            return __awaiter(_this, void 0, void 0, function () {
              return __generator(this, function (_a) {
                switch (_a.label) {
                  case 0:
                    return [4
                    , connection.stop()];
                  case 1:
                    _a.sent();
                    console.log("disconnected");
                    return [2
                    ];
                }
              });
            });
          };
          return [4
          , connection.start()];
        case 2:
          _a.sent();
          console.log("connected");
          _a.label = 3;
        case 3:
          return [3
          , 5];
        case 4:
          error_1 = _a.sent();
          console.error(error_1);
          return [3
          , 5];
        case 5:
          return [2
          ];
      }
    });
  });
}
function initSignalR ( channel , invocation ) { return __awaiter ( this , void 0 , void 0 , function ( ) { var res , response , options , connection , error_1 ; var _this = this ; return __generator ( this , function ( _a ) { switch ( _a . label ) { case 0 : _a . trys . push ( [ 0 , 4 , , 5 ] ) ; return [ 4 , getSignalRInfo ( ) ] ; case 1 : res = _a . sent ( ) ; if ( ! ( typeof res === "string" ) ) return [ 3 , 3 ] ; response = JSON . parse ( res ) ; options = { accessTokenFactory : function ( ) { return response . accessToken ; } } ; connection = new signalr_1 . HubConnectionBuilder ( ) . withUrl ( response . url , options ) . build ( ) ; connection . on ( channel , function ( message ) { console . log ( message ) ; invocation . setResult ( "Message received: " + message ) ; } ) ; invocation . onCanceled = function ( ) { return __awaiter ( _this , void 0 , void 0 , function ( ) { return __generator ( this , function ( _a ) { switch ( _a . label ) { case 0 : return [ 4 , connection . stop ( ) ] ; case 1 : _a . sent ( ) ; console . log ( "disconnected" ) ; return [ 2 ] ; } } ) ; } ) ; } ; return [ 4 , connection . start ( ) ] ; case 2 : _a . sent ( ) ; console . log ( "connected" ) ; _a . label = 3 ; case 3 : return [ 3 , 5 ] ; case 4 : error_1 = _a . sent ( ) ; console . error ( error_1 ) ; return [ 3 , 5 ] ; case 5 : return [ 2 ] ; } } ) ; } ) ; }
Displays the current time once a second.
Displays the current time once a second .
/*yield*/ /*break*/ /*yield*/ /*return*/ /*yield*/ /*break*/ /*break*/ /*return*/