Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vertexvis/stream-api

Package Overview
Dependencies
Maintainers
5
Versions
625
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vertexvis/stream-api - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

82

dist/bundle.cjs.js

@@ -5,68 +5,6 @@ 'use strict';

var tslib = require('tslib');
var utils = require('@vertexvis/utils');
var frameStreamingProtos = require('@vertexvis/frame-streaming-protos');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
var WS_RECONNECT_DELAYS = [0, 1000, 1000, 5000];

@@ -117,6 +55,6 @@ var WebSocketClient = /** @class */ (function () {

WebSocketClient.prototype.connect = function (urlProvider) {
return __awaiter(this, void 0, void 0, function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var urlAndProtocol;
var _this = this;
return __generator(this, function (_a) {
return tslib.__generator(this, function (_a) {
urlAndProtocol = urlProvider();

@@ -146,6 +84,6 @@ this.webSocket = new WebSocket(urlAndProtocol.url, urlAndProtocol.protocols);

WebSocketClient.prototype.reconnect = function (urlProvider) {
return __awaiter(this, void 0, void 0, function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var e_1;
var _this = this;
return __generator(this, function (_a) {
return tslib.__generator(this, function (_a) {
switch (_a.label) {

@@ -198,5 +136,5 @@ case 0: return [4 /*yield*/, new Promise(function (resolve) {

StreamApi.prototype.connect = function (urlProvider) {
return __awaiter(this, void 0, void 0, function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return tslib.__generator(this, function (_a) {
switch (_a.label) {

@@ -233,4 +171,4 @@ case 0: return [4 /*yield*/, this.websocket.connect(urlProvider)];

if (withResponse === void 0) { withResponse = true; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
return [2 /*return*/, this.sendRequest({

@@ -276,3 +214,3 @@ reconnect: data,

var requestId_1 = utils.UUID.create();
request = __assign({ requestId: {
request = tslib.__assign({ requestId: {
value: requestId_1,

@@ -279,0 +217,0 @@ } }, request);

2

dist/bundle.cjs.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@vertexvis/utils"),t=require("@vertexvis/frame-streaming-protos"),n=function(){return(n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function r(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{u(r.next(e))}catch(e){s(e)}}function c(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(i,c)}u((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}var s=[0,1e3,1e3,5e3],i=function(){function t(t){var n=this;void 0===t&&(t=s),this.reconnectDelays=t,this.onMessageDispatcher=new e.EventDispatcher,this.reopenAttempt=0,this.addWebSocketListeners=function(e,t,r){var o=function(){return n.onOpen(t)},s=function(){return r()};return e.addEventListener("message",n.handleMessage),e.addEventListener("open",o),e.addEventListener("error",s),e.addEventListener("close",n.handleClose),{dispose:function(){e.removeEventListener("message",n.handleMessage),e.removeEventListener("open",o),e.removeEventListener("error",s),e.removeEventListener("close",n.handleClose)}}},this.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(){n.removeWebSocketListeners(),null!=n.urlProvider&&n.reconnect(n.urlProvider)}}return t.prototype.close=function(){null!=this.webSocket&&(this.removeWebSocketListeners(),this.webSocket.close(),null!=this.timer&&(window.clearTimeout(this.timer),this.webSocket=void 0))},t.prototype.connect=function(e){return r(this,void 0,void 0,(function(){var t,n=this;return o(this,(function(r){return t=e(),this.webSocket=new WebSocket(t.url,t.protocols),this.webSocket.binaryType="arraybuffer",this.urlProvider=e,[2,new Promise((function(e,t){null!=n.webSocket&&(n.listeners=n.addWebSocketListeners(n.webSocket,e,t))}))]}))}))},t.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},t.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},t.prototype.reconnect=function(e){return r(this,void 0,void 0,(function(){var t=this;return o(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(e){t.timer=window.setTimeout(e,t.reconnectDelays[Math.min(t.reopenAttempt,t.reconnectDelays.length-1)])}))];case 1:n.sent(),this.reopenAttempt+=1,n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this.connect(e)];case 3:return n.sent(),[3,5];case 4:return n.sent(),[3,5];case 5:return[2]}}))}))},t.prototype.removeWebSocketListeners=function(){var e;null===(e=this.listeners)||void 0===e||e.dispose()},t.prototype.onOpen=function(e){this.reopenAttempt=0,e()},t}();var c=function(){function s(t){void 0===t&&(t=new i),this.websocket=t,this.onResponseDispatcher=new e.EventDispatcher,this.onRequestDispatcher=new e.EventDispatcher}return s.prototype.connect=function(e){return r(this,void 0,void 0,(function(){var t=this;return o(this,(function(n){switch(n.label){case 0:return[4,this.websocket.connect(e)];case 1:return n.sent(),this.messageSubscription=this.websocket.onMessage((function(e){t.handleMessage(e)})),[2,{dispose:function(){return t.dispose()}}]}}))}))},s.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},s.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},s.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},s.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},s.prototype.reconnect=function(e,t){return void 0===t&&(t=!0),r(this,void 0,void 0,(function(){return o(this,(function(n){return[2,this.sendRequest({reconnect:e},t)]}))}))},s.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},s.prototype.replaceCamera=function(e,t){var n=e.camera;return void 0===t&&(t=!0),this.sendRequest({updateCamera:{camera:n}},t)},s.prototype.hitItems=function(e,t){var n=e.point;return void 0===t&&(t=!0),this.sendRequest({hitItems:{point:n}},t)},s.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},s.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},s.prototype.sendRequest=function(r,o){var s=this;if(o){var i=e.UUID.create();return r=n({requestId:{value:i}},r),new Promise((function(e){var n=s.onResponse((function(t){var r;i===(null===(r=t.requestId)||void 0===r?void 0:r.value)&&(e(t),n.dispose())}));s.websocket.send(t.vertexvis.protobuf.stream.StreamMessage.encode({request:r}).finish())}))}return this.websocket.send(t.vertexvis.protobuf.stream.StreamMessage.encode({request:r}).finish()),Promise.resolve({})},s.prototype.handleMessage=function(e){var n,r,o=(n=e.data,r=new Uint8Array(n),t.vertexvis.protobuf.stream.StreamMessage.decode(r));null!=o&&null!=o.response&&this.onResponseDispatcher.emit(o.response),null!=o&&null!=o.request&&this.onRequestDispatcher.emit(o.request)},s}();exports.StreamApi=c,exports.WebSocketClient=i;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@vertexvis/utils"),n=require("@vertexvis/frame-streaming-protos"),r=[0,1e3,1e3,5e3],s=function(){function n(e){var n=this;void 0===e&&(e=r),this.reconnectDelays=e,this.onMessageDispatcher=new t.EventDispatcher,this.reopenAttempt=0,this.addWebSocketListeners=function(e,t,r){var s=function(){return n.onOpen(t)},o=function(){return r()};return e.addEventListener("message",n.handleMessage),e.addEventListener("open",s),e.addEventListener("error",o),e.addEventListener("close",n.handleClose),{dispose:function(){e.removeEventListener("message",n.handleMessage),e.removeEventListener("open",s),e.removeEventListener("error",o),e.removeEventListener("close",n.handleClose)}}},this.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(){n.removeWebSocketListeners(),null!=n.urlProvider&&n.reconnect(n.urlProvider)}}return n.prototype.close=function(){null!=this.webSocket&&(this.removeWebSocketListeners(),this.webSocket.close(),null!=this.timer&&(window.clearTimeout(this.timer),this.webSocket=void 0))},n.prototype.connect=function(t){return e.__awaiter(this,void 0,void 0,(function(){var n,r=this;return e.__generator(this,(function(e){return n=t(),this.webSocket=new WebSocket(n.url,n.protocols),this.webSocket.binaryType="arraybuffer",this.urlProvider=t,[2,new Promise((function(e,t){null!=r.webSocket&&(r.listeners=r.addWebSocketListeners(r.webSocket,e,t))}))]}))}))},n.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},n.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},n.prototype.reconnect=function(t){return e.__awaiter(this,void 0,void 0,(function(){var n=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){n.timer=window.setTimeout(e,n.reconnectDelays[Math.min(n.reopenAttempt,n.reconnectDelays.length-1)])}))];case 1:e.sent(),this.reopenAttempt+=1,e.label=2;case 2:return e.trys.push([2,4,,5]),[4,this.connect(t)];case 3:return e.sent(),[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},n.prototype.removeWebSocketListeners=function(){var e;null===(e=this.listeners)||void 0===e||e.dispose()},n.prototype.onOpen=function(e){this.reopenAttempt=0,e()},n}();var o=function(){function r(e){void 0===e&&(e=new s),this.websocket=e,this.onResponseDispatcher=new t.EventDispatcher,this.onRequestDispatcher=new t.EventDispatcher}return r.prototype.connect=function(t){return e.__awaiter(this,void 0,void 0,(function(){var n=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.websocket.connect(t)];case 1:return e.sent(),this.messageSubscription=this.websocket.onMessage((function(e){n.handleMessage(e)})),[2,{dispose:function(){return n.dispose()}}]}}))}))},r.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},r.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},r.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},r.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},r.prototype.reconnect=function(t,n){return void 0===n&&(n=!0),e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){return[2,this.sendRequest({reconnect:t},n)]}))}))},r.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},r.prototype.replaceCamera=function(e,t){var n=e.camera;return void 0===t&&(t=!0),this.sendRequest({updateCamera:{camera:n}},t)},r.prototype.hitItems=function(e,t){var n=e.point;return void 0===t&&(t=!0),this.sendRequest({hitItems:{point:n}},t)},r.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},r.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},r.prototype.sendRequest=function(r,s){var o=this;if(s){var i=t.UUID.create();return r=e.__assign({requestId:{value:i}},r),new Promise((function(e){var t=o.onResponse((function(n){var r;i===(null===(r=n.requestId)||void 0===r?void 0:r.value)&&(e(n),t.dispose())}));o.websocket.send(n.vertexvis.protobuf.stream.StreamMessage.encode({request:r}).finish())}))}return this.websocket.send(n.vertexvis.protobuf.stream.StreamMessage.encode({request:r}).finish()),Promise.resolve({})},r.prototype.handleMessage=function(e){var t,r,s=(t=e.data,r=new Uint8Array(t),n.vertexvis.protobuf.stream.StreamMessage.decode(r));null!=s&&null!=s.response&&this.onResponseDispatcher.emit(s.response),null!=s&&null!=s.request&&this.onRequestDispatcher.emit(s.request)},r}();exports.StreamApi=o,exports.WebSocketClient=s;
//# sourceMappingURL=bundle.cjs.min.js.map

@@ -0,67 +1,5 @@

import { __awaiter, __generator, __assign } from 'tslib';
import { EventDispatcher, UUID } from '@vertexvis/utils';
import { vertexvis } from '@vertexvis/frame-streaming-protos';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
var WS_RECONNECT_DELAYS = [0, 1000, 1000, 5000];

@@ -68,0 +6,0 @@ var WebSocketClient = /** @class */ (function () {

@@ -1,16 +0,2 @@

import{EventDispatcher as e,UUID as t}from"@vertexvis/utils";import{vertexvis as n}from"@vertexvis/frame-streaming-protos";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var r=function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function o(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{u(r.next(e))}catch(e){s(e)}}function c(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(i,c)}u((r=r.apply(e,t||[])).next())}))}function s(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}var i=[0,1e3,1e3,5e3],c=function(){function t(t){var n=this;void 0===t&&(t=i),this.reconnectDelays=t,this.onMessageDispatcher=new e,this.reopenAttempt=0,this.addWebSocketListeners=function(e,t,r){var o=function(){return n.onOpen(t)},s=function(){return r()};return e.addEventListener("message",n.handleMessage),e.addEventListener("open",o),e.addEventListener("error",s),e.addEventListener("close",n.handleClose),{dispose:function(){e.removeEventListener("message",n.handleMessage),e.removeEventListener("open",o),e.removeEventListener("error",s),e.removeEventListener("close",n.handleClose)}}},this.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(){n.removeWebSocketListeners(),null!=n.urlProvider&&n.reconnect(n.urlProvider)}}return t.prototype.close=function(){null!=this.webSocket&&(this.removeWebSocketListeners(),this.webSocket.close(),null!=this.timer&&(window.clearTimeout(this.timer),this.webSocket=void 0))},t.prototype.connect=function(e){return o(this,void 0,void 0,(function(){var t,n=this;return s(this,(function(r){return t=e(),this.webSocket=new WebSocket(t.url,t.protocols),this.webSocket.binaryType="arraybuffer",this.urlProvider=e,[2,new Promise((function(e,t){null!=n.webSocket&&(n.listeners=n.addWebSocketListeners(n.webSocket,e,t))}))]}))}))},t.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},t.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},t.prototype.reconnect=function(e){return o(this,void 0,void 0,(function(){var t=this;return s(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(e){t.timer=window.setTimeout(e,t.reconnectDelays[Math.min(t.reopenAttempt,t.reconnectDelays.length-1)])}))];case 1:n.sent(),this.reopenAttempt+=1,n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this.connect(e)];case 3:return n.sent(),[3,5];case 4:return n.sent(),[3,5];case 5:return[2]}}))}))},t.prototype.removeWebSocketListeners=function(){var e;null===(e=this.listeners)||void 0===e||e.dispose()},t.prototype.onOpen=function(e){this.reopenAttempt=0,e()},t}();var u=function(){function i(t){void 0===t&&(t=new c),this.websocket=t,this.onResponseDispatcher=new e,this.onRequestDispatcher=new e}return i.prototype.connect=function(e){return o(this,void 0,void 0,(function(){var t=this;return s(this,(function(n){switch(n.label){case 0:return[4,this.websocket.connect(e)];case 1:return n.sent(),this.messageSubscription=this.websocket.onMessage((function(e){t.handleMessage(e)})),[2,{dispose:function(){return t.dispose()}}]}}))}))},i.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},i.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},i.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},i.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},i.prototype.reconnect=function(e,t){return void 0===t&&(t=!0),o(this,void 0,void 0,(function(){return s(this,(function(n){return[2,this.sendRequest({reconnect:e},t)]}))}))},i.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},i.prototype.replaceCamera=function(e,t){var n=e.camera;return void 0===t&&(t=!0),this.sendRequest({updateCamera:{camera:n}},t)},i.prototype.hitItems=function(e,t){var n=e.point;return void 0===t&&(t=!0),this.sendRequest({hitItems:{point:n}},t)},i.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},i.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},i.prototype.sendRequest=function(e,o){var s=this;if(o){var i=t.create();return e=r({requestId:{value:i}},e),new Promise((function(t){var r=s.onResponse((function(e){var n;i===(null===(n=e.requestId)||void 0===n?void 0:n.value)&&(t(e),r.dispose())}));s.websocket.send(n.protobuf.stream.StreamMessage.encode({request:e}).finish())}))}return this.websocket.send(n.protobuf.stream.StreamMessage.encode({request:e}).finish()),Promise.resolve({})},i.prototype.handleMessage=function(e){var t,r,o=(t=e.data,r=new Uint8Array(t),n.protobuf.stream.StreamMessage.decode(r));null!=o&&null!=o.response&&this.onResponseDispatcher.emit(o.response),null!=o&&null!=o.request&&this.onRequestDispatcher.emit(o.request)},i}();export{u as StreamApi,c as WebSocketClient};
import{__awaiter as e,__generator as t,__assign as n}from"tslib";import{EventDispatcher as o,UUID as s}from"@vertexvis/utils";import{vertexvis as r}from"@vertexvis/frame-streaming-protos";var i=[0,1e3,1e3,5e3],c=function(){function n(e){var t=this;void 0===e&&(e=i),this.reconnectDelays=e,this.onMessageDispatcher=new o,this.reopenAttempt=0,this.addWebSocketListeners=function(e,n,o){var s=function(){return t.onOpen(n)},r=function(){return o()};return e.addEventListener("message",t.handleMessage),e.addEventListener("open",s),e.addEventListener("error",r),e.addEventListener("close",t.handleClose),{dispose:function(){e.removeEventListener("message",t.handleMessage),e.removeEventListener("open",s),e.removeEventListener("error",r),e.removeEventListener("close",t.handleClose)}}},this.handleMessage=function(e){t.onMessageDispatcher.emit(e)},this.handleClose=function(){t.removeWebSocketListeners(),null!=t.urlProvider&&t.reconnect(t.urlProvider)}}return n.prototype.close=function(){null!=this.webSocket&&(this.removeWebSocketListeners(),this.webSocket.close(),null!=this.timer&&(window.clearTimeout(this.timer),this.webSocket=void 0))},n.prototype.connect=function(n){return e(this,void 0,void 0,(function(){var e,o=this;return t(this,(function(t){return e=n(),this.webSocket=new WebSocket(e.url,e.protocols),this.webSocket.binaryType="arraybuffer",this.urlProvider=n,[2,new Promise((function(e,t){null!=o.webSocket&&(o.listeners=o.addWebSocketListeners(o.webSocket,e,t))}))]}))}))},n.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},n.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},n.prototype.reconnect=function(n){return e(this,void 0,void 0,(function(){var e=this;return t(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t){e.timer=window.setTimeout(t,e.reconnectDelays[Math.min(e.reopenAttempt,e.reconnectDelays.length-1)])}))];case 1:t.sent(),this.reopenAttempt+=1,t.label=2;case 2:return t.trys.push([2,4,,5]),[4,this.connect(n)];case 3:return t.sent(),[3,5];case 4:return t.sent(),[3,5];case 5:return[2]}}))}))},n.prototype.removeWebSocketListeners=function(){var e;null===(e=this.listeners)||void 0===e||e.dispose()},n.prototype.onOpen=function(e){this.reopenAttempt=0,e()},n}();var u=function(){function i(e){void 0===e&&(e=new c),this.websocket=e,this.onResponseDispatcher=new o,this.onRequestDispatcher=new o}return i.prototype.connect=function(n){return e(this,void 0,void 0,(function(){var e=this;return t(this,(function(t){switch(t.label){case 0:return[4,this.websocket.connect(n)];case 1:return t.sent(),this.messageSubscription=this.websocket.onMessage((function(t){e.handleMessage(t)})),[2,{dispose:function(){return e.dispose()}}]}}))}))},i.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},i.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},i.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},i.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},i.prototype.reconnect=function(n,o){return void 0===o&&(o=!0),e(this,void 0,void 0,(function(){return t(this,(function(e){return[2,this.sendRequest({reconnect:n},o)]}))}))},i.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},i.prototype.replaceCamera=function(e,t){var n=e.camera;return void 0===t&&(t=!0),this.sendRequest({updateCamera:{camera:n}},t)},i.prototype.hitItems=function(e,t){var n=e.point;return void 0===t&&(t=!0),this.sendRequest({hitItems:{point:n}},t)},i.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},i.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},i.prototype.sendRequest=function(e,t){var o=this;if(t){var i=s.create();return e=n({requestId:{value:i}},e),new Promise((function(t){var n=o.onResponse((function(e){var o;i===(null===(o=e.requestId)||void 0===o?void 0:o.value)&&(t(e),n.dispose())}));o.websocket.send(r.protobuf.stream.StreamMessage.encode({request:e}).finish())}))}return this.websocket.send(r.protobuf.stream.StreamMessage.encode({request:e}).finish()),Promise.resolve({})},i.prototype.handleMessage=function(e){var t,n,o=(t=e.data,n=new Uint8Array(t),r.protobuf.stream.StreamMessage.decode(n));null!=o&&null!=o.response&&this.onResponseDispatcher.emit(o.response),null!=o&&null!=o.request&&this.onRequestDispatcher.emit(o.request)},i}();export{u as StreamApi,c as WebSocketClient};
//# sourceMappingURL=bundle.esm.min.js.map
{
"name": "@vertexvis/stream-api",
"version": "0.6.0",
"version": "0.6.1",
"description": "A websocket client for interacting with Vertex's stream API.",

@@ -30,3 +30,3 @@ "author": "Dan Schultz <dan.schultz@vertexvis.com>",

"prebuild": "yarn clean",
"build": "./node_modules/@vertexvis/build-tools/bin/build-web.sh",
"build": "rollup --config ./rollup.config.js --silent",
"format": "yarn lint --fix",

@@ -40,13 +40,13 @@ "lint": "eslint --ext .ts,.tsx,.js,.jsx --ignore-path ../../.gitignore .",

"@vertexvis/frame-streaming-protos": "^0.0.21",
"@vertexvis/utils": "0.6.0"
"@vertexvis/utils": "0.6.1"
},
"devDependencies": {
"@types/jest": "^24.0.23",
"@vertexvis/build-tools": "0.7.3",
"@vertexvis/eslint-config-vertexvis-typescript": "0.2.2",
"@vertexvis/jest-config-vertexvis": "0.4.2",
"@vertexvis/typescript-config-vertexvis": "1.0.2",
"@vertexvis/jest-config-vertexvis": "0.4.4",
"@vertexwebsdk/build": "0.6.1",
"eslint": "^6.1.0",
"jest": "^24.9.0",
"protobufjs": "^6.9.0",
"rollup": "^1.19.4",
"ts-jest": "^24.0.2",

@@ -58,3 +58,3 @@ "typescript": "^3.7.4"

},
"gitHead": "e950afff87f090332726c7a1e7a139bacd6da507"
"gitHead": "515783203b4bece966e9e3514bc53d891903e477"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc