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.4.1 to 0.4.2

89

dist/bundle.cjs.js

@@ -79,2 +79,18 @@ 'use strict';

this.reopenAttempt = 0;
this.addWebSocketListeners = function (ws, resolve, reject) {
var onOpen = function () { return _this.onOpen(resolve); };
var onError = function () { return reject(); };
ws.addEventListener('message', _this.handleMessage);
ws.addEventListener('open', onOpen);
ws.addEventListener('error', onError);
ws.addEventListener('close', _this.onClose);
return {
dispose: function () {
ws.removeEventListener('message', _this.handleMessage);
ws.removeEventListener('open', onOpen);
ws.removeEventListener('error', onError);
ws.removeEventListener('close', _this.onClose);
},
};
};
this.handleMessage = function (event) {

@@ -89,3 +105,7 @@ _this.onMessageDispatcher.emit(event);

if (this.webSocket != null) {
this.removeWebSocketListeners();
this.webSocket.close();
if (this.timer != null) {
window.clearTimeout(this.timer);
}
}

@@ -101,28 +121,6 @@ };

this.webSocket.binaryType = 'arraybuffer';
this.urlProvider = urlProvider;
return [2 /*return*/, new Promise(function (resolve, reject) {
var onOpen = function () {
_this.reopenAttempt = 0;
resolve();
};
var onError = function () {
reject();
removeWebSocketListeners();
};
var onClose = function () {
_this.handleClose(urlProvider);
removeWebSocketListeners();
};
var removeWebSocketListeners = function () {
if (_this.webSocket != null) {
_this.webSocket.removeEventListener('message', _this.handleMessage);
_this.webSocket.removeEventListener('open', onOpen);
_this.webSocket.removeEventListener('error', onError);
_this.webSocket.removeEventListener('close', onClose);
}
};
if (_this.webSocket != null) {
_this.webSocket.addEventListener('message', _this.handleMessage);
_this.webSocket.addEventListener('open', onOpen);
_this.webSocket.addEventListener('error', function () { return reject(); });
_this.webSocket.addEventListener('close', onClose);
_this.listeners = _this.addWebSocketListeners(_this.webSocket, resolve, reject);
}

@@ -151,3 +149,3 @@ })];

case 0: return [4 /*yield*/, new Promise(function (resolve) {
return setTimeout(resolve, _this.reconnectDelays[Math.min(_this.reopenAttempt, _this.reconnectDelays.length - 1)]);
_this.timer = window.setTimeout(resolve, _this.reconnectDelays[Math.min(_this.reopenAttempt, _this.reconnectDelays.length - 1)]);
})];

@@ -172,9 +170,23 @@ case 1:

};
WebSocketClient.prototype.onClose = function () {
this.removeWebSocketListeners();
if (this.urlProvider != null) {
this.handleClose(this.urlProvider);
}
};
WebSocketClient.prototype.removeWebSocketListeners = function () {
var _a;
(_a = this.listeners) === null || _a === void 0 ? void 0 : _a.dispose();
};
WebSocketClient.prototype.onOpen = function (resolve) {
this.reopenAttempt = 0;
resolve();
};
return WebSocketClient;
}());
function parseResponse(buffer) {
function parseStreamMessage(buffer) {
var bytes = new Uint8Array(buffer);
var message = frameStreamingProtos.vertexvis.protobuf.stream.StreamMessage.decode(bytes);
return message.response;
return message;
}

@@ -187,2 +199,3 @@

this.onResponseDispatcher = new utils.EventDispatcher();
this.onRequestDispatcher = new utils.EventDispatcher();
}

@@ -213,2 +226,5 @@ StreamApi.prototype.connect = function (urlProvider) {

};
StreamApi.prototype.onRequest = function (handler) {
return this.onRequestDispatcher.on(handler);
};
StreamApi.prototype.startStream = function (data, withResponse) {

@@ -220,2 +236,12 @@ if (withResponse === void 0) { withResponse = true; }

};
StreamApi.prototype.reconnect = function (data, withResponse) {
if (withResponse === void 0) { withResponse = true; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.sendRequest({
reconnect: data,
}, withResponse)];
});
});
};
StreamApi.prototype.beginInteraction = function (withResponse) {

@@ -273,6 +299,9 @@ if (withResponse === void 0) { withResponse = true; }

StreamApi.prototype.handleMessage = function (message) {
var response = parseResponse(message.data);
if (response != null) {
this.onResponseDispatcher.emit(response);
var messagePayload = parseStreamMessage(message.data);
if (messagePayload != null && messagePayload.response != null) {
this.onResponseDispatcher.emit(messagePayload.response);
}
if (messagePayload != null && messagePayload.request != null) {
this.onRequestDispatcher.emit(messagePayload.request);
}
};

@@ -279,0 +308,0 @@ return StreamApi;

@@ -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{a(r.next(e))}catch(e){s(e)}}function c(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(i,c)}a((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.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(e){n.reconnect(e)}}return t.prototype.close=function(){null!=this.webSocket&&this.webSocket.close()},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",[2,new Promise((function(t,r){var o=function(){n.reopenAttempt=0,t()},s=function(){r(),c()},i=function(){n.handleClose(e),c()},c=function(){null!=n.webSocket&&(n.webSocket.removeEventListener("message",n.handleMessage),n.webSocket.removeEventListener("open",o),n.webSocket.removeEventListener("error",s),n.webSocket.removeEventListener("close",i))};null!=n.webSocket&&(n.webSocket.addEventListener("message",n.handleMessage),n.webSocket.addEventListener("open",o),n.webSocket.addEventListener("error",(function(){return r()})),n.webSocket.addEventListener("close",i))}))]}))}))},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){return 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}();var c=function(){function s(t){void 0===t&&(t=new i),this.websocket=t,this.onResponseDispatcher=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.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream: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).response);null!=o&&this.onResponseDispatcher.emit(o)},s}();exports.StreamApi=c,exports.WebSocketClient=i;
"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.onClose),{dispose:function(){e.removeEventListener("message",n.handleMessage),e.removeEventListener("open",o),e.removeEventListener("error",s),e.removeEventListener("close",n.onClose)}}},this.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(e){n.reconnect(e)}}return t.prototype.close=function(){null!=this.webSocket&&(this.removeWebSocketListeners(),this.webSocket.close(),null!=this.timer&&window.clearTimeout(this.timer))},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.onClose=function(){this.removeWebSocketListeners(),null!=this.urlProvider&&this.handleClose(this.urlProvider)},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;
//# sourceMappingURL=bundle.cjs.min.js.map

@@ -75,2 +75,18 @@ import { EventDispatcher, UUID } from '@vertexvis/utils';

this.reopenAttempt = 0;
this.addWebSocketListeners = function (ws, resolve, reject) {
var onOpen = function () { return _this.onOpen(resolve); };
var onError = function () { return reject(); };
ws.addEventListener('message', _this.handleMessage);
ws.addEventListener('open', onOpen);
ws.addEventListener('error', onError);
ws.addEventListener('close', _this.onClose);
return {
dispose: function () {
ws.removeEventListener('message', _this.handleMessage);
ws.removeEventListener('open', onOpen);
ws.removeEventListener('error', onError);
ws.removeEventListener('close', _this.onClose);
},
};
};
this.handleMessage = function (event) {

@@ -85,3 +101,7 @@ _this.onMessageDispatcher.emit(event);

if (this.webSocket != null) {
this.removeWebSocketListeners();
this.webSocket.close();
if (this.timer != null) {
window.clearTimeout(this.timer);
}
}

@@ -97,28 +117,6 @@ };

this.webSocket.binaryType = 'arraybuffer';
this.urlProvider = urlProvider;
return [2 /*return*/, new Promise(function (resolve, reject) {
var onOpen = function () {
_this.reopenAttempt = 0;
resolve();
};
var onError = function () {
reject();
removeWebSocketListeners();
};
var onClose = function () {
_this.handleClose(urlProvider);
removeWebSocketListeners();
};
var removeWebSocketListeners = function () {
if (_this.webSocket != null) {
_this.webSocket.removeEventListener('message', _this.handleMessage);
_this.webSocket.removeEventListener('open', onOpen);
_this.webSocket.removeEventListener('error', onError);
_this.webSocket.removeEventListener('close', onClose);
}
};
if (_this.webSocket != null) {
_this.webSocket.addEventListener('message', _this.handleMessage);
_this.webSocket.addEventListener('open', onOpen);
_this.webSocket.addEventListener('error', function () { return reject(); });
_this.webSocket.addEventListener('close', onClose);
_this.listeners = _this.addWebSocketListeners(_this.webSocket, resolve, reject);
}

@@ -147,3 +145,3 @@ })];

case 0: return [4 /*yield*/, new Promise(function (resolve) {
return setTimeout(resolve, _this.reconnectDelays[Math.min(_this.reopenAttempt, _this.reconnectDelays.length - 1)]);
_this.timer = window.setTimeout(resolve, _this.reconnectDelays[Math.min(_this.reopenAttempt, _this.reconnectDelays.length - 1)]);
})];

@@ -168,9 +166,23 @@ case 1:

};
WebSocketClient.prototype.onClose = function () {
this.removeWebSocketListeners();
if (this.urlProvider != null) {
this.handleClose(this.urlProvider);
}
};
WebSocketClient.prototype.removeWebSocketListeners = function () {
var _a;
(_a = this.listeners) === null || _a === void 0 ? void 0 : _a.dispose();
};
WebSocketClient.prototype.onOpen = function (resolve) {
this.reopenAttempt = 0;
resolve();
};
return WebSocketClient;
}());
function parseResponse(buffer) {
function parseStreamMessage(buffer) {
var bytes = new Uint8Array(buffer);
var message = vertexvis.protobuf.stream.StreamMessage.decode(bytes);
return message.response;
return message;
}

@@ -183,2 +195,3 @@

this.onResponseDispatcher = new EventDispatcher();
this.onRequestDispatcher = new EventDispatcher();
}

@@ -209,2 +222,5 @@ StreamApi.prototype.connect = function (urlProvider) {

};
StreamApi.prototype.onRequest = function (handler) {
return this.onRequestDispatcher.on(handler);
};
StreamApi.prototype.startStream = function (data, withResponse) {

@@ -216,2 +232,12 @@ if (withResponse === void 0) { withResponse = true; }

};
StreamApi.prototype.reconnect = function (data, withResponse) {
if (withResponse === void 0) { withResponse = true; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.sendRequest({
reconnect: data,
}, withResponse)];
});
});
};
StreamApi.prototype.beginInteraction = function (withResponse) {

@@ -269,6 +295,9 @@ if (withResponse === void 0) { withResponse = true; }

StreamApi.prototype.handleMessage = function (message) {
var response = parseResponse(message.data);
if (response != null) {
this.onResponseDispatcher.emit(response);
var messagePayload = parseStreamMessage(message.data);
if (messagePayload != null && messagePayload.response != null) {
this.onResponseDispatcher.emit(messagePayload.response);
}
if (messagePayload != null && messagePayload.request != null) {
this.onRequestDispatcher.emit(messagePayload.request);
}
};

@@ -275,0 +304,0 @@ return StreamApi;

@@ -15,3 +15,3 @@ import{EventDispatcher as e,UUID as t}from"@vertexvis/utils";import{vertexvis as n}from"@vertexvis/frame-streaming-protos";

and limitations under the License.
***************************************************************************** */var o=function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function r(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{a(o.next(e))}catch(e){s(e)}}function c(e){try{a(o.throw(e))}catch(e){s(e)}}function a(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(i,c)}a((o=o.apply(e,t||[])).next())}))}function s(e,t){var n,o,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=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.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(e){n.reconnect(e)}}return t.prototype.close=function(){null!=this.webSocket&&this.webSocket.close()},t.prototype.connect=function(e){return r(this,void 0,void 0,(function(){var t,n=this;return s(this,(function(o){return t=e(),this.webSocket=new WebSocket(t.url,t.protocols),this.webSocket.binaryType="arraybuffer",[2,new Promise((function(t,o){var r=function(){n.reopenAttempt=0,t()},s=function(){o(),c()},i=function(){n.handleClose(e),c()},c=function(){null!=n.webSocket&&(n.webSocket.removeEventListener("message",n.handleMessage),n.webSocket.removeEventListener("open",r),n.webSocket.removeEventListener("error",s),n.webSocket.removeEventListener("close",i))};null!=n.webSocket&&(n.webSocket.addEventListener("message",n.handleMessage),n.webSocket.addEventListener("open",r),n.webSocket.addEventListener("error",(function(){return o()})),n.webSocket.addEventListener("close",i))}))]}))}))},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 s(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(e){return 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}();var a=function(){function i(t){void 0===t&&(t=new c),this.websocket=t,this.onResponseDispatcher=new e}return i.prototype.connect=function(e){return r(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.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream: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,r){var s=this;if(r){var i=t.create();return e=o({requestId:{value:i}},e),new Promise((function(t){var o=s.onResponse((function(e){var n;i===(null===(n=e.requestId)||void 0===n?void 0:n.value)&&(t(e),o.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,o,r=(t=e.data,o=new Uint8Array(t),n.protobuf.stream.StreamMessage.decode(o).response);null!=r&&this.onResponseDispatcher.emit(r)},i}();export{a as StreamApi,c as WebSocketClient};
***************************************************************************** */var o=function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function r(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function c(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(i,c)}u((o=o.apply(e,t||[])).next())}))}function s(e,t){var n,o,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=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,o){var r=function(){return n.onOpen(t)},s=function(){return o()};return e.addEventListener("message",n.handleMessage),e.addEventListener("open",r),e.addEventListener("error",s),e.addEventListener("close",n.onClose),{dispose:function(){e.removeEventListener("message",n.handleMessage),e.removeEventListener("open",r),e.removeEventListener("error",s),e.removeEventListener("close",n.onClose)}}},this.handleMessage=function(e){n.onMessageDispatcher.emit(e)},this.handleClose=function(e){n.reconnect(e)}}return t.prototype.close=function(){null!=this.webSocket&&(this.removeWebSocketListeners(),this.webSocket.close(),null!=this.timer&&window.clearTimeout(this.timer))},t.prototype.connect=function(e){return r(this,void 0,void 0,(function(){var t,n=this;return s(this,(function(o){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 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.onClose=function(){this.removeWebSocketListeners(),null!=this.urlProvider&&this.handleClose(this.urlProvider)},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 r(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),r(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,r){var s=this;if(r){var i=t.create();return e=o({requestId:{value:i}},e),new Promise((function(t){var o=s.onResponse((function(e){var n;i===(null===(n=e.requestId)||void 0===n?void 0:n.value)&&(t(e),o.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,o,r=(t=e.data,o=new Uint8Array(t),n.protobuf.stream.StreamMessage.decode(o));null!=r&&null!=r.response&&this.onResponseDispatcher.emit(r.response),null!=r&&null!=r.request&&this.onRequestDispatcher.emit(r.request)},i}();export{u as StreamApi,c as WebSocketClient};
//# sourceMappingURL=bundle.esm.min.js.map
import { vertexvis } from '@vertexvis/frame-streaming-protos';
export declare function parseResponse(buffer: ArrayBuffer): vertexvis.protobuf.stream.IStreamResponse | null | undefined;
export declare function parseStreamMessage(buffer: ArrayBuffer): vertexvis.protobuf.stream.IStreamMessage;
import { WebSocketClient } from './webSocketClient';
import { UrlProvider } from './url';
import { HitItemsPayload, ReplaceCameraPayload, StartStreamPayload } from './types';
import { HitItemsPayload, ReconnectPayload, ReplaceCameraPayload, StartStreamPayload } from './types';
import { vertexvis } from '@vertexvis/frame-streaming-protos';
import { Disposable } from '@vertexvis/utils';
declare type ResponseHandler = (response: vertexvis.protobuf.stream.IStreamResponse) => void;
declare type RequestHandler = (request: vertexvis.protobuf.stream.IStreamRequest) => void;
export declare class StreamApi {
private websocket;
private onResponseDispatcher;
private onRequestDispatcher;
private messageSubscription?;

@@ -15,3 +17,5 @@ constructor(websocket?: WebSocketClient);

onResponse(handler: ResponseHandler): Disposable;
onRequest(handler: RequestHandler): Disposable;
startStream(data: StartStreamPayload, withResponse?: boolean): Promise<vertexvis.protobuf.stream.IStreamResponse>;
reconnect(data: ReconnectPayload, withResponse?: boolean): Promise<vertexvis.protobuf.stream.IStreamResponse>;
beginInteraction(withResponse?: boolean): Promise<vertexvis.protobuf.stream.IStreamResponse>;

@@ -18,0 +22,0 @@ replaceCamera({ camera }: ReplaceCameraPayload, withResponse?: boolean): Promise<vertexvis.protobuf.stream.IStreamResponse>;

import { DeepRequired } from '@vertexvis/utils';
import { vertexvis } from '@vertexvis/frame-streaming-protos';
export declare type StartStreamPayload = DeepRequired<vertexvis.protobuf.stream.IStartStreamPayload, ['frameCorrelationId']>;
export declare type ReconnectPayload = DeepRequired<vertexvis.protobuf.stream.IReconnectPayload, ['frameCorrelationId']>;
export declare type ReplaceCameraPayload = DeepRequired<vertexvis.protobuf.stream.IUpdateCameraPayload, ['frameCorrelationId']>;
export declare type HitItemsPayload = DeepRequired<vertexvis.protobuf.stream.IHitItemsPayload, []>;

@@ -10,2 +10,5 @@ import { Disposable } from '@vertexvis/utils';

private reopenAttempt;
private urlProvider?;
private timer?;
private listeners?;
constructor(reconnectDelays?: number[]);

@@ -20,5 +23,9 @@ close(): void;

reconnect(urlProvider: UrlProvider): Promise<void>;
private onClose;
private addWebSocketListeners;
private removeWebSocketListeners;
private handleMessage;
private handleClose;
private onOpen;
}
export {};
{
"name": "@vertexvis/stream-api",
"version": "0.4.1",
"version": "0.4.2",
"description": "A websocket client for interacting with Vertex's stream API.",

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

"@vertexvis/frame-streaming-protos": "^0.0.21",
"@vertexvis/utils": "0.4.1"
"@vertexvis/utils": "0.4.2"
},

@@ -57,3 +57,3 @@ "devDependencies": {

},
"gitHead": "34d6ab27273bbcf39c12f8b6b7518278d441a6b1"
"gitHead": "376a455e09afb52b508626ed806b8613c8001406"
}

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