New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vertexvis/stream-api

Package Overview
Dependencies
Maintainers
4
Versions
652
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

to
0.9.24-canary.2

dist/testing/fixtures/events.d.ts

60

dist/bundle.cjs.js

@@ -238,2 +238,3 @@ 'use strict';

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

@@ -287,2 +288,11 @@ /**

/**
* Adds a callback that is invoked when the client receives an event from the
* server. Returns a `Disposable` that can be used to remove the listener.
*
* @param handler - A handler function.
*/
StreamApi.prototype.onEvent = function (handler) {
return this.onEventDispatcher.on(handler);
};
/**
* Sends a request to initiate a streaming session.

@@ -532,14 +542,22 @@ *

this.log('WS message received', msg);
if ((msg === null || msg === void 0 ? void 0 : msg.sentAtTime) != null && (msg === null || msg === void 0 ? void 0 : msg.response) != null) {
this.onResponseDispatcher.emit({
sentAtTime: msg.sentAtTime,
response: msg.response,
});
if ((msg === null || msg === void 0 ? void 0 : msg.sentAtTime) != null) {
if (msg.response != null) {
this.onResponseDispatcher.emit({
sentAtTime: msg.sentAtTime,
response: msg.response,
});
}
if (msg.request != null) {
this.onRequestDispatcher.emit({
sentAtTime: msg.sentAtTime,
request: msg.request,
});
}
if (msg.event != null) {
this.onEventDispatcher.emit({
sentAtTime: msg.sentAtTime,
event: msg.event,
});
}
}
if ((msg === null || msg === void 0 ? void 0 : msg.sentAtTime) != null && (msg === null || msg === void 0 ? void 0 : msg.request) != null) {
this.onRequestDispatcher.emit({
sentAtTime: msg.sentAtTime,
request: msg.request,
});
}
};

@@ -640,7 +658,25 @@ StreamApi.prototype.onResponse = function (handler) {

function event(req, meta) {
return tslib.__assign({ sentAtTime: currentDateAsProtoTimestamp(), event: tslib.__assign({}, req) }, meta);
}
function animationCompleted(id) {
var def = {
animationId: { hex: id },
};
return event({
animationCompleted: tslib.__assign({}, def),
});
}
var events = /*#__PURE__*/Object.freeze({
__proto__: null,
animationCompleted: animationCompleted
});
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
Requests: requests
Requests: requests,
Events: events
});

@@ -647,0 +683,0 @@

2

dist/bundle.cjs.min.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@vertexvis/frame-streaming-protos"),n=require("tslib"),r=require("@vertexvis/utils"),o=(e=require("long"))&&"object"==typeof e&&"default"in e?e.default:e;function s(e){return t.vertexvis.protobuf.stream.StreamMessage.encode(e).finish()}function i(e){var n=e instanceof ArrayBuffer?new Uint8Array(e):e;return t.vertexvis.protobuf.stream.StreamMessage.decode(n)}var a=function(){function e(){var e=this;this.listeners={},this.onMessageDispatcher=new r.EventDispatcher,this.onCloseDispatcher=new r.EventDispatcher,this.addWebSocketListeners=function(t,n,r,o){var s=function(){return e.onOpen(r)},i=function(){return o()},a=function(t){return e.handleClose(t,n)};return t.addEventListener("message",e.handleMessage),t.addEventListener("open",s),t.addEventListener("error",i),t.addEventListener("close",a),{dispose:function(){t.removeEventListener("message",e.handleMessage),t.removeEventListener("open",s),t.removeEventListener("error",i),t.removeEventListener("close",a)}}},this.handleMessage=function(t){e.onMessageDispatcher.emit(t)},this.handleClose=function(t,n){e.onCloseDispatcher.emit(t),e.removeWebSocketListeners(n)}}return e.prototype.close=function(){null!=this.webSocket&&this.webSocket.close()},e.prototype.connect=function(e){return n.__awaiter(this,void 0,void 0,(function(){var t,o=this;return n.__generator(this,(function(n){return t=r.UUID.create(),this.webSocket=new WebSocket(e.url,e.protocols),this.webSocket.binaryType="arraybuffer",[2,new Promise((function(e,n){null!=o.webSocket&&(o.listeners[t]=o.addWebSocketListeners(o.webSocket,t,e,n))}))]}))}))},e.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},e.prototype.onClose=function(e){return this.onCloseDispatcher.on(e)},e.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},e.prototype.removeWebSocketListeners=function(e){var t;null===(t=this.listeners[e])||void 0===t||t.dispose()},e.prototype.onOpen=function(e){e()},e}();function u(e){var n=e.getTime();return t.google.protobuf.Timestamp.create(d(n))}function c(){return u(new Date)}function d(e){return{seconds:Math.floor(e/1e3),nanos:e%1e3*1e6}}var p=function(e){function t(t,n,r,o){var s=e.call(this,null!=r&&r.length>0?"Stream request failed ("+r+")":"Stream request failed")||this;return s.requestId=t,s.requestPayload=n,s.summary=r,s.details=o,s}return n.__extends(t,e),t}(Error);function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return e.reduce((function(e,r){return n.__assign(n.__assign({},e),r(t))}),{})}}function f(e,t){return m(e,t,(function(e){return"boolean"==typeof e?e?"on":"off":void 0}))}function h(e,t){return m(e,t,(function(e){return"number"==typeof e?e.toString():void 0}))}function v(e,t){return m(e,t,(function(e){return"string"==typeof e?e:void 0}))}function m(e,t,n){return function(r){var o,s=n(r[t]);return null!=s?((o={})[e]=s,o):{}}}function g(e,t){var n={},o=r.Uri.parse(e),s=l(function(e){return y((function(e){return e.EXPERIMENTAL_frameDelivery}),e,l(f("frame-delivery.rate-limit-enabled","rateLimitingEnabled"),h("frame-delivery.packet-loss-threshold","packetLossThreshold"),h("frame-delivery.history-max-size","historyMaxSize"),v("frame-delivery.timeout","timeout"),h("frame-delivery.timeout-ratio-threshold","timeoutRatioThreshold")))}(n.EXPERIMENTAL_frameDelivery),function(e){return y((function(e){return e.EXPERIMENTAL_adaptiveRendering}),e,l(f("adaptive-rendering.enabled","enabled"),v("adaptive-rendering.method","method"),h("adaptive-rendering.jpeg-quality-min","jpegMinQuality"),h("adaptive-rendering.jpeg-quality-max","jpegMaxQuality"),h("adaptive-rendering.image-scale-min","imageMinScale"),h("adaptive-rendering.image-scale-max","imageMaxScale"),h("adaptive-rendering.window-size","windowSize")))}(n.EXPERIMENTAL_adaptiveRendering),function(e){return y((function(e){return e.EXPERIMENTAL_qualityOfService}),e,l(h("qos.history-max-size","historyMaxSize")))}(n.EXPERIMENTAL_qualityOfService))(t);return r.Uri.toString(r.Uri.addQueryParams(s,o))}function y(e,t,n){return function(o){var s=r.Objects.defaults(e(o)||{},t);return n(s)}}var b=function(){function e(e,t){void 0===e&&(e=new a),void 0===t&&(t=!1),this.websocket=e,this.loggingEnabled=t,this.onResponseDispatcher=new r.EventDispatcher,this.onRequestDispatcher=new r.EventDispatcher}return e.prototype.connect=function(e,t){return void 0===t&&(t={}),n.__awaiter(this,void 0,void 0,(function(){var r,o=this;return n.__generator(this,(function(s){switch(s.label){case 0:return r=n.__assign(n.__assign({},e),{url:g(e.url,t)}),[4,this.websocket.connect(r)];case 1:return s.sent(),this.messageSubscription=this.websocket.onMessage((function(e){o.handleMessage(e)})),[2,{dispose:function(){return o.dispose()}}]}}))}))},e.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},e.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},e.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},e.prototype.reconnect=function(e,t){return void 0===t&&(t=!0),n.__awaiter(this,void 0,void 0,(function(){return n.__generator(this,(function(n){return[2,this.sendRequest({reconnect:e},t)]}))}))},e.prototype.updateStream=function(e,t){return void 0===t&&(t=!1),n.__awaiter(this,void 0,void 0,(function(){return n.__generator(this,(function(n){return[2,this.sendRequest({updateStream:e},t)]}))}))},e.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},e.prototype.replaceCamera=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateCamera:e},t)},e.prototype.flyTo=function(e,t){return void 0===t&&(t=!0),this.sendRequest({flyTo:e},t)},e.prototype.updateDimensions=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateDimensions:e},t)},e.prototype.hitItems=function(e,t){return void 0===t&&(t=!0),this.sendRequest({hitItems:e},t)},e.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},e.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},e.prototype.syncTime=function(e,t){return void 0===t&&(t=!0),this.sendRequest({syncTime:e},t)},e.prototype.recordPerformance=function(e,t){return void 0===t&&(t=!0),this.sendRequest({recordPerformance:e},t)},e.prototype.loadSceneViewState=function(e,t){return void 0===t&&(t=!0),this.sendRequest({loadSceneViewState:e},t)},e.prototype.replyResult=function(e,t){this.sendResponse(n.__assign({requestId:{value:e}},t))},e.prototype.replyError=function(e,t){this.sendResponse({requestId:{value:e},error:t})},e.prototype.handleMessage=function(e){var t=i(e.data);this.log("WS message received",t),null!=(null==t?void 0:t.sentAtTime)&&null!=(null==t?void 0:t.response)&&this.onResponseDispatcher.emit({sentAtTime:t.sentAtTime,response:t.response}),null!=(null==t?void 0:t.sentAtTime)&&null!=(null==t?void 0:t.request)&&this.onRequestDispatcher.emit({sentAtTime:t.sentAtTime,request:t.request})},e.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},e.prototype.log=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.loggingEnabled&&console.debug.apply(console,n.__spreadArray([e],t))},e.prototype.sendRequest=function(e,t){var o=this,s=c();if(t){var i=r.UUID.create(),a=n.__assign(n.__assign({},e),{requestId:{value:i}});return new Promise((function(t,n){var r=o.onResponse((function(o){var s;if(i===(null===(s=o.response.requestId)||void 0===s?void 0:s.value)){if(null==o.response.error)t(o.response);else{var a=o.response.error,u=a.message,c=a.details;n(new p(i,e,null==u?void 0:u.value,null==c?void 0:c.value))}r.dispose()}}));o.sendMessage({sentAtTime:s,request:a})}))}return this.sendMessage({sentAtTime:s,request:e}),Promise.resolve({})},e.prototype.sendMessage=function(e){this.websocket.send(s(e)),this.log("WS message sent",e)},e.prototype.sendResponse=function(e){var t=c();this.websocket.send(s({sentAtTime:t,response:e}))},e}();function _(e,t){return n.__assign(n.__assign({sentAtTime:c()},t),{request:n.__assign({requestId:null!=e.requestId?{value:e.requestId}:void 0},e.payload)})}var q=Object.freeze({__proto__:null,drawFrame:function(e,t){void 0===e&&(e={});var n={sequenceNumber:1,sceneAttributes:{camera:{position:{x:0,y:0,z:1},lookAt:{x:0,y:0,z:0},up:{x:0,y:1,z:0}}},imageAttributes:{frameDimensions:{width:200,height:150},imageRect:{x:0,y:0,width:200,height:150},scaleFactor:1},frameCorrelationIds:["123"],image:new Uint8Array};return _({requestId:e.requestId,payload:{drawFrame:r.Objects.defaults(e.payload,n)}},t)},gracefulReconnect:function(e,t){void 0===e&&(e={});var n={streamId:{hex:r.UUID.create()},timeToReconnectDuration:{seconds:1,nanos:0}};return _({requestId:e.requestId,payload:{reconnect:r.Objects.defaults(e.payload,n)}},t)}}),w=Object.freeze({__proto__:null,Requests:q}),S=function(){function e(){this.handlers=new Set,this.sentMessages=new Array}return e.prototype.close=function(){},e.prototype.connect=function(e){return Promise.resolve()},e.prototype.onMessage=function(e){var t=this;return this.handlers.add(e),{dispose:function(){return t.handlers.delete(e)}}},e.prototype.send=function(e){this.sentMessages.push(e)},e.prototype.reconnect=function(e){return Promise.resolve()},e.prototype.receiveMessage=function(e){this.handlers.forEach((function(t){return t(new MessageEvent("message",{data:e}))}))},e.prototype.reset=function(){this.sentMessages=[],this.handlers.clear()},e.prototype.hasNextSent=function(){return this.sentMessages.length>0},e.prototype.nextSent=function(e){var t=this.sentMessages.shift();if(null!=t)return null!=e?e(t):t;throw new Error("Sent messages is empty")},e.prototype.skipSent=function(e){if(void 0===e&&(e=1),!(e<=this.sentMessages.length))throw new Error("Cannot skip the next "+e+" messages. Sent message queue only has "+this.sentMessages.length+" messages.");for(var t=0;t<e;t++)this.nextSent();return this},e}();exports.Fixtures=w,exports.StreamApi=b,exports.WebSocketClientImpl=a,exports.WebSocketClientMock=S,exports.currentDateAsProtoTimestamp=c,exports.decode=i,exports.encode=s,exports.protoToDate=function(e){if(null!=e.seconds&&null!=e.nanos){var t=o.isLong(e.seconds)?e.seconds.toNumber():e.seconds;return new Date(1e3*t+e.nanos/1e6)}},exports.toProtoDuration=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(2===e.length){var r=e[0],o=e[1],s=o.getTime()-r.getTime();return t.google.protobuf.Duration.create(d(s))}if(1===e.length){s=e[0];return t.google.protobuf.Duration.create(d(s))}throw new Error("Expected input to be a number or start and end date.")},exports.toProtoTimestamp=u;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@vertexvis/frame-streaming-protos"),n=require("tslib"),r=require("@vertexvis/utils"),o=(e=require("long"))&&"object"==typeof e&&"default"in e?e.default:e;function s(e){return t.vertexvis.protobuf.stream.StreamMessage.encode(e).finish()}function i(e){var n=e instanceof ArrayBuffer?new Uint8Array(e):e;return t.vertexvis.protobuf.stream.StreamMessage.decode(n)}var a=function(){function e(){var e=this;this.listeners={},this.onMessageDispatcher=new r.EventDispatcher,this.onCloseDispatcher=new r.EventDispatcher,this.addWebSocketListeners=function(t,n,r,o){var s=function(){return e.onOpen(r)},i=function(){return o()},a=function(t){return e.handleClose(t,n)};return t.addEventListener("message",e.handleMessage),t.addEventListener("open",s),t.addEventListener("error",i),t.addEventListener("close",a),{dispose:function(){t.removeEventListener("message",e.handleMessage),t.removeEventListener("open",s),t.removeEventListener("error",i),t.removeEventListener("close",a)}}},this.handleMessage=function(t){e.onMessageDispatcher.emit(t)},this.handleClose=function(t,n){e.onCloseDispatcher.emit(t),e.removeWebSocketListeners(n)}}return e.prototype.close=function(){null!=this.webSocket&&this.webSocket.close()},e.prototype.connect=function(e){return n.__awaiter(this,void 0,void 0,(function(){var t,o=this;return n.__generator(this,(function(n){return t=r.UUID.create(),this.webSocket=new WebSocket(e.url,e.protocols),this.webSocket.binaryType="arraybuffer",[2,new Promise((function(e,n){null!=o.webSocket&&(o.listeners[t]=o.addWebSocketListeners(o.webSocket,t,e,n))}))]}))}))},e.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},e.prototype.onClose=function(e){return this.onCloseDispatcher.on(e)},e.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},e.prototype.removeWebSocketListeners=function(e){var t;null===(t=this.listeners[e])||void 0===t||t.dispose()},e.prototype.onOpen=function(e){e()},e}();function u(e){var n=e.getTime();return t.google.protobuf.Timestamp.create(d(n))}function c(){return u(new Date)}function d(e){return{seconds:Math.floor(e/1e3),nanos:e%1e3*1e6}}var p=function(e){function t(t,n,r,o){var s=e.call(this,null!=r&&r.length>0?"Stream request failed ("+r+")":"Stream request failed")||this;return s.requestId=t,s.requestPayload=n,s.summary=r,s.details=o,s}return n.__extends(t,e),t}(Error);function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return e.reduce((function(e,r){return n.__assign(n.__assign({},e),r(t))}),{})}}function f(e,t){return m(e,t,(function(e){return"boolean"==typeof e?e?"on":"off":void 0}))}function h(e,t){return m(e,t,(function(e){return"number"==typeof e?e.toString():void 0}))}function v(e,t){return m(e,t,(function(e){return"string"==typeof e?e:void 0}))}function m(e,t,n){return function(r){var o,s=n(r[t]);return null!=s?((o={})[e]=s,o):{}}}function g(e,t){var n={},o=r.Uri.parse(e),s=l(function(e){return y((function(e){return e.EXPERIMENTAL_frameDelivery}),e,l(f("frame-delivery.rate-limit-enabled","rateLimitingEnabled"),h("frame-delivery.packet-loss-threshold","packetLossThreshold"),h("frame-delivery.history-max-size","historyMaxSize"),v("frame-delivery.timeout","timeout"),h("frame-delivery.timeout-ratio-threshold","timeoutRatioThreshold")))}(n.EXPERIMENTAL_frameDelivery),function(e){return y((function(e){return e.EXPERIMENTAL_adaptiveRendering}),e,l(f("adaptive-rendering.enabled","enabled"),v("adaptive-rendering.method","method"),h("adaptive-rendering.jpeg-quality-min","jpegMinQuality"),h("adaptive-rendering.jpeg-quality-max","jpegMaxQuality"),h("adaptive-rendering.image-scale-min","imageMinScale"),h("adaptive-rendering.image-scale-max","imageMaxScale"),h("adaptive-rendering.window-size","windowSize")))}(n.EXPERIMENTAL_adaptiveRendering),function(e){return y((function(e){return e.EXPERIMENTAL_qualityOfService}),e,l(h("qos.history-max-size","historyMaxSize")))}(n.EXPERIMENTAL_qualityOfService))(t);return r.Uri.toString(r.Uri.addQueryParams(s,o))}function y(e,t,n){return function(o){var s=r.Objects.defaults(e(o)||{},t);return n(s)}}var _=function(){function e(e,t){void 0===e&&(e=new a),void 0===t&&(t=!1),this.websocket=e,this.loggingEnabled=t,this.onResponseDispatcher=new r.EventDispatcher,this.onRequestDispatcher=new r.EventDispatcher,this.onEventDispatcher=new r.EventDispatcher}return e.prototype.connect=function(e,t){return void 0===t&&(t={}),n.__awaiter(this,void 0,void 0,(function(){var r,o=this;return n.__generator(this,(function(s){switch(s.label){case 0:return r=n.__assign(n.__assign({},e),{url:g(e.url,t)}),[4,this.websocket.connect(r)];case 1:return s.sent(),this.messageSubscription=this.websocket.onMessage((function(e){o.handleMessage(e)})),[2,{dispose:function(){return o.dispose()}}]}}))}))},e.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},e.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},e.prototype.onEvent=function(e){return this.onEventDispatcher.on(e)},e.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},e.prototype.reconnect=function(e,t){return void 0===t&&(t=!0),n.__awaiter(this,void 0,void 0,(function(){return n.__generator(this,(function(n){return[2,this.sendRequest({reconnect:e},t)]}))}))},e.prototype.updateStream=function(e,t){return void 0===t&&(t=!1),n.__awaiter(this,void 0,void 0,(function(){return n.__generator(this,(function(n){return[2,this.sendRequest({updateStream:e},t)]}))}))},e.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},e.prototype.replaceCamera=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateCamera:e},t)},e.prototype.flyTo=function(e,t){return void 0===t&&(t=!0),this.sendRequest({flyTo:e},t)},e.prototype.updateDimensions=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateDimensions:e},t)},e.prototype.hitItems=function(e,t){return void 0===t&&(t=!0),this.sendRequest({hitItems:e},t)},e.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},e.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},e.prototype.syncTime=function(e,t){return void 0===t&&(t=!0),this.sendRequest({syncTime:e},t)},e.prototype.recordPerformance=function(e,t){return void 0===t&&(t=!0),this.sendRequest({recordPerformance:e},t)},e.prototype.loadSceneViewState=function(e,t){return void 0===t&&(t=!0),this.sendRequest({loadSceneViewState:e},t)},e.prototype.replyResult=function(e,t){this.sendResponse(n.__assign({requestId:{value:e}},t))},e.prototype.replyError=function(e,t){this.sendResponse({requestId:{value:e},error:t})},e.prototype.handleMessage=function(e){var t=i(e.data);this.log("WS message received",t),null!=(null==t?void 0:t.sentAtTime)&&(null!=t.response&&this.onResponseDispatcher.emit({sentAtTime:t.sentAtTime,response:t.response}),null!=t.request&&this.onRequestDispatcher.emit({sentAtTime:t.sentAtTime,request:t.request}),null!=t.event&&this.onEventDispatcher.emit({sentAtTime:t.sentAtTime,event:t.event}))},e.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},e.prototype.log=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.loggingEnabled&&console.debug.apply(console,n.__spreadArray([e],t))},e.prototype.sendRequest=function(e,t){var o=this,s=c();if(t){var i=r.UUID.create(),a=n.__assign(n.__assign({},e),{requestId:{value:i}});return new Promise((function(t,n){var r=o.onResponse((function(o){var s;if(i===(null===(s=o.response.requestId)||void 0===s?void 0:s.value)){if(null==o.response.error)t(o.response);else{var a=o.response.error,u=a.message,c=a.details;n(new p(i,e,null==u?void 0:u.value,null==c?void 0:c.value))}r.dispose()}}));o.sendMessage({sentAtTime:s,request:a})}))}return this.sendMessage({sentAtTime:s,request:e}),Promise.resolve({})},e.prototype.sendMessage=function(e){this.websocket.send(s(e)),this.log("WS message sent",e)},e.prototype.sendResponse=function(e){var t=c();this.websocket.send(s({sentAtTime:t,response:e}))},e}();function b(e,t){return n.__assign(n.__assign({sentAtTime:c()},t),{request:n.__assign({requestId:null!=e.requestId?{value:e.requestId}:void 0},e.payload)})}var w=Object.freeze({__proto__:null,drawFrame:function(e,t){void 0===e&&(e={});var n={sequenceNumber:1,sceneAttributes:{camera:{position:{x:0,y:0,z:1},lookAt:{x:0,y:0,z:0},up:{x:0,y:1,z:0}}},imageAttributes:{frameDimensions:{width:200,height:150},imageRect:{x:0,y:0,width:200,height:150},scaleFactor:1},frameCorrelationIds:["123"],image:new Uint8Array};return b({requestId:e.requestId,payload:{drawFrame:r.Objects.defaults(e.payload,n)}},t)},gracefulReconnect:function(e,t){void 0===e&&(e={});var n={streamId:{hex:r.UUID.create()},timeToReconnectDuration:{seconds:1,nanos:0}};return b({requestId:e.requestId,payload:{reconnect:r.Objects.defaults(e.payload,n)}},t)}});var q=Object.freeze({__proto__:null,animationCompleted:function(e){var t,r,o={animationId:{hex:e}};return t={animationCompleted:n.__assign({},o)},n.__assign({sentAtTime:c(),event:n.__assign({},t)},r)}}),S=Object.freeze({__proto__:null,Requests:w,Events:q}),E=function(){function e(){this.handlers=new Set,this.sentMessages=new Array}return e.prototype.close=function(){},e.prototype.connect=function(e){return Promise.resolve()},e.prototype.onMessage=function(e){var t=this;return this.handlers.add(e),{dispose:function(){return t.handlers.delete(e)}}},e.prototype.send=function(e){this.sentMessages.push(e)},e.prototype.reconnect=function(e){return Promise.resolve()},e.prototype.receiveMessage=function(e){this.handlers.forEach((function(t){return t(new MessageEvent("message",{data:e}))}))},e.prototype.reset=function(){this.sentMessages=[],this.handlers.clear()},e.prototype.hasNextSent=function(){return this.sentMessages.length>0},e.prototype.nextSent=function(e){var t=this.sentMessages.shift();if(null!=t)return null!=e?e(t):t;throw new Error("Sent messages is empty")},e.prototype.skipSent=function(e){if(void 0===e&&(e=1),!(e<=this.sentMessages.length))throw new Error("Cannot skip the next "+e+" messages. Sent message queue only has "+this.sentMessages.length+" messages.");for(var t=0;t<e;t++)this.nextSent();return this},e}();exports.Fixtures=S,exports.StreamApi=_,exports.WebSocketClientImpl=a,exports.WebSocketClientMock=E,exports.currentDateAsProtoTimestamp=c,exports.decode=i,exports.encode=s,exports.protoToDate=function(e){if(null!=e.seconds&&null!=e.nanos){var t=o.isLong(e.seconds)?e.seconds.toNumber():e.seconds;return new Date(1e3*t+e.nanos/1e6)}},exports.toProtoDuration=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(2===e.length){var r=e[0],o=e[1],s=o.getTime()-r.getTime();return t.google.protobuf.Duration.create(d(s))}if(1===e.length){s=e[0];return t.google.protobuf.Duration.create(d(s))}throw new Error("Expected input to be a number or start and end date.")},exports.toProtoTimestamp=u;
//# sourceMappingURL=bundle.cjs.min.js.map

@@ -232,2 +232,3 @@ import { vertexvis, google } from '@vertexvis/frame-streaming-protos';

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

@@ -281,2 +282,11 @@ /**

/**
* Adds a callback that is invoked when the client receives an event from the
* server. Returns a `Disposable` that can be used to remove the listener.
*
* @param handler - A handler function.
*/
StreamApi.prototype.onEvent = function (handler) {
return this.onEventDispatcher.on(handler);
};
/**
* Sends a request to initiate a streaming session.

@@ -526,14 +536,22 @@ *

this.log('WS message received', msg);
if ((msg === null || msg === void 0 ? void 0 : msg.sentAtTime) != null && (msg === null || msg === void 0 ? void 0 : msg.response) != null) {
this.onResponseDispatcher.emit({
sentAtTime: msg.sentAtTime,
response: msg.response,
});
if ((msg === null || msg === void 0 ? void 0 : msg.sentAtTime) != null) {
if (msg.response != null) {
this.onResponseDispatcher.emit({
sentAtTime: msg.sentAtTime,
response: msg.response,
});
}
if (msg.request != null) {
this.onRequestDispatcher.emit({
sentAtTime: msg.sentAtTime,
request: msg.request,
});
}
if (msg.event != null) {
this.onEventDispatcher.emit({
sentAtTime: msg.sentAtTime,
event: msg.event,
});
}
}
if ((msg === null || msg === void 0 ? void 0 : msg.sentAtTime) != null && (msg === null || msg === void 0 ? void 0 : msg.request) != null) {
this.onRequestDispatcher.emit({
sentAtTime: msg.sentAtTime,
request: msg.request,
});
}
};

@@ -634,7 +652,25 @@ StreamApi.prototype.onResponse = function (handler) {

function event(req, meta) {
return __assign({ sentAtTime: currentDateAsProtoTimestamp(), event: __assign({}, req) }, meta);
}
function animationCompleted(id) {
var def = {
animationId: { hex: id },
};
return event({
animationCompleted: __assign({}, def),
});
}
var events = /*#__PURE__*/Object.freeze({
__proto__: null,
animationCompleted: animationCompleted
});
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
Requests: requests
Requests: requests,
Events: events
});

@@ -641,0 +677,0 @@

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

import{vertexvis as e,google as t}from"@vertexvis/frame-streaming-protos";import{__awaiter as n,__generator as r,__extends as o,__assign as s,__spreadArray as i}from"tslib";import{UUID as u,EventDispatcher as a,Uri as c,Objects as d}from"@vertexvis/utils";import p from"long";function l(t){return e.protobuf.stream.StreamMessage.encode(t).finish()}function f(t){var n=t instanceof ArrayBuffer?new Uint8Array(t):t;return e.protobuf.stream.StreamMessage.decode(n)}var h=function(){function e(){var e=this;this.listeners={},this.onMessageDispatcher=new a,this.onCloseDispatcher=new a,this.addWebSocketListeners=function(t,n,r,o){var s=function(){return e.onOpen(r)},i=function(){return o()},u=function(t){return e.handleClose(t,n)};return t.addEventListener("message",e.handleMessage),t.addEventListener("open",s),t.addEventListener("error",i),t.addEventListener("close",u),{dispose:function(){t.removeEventListener("message",e.handleMessage),t.removeEventListener("open",s),t.removeEventListener("error",i),t.removeEventListener("close",u)}}},this.handleMessage=function(t){e.onMessageDispatcher.emit(t)},this.handleClose=function(t,n){e.onCloseDispatcher.emit(t),e.removeWebSocketListeners(n)}}return e.prototype.close=function(){null!=this.webSocket&&this.webSocket.close()},e.prototype.connect=function(e){return n(this,void 0,void 0,(function(){var t,n=this;return r(this,(function(r){return t=u.create(),this.webSocket=new WebSocket(e.url,e.protocols),this.webSocket.binaryType="arraybuffer",[2,new Promise((function(e,r){null!=n.webSocket&&(n.listeners[t]=n.addWebSocketListeners(n.webSocket,t,e,r))}))]}))}))},e.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},e.prototype.onClose=function(e){return this.onCloseDispatcher.on(e)},e.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},e.prototype.removeWebSocketListeners=function(e){var t;null===(t=this.listeners[e])||void 0===t||t.dispose()},e.prototype.onOpen=function(e){e()},e}();function v(e){var n=e.getTime();return t.protobuf.Timestamp.create(b(n))}function m(){return v(new Date)}function g(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(2===e.length){var r=e[0],o=e[1],s=o.getTime()-r.getTime();return t.protobuf.Duration.create(b(s))}if(1===e.length){s=e[0];return t.protobuf.Duration.create(b(s))}throw new Error("Expected input to be a number or start and end date.")}function y(e){if(null!=e.seconds&&null!=e.nanos){var t=p.isLong(e.seconds)?e.seconds.toNumber():e.seconds;return new Date(1e3*t+e.nanos/1e6)}}function b(e){return{seconds:Math.floor(e/1e3),nanos:e%1e3*1e6}}var q=function(e){function t(t,n,r,o){var s=e.call(this,null!=r&&r.length>0?"Stream request failed ("+r+")":"Stream request failed")||this;return s.requestId=t,s.requestPayload=n,s.summary=r,s.details=o,s}return o(t,e),t}(Error);function w(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return e.reduce((function(e,n){return s(s({},e),n(t))}),{})}}function S(e,t){return E(e,t,(function(e){return"boolean"==typeof e?e?"on":"off":void 0}))}function R(e,t){return E(e,t,(function(e){return"number"==typeof e?e.toString():void 0}))}function M(e,t){return E(e,t,(function(e){return"string"==typeof e?e:void 0}))}function E(e,t,n){return function(r){var o,s=n(r[t]);return null!=s?((o={})[e]=s,o):{}}}function T(e,t){var n={},r=c.parse(e),o=w(function(e){return I((function(e){return e.EXPERIMENTAL_frameDelivery}),e,w(S("frame-delivery.rate-limit-enabled","rateLimitingEnabled"),R("frame-delivery.packet-loss-threshold","packetLossThreshold"),R("frame-delivery.history-max-size","historyMaxSize"),M("frame-delivery.timeout","timeout"),R("frame-delivery.timeout-ratio-threshold","timeoutRatioThreshold")))}(n.EXPERIMENTAL_frameDelivery),function(e){return I((function(e){return e.EXPERIMENTAL_adaptiveRendering}),e,w(S("adaptive-rendering.enabled","enabled"),M("adaptive-rendering.method","method"),R("adaptive-rendering.jpeg-quality-min","jpegMinQuality"),R("adaptive-rendering.jpeg-quality-max","jpegMaxQuality"),R("adaptive-rendering.image-scale-min","imageMinScale"),R("adaptive-rendering.image-scale-max","imageMaxScale"),R("adaptive-rendering.window-size","windowSize")))}(n.EXPERIMENTAL_adaptiveRendering),function(e){return I((function(e){return e.EXPERIMENTAL_qualityOfService}),e,w(R("qos.history-max-size","historyMaxSize")))}(n.EXPERIMENTAL_qualityOfService))(t);return c.toString(c.addQueryParams(o,r))}function I(e,t,n){return function(r){var o=d.defaults(e(r)||{},t);return n(o)}}var A=function(){function e(e,t){void 0===e&&(e=new h),void 0===t&&(t=!1),this.websocket=e,this.loggingEnabled=t,this.onResponseDispatcher=new a,this.onRequestDispatcher=new a}return e.prototype.connect=function(e,t){return void 0===t&&(t={}),n(this,void 0,void 0,(function(){var n,o=this;return r(this,(function(r){switch(r.label){case 0:return n=s(s({},e),{url:T(e.url,t)}),[4,this.websocket.connect(n)];case 1:return r.sent(),this.messageSubscription=this.websocket.onMessage((function(e){o.handleMessage(e)})),[2,{dispose:function(){return o.dispose()}}]}}))}))},e.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},e.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},e.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},e.prototype.reconnect=function(e,t){return void 0===t&&(t=!0),n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,this.sendRequest({reconnect:e},t)]}))}))},e.prototype.updateStream=function(e,t){return void 0===t&&(t=!1),n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,this.sendRequest({updateStream:e},t)]}))}))},e.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},e.prototype.replaceCamera=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateCamera:e},t)},e.prototype.flyTo=function(e,t){return void 0===t&&(t=!0),this.sendRequest({flyTo:e},t)},e.prototype.updateDimensions=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateDimensions:e},t)},e.prototype.hitItems=function(e,t){return void 0===t&&(t=!0),this.sendRequest({hitItems:e},t)},e.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},e.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},e.prototype.syncTime=function(e,t){return void 0===t&&(t=!0),this.sendRequest({syncTime:e},t)},e.prototype.recordPerformance=function(e,t){return void 0===t&&(t=!0),this.sendRequest({recordPerformance:e},t)},e.prototype.loadSceneViewState=function(e,t){return void 0===t&&(t=!0),this.sendRequest({loadSceneViewState:e},t)},e.prototype.replyResult=function(e,t){this.sendResponse(s({requestId:{value:e}},t))},e.prototype.replyError=function(e,t){this.sendResponse({requestId:{value:e},error:t})},e.prototype.handleMessage=function(e){var t=f(e.data);this.log("WS message received",t),null!=(null==t?void 0:t.sentAtTime)&&null!=(null==t?void 0:t.response)&&this.onResponseDispatcher.emit({sentAtTime:t.sentAtTime,response:t.response}),null!=(null==t?void 0:t.sentAtTime)&&null!=(null==t?void 0:t.request)&&this.onRequestDispatcher.emit({sentAtTime:t.sentAtTime,request:t.request})},e.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},e.prototype.log=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];this.loggingEnabled&&console.debug.apply(console,i([e],t))},e.prototype.sendRequest=function(e,t){var n=this,r=m();if(t){var o=u.create(),i=s(s({},e),{requestId:{value:o}});return new Promise((function(t,s){var u=n.onResponse((function(n){var r;if(o===(null===(r=n.response.requestId)||void 0===r?void 0:r.value)){if(null==n.response.error)t(n.response);else{var i=n.response.error,a=i.message,c=i.details;s(new q(o,e,null==a?void 0:a.value,null==c?void 0:c.value))}u.dispose()}}));n.sendMessage({sentAtTime:r,request:i})}))}return this.sendMessage({sentAtTime:r,request:e}),Promise.resolve({})},e.prototype.sendMessage=function(e){this.websocket.send(l(e)),this.log("WS message sent",e)},e.prototype.sendResponse=function(e){var t=m();this.websocket.send(l({sentAtTime:t,response:e}))},e}();function k(e,t){return s(s({sentAtTime:m()},t),{request:s({requestId:null!=e.requestId?{value:e.requestId}:void 0},e.payload)})}var x=Object.freeze({__proto__:null,drawFrame:function(e,t){void 0===e&&(e={});var n={sequenceNumber:1,sceneAttributes:{camera:{position:{x:0,y:0,z:1},lookAt:{x:0,y:0,z:0},up:{x:0,y:1,z:0}}},imageAttributes:{frameDimensions:{width:200,height:150},imageRect:{x:0,y:0,width:200,height:150},scaleFactor:1},frameCorrelationIds:["123"],image:new Uint8Array};return k({requestId:e.requestId,payload:{drawFrame:d.defaults(e.payload,n)}},t)},gracefulReconnect:function(e,t){void 0===e&&(e={});var n={streamId:{hex:u.create()},timeToReconnectDuration:{seconds:1,nanos:0}};return k({requestId:e.requestId,payload:{reconnect:d.defaults(e.payload,n)}},t)}}),D=Object.freeze({__proto__:null,Requests:x}),L=function(){function e(){this.handlers=new Set,this.sentMessages=new Array}return e.prototype.close=function(){},e.prototype.connect=function(e){return Promise.resolve()},e.prototype.onMessage=function(e){var t=this;return this.handlers.add(e),{dispose:function(){return t.handlers.delete(e)}}},e.prototype.send=function(e){this.sentMessages.push(e)},e.prototype.reconnect=function(e){return Promise.resolve()},e.prototype.receiveMessage=function(e){this.handlers.forEach((function(t){return t(new MessageEvent("message",{data:e}))}))},e.prototype.reset=function(){this.sentMessages=[],this.handlers.clear()},e.prototype.hasNextSent=function(){return this.sentMessages.length>0},e.prototype.nextSent=function(e){var t=this.sentMessages.shift();if(null!=t)return null!=e?e(t):t;throw new Error("Sent messages is empty")},e.prototype.skipSent=function(e){if(void 0===e&&(e=1),!(e<=this.sentMessages.length))throw new Error("Cannot skip the next "+e+" messages. Sent message queue only has "+this.sentMessages.length+" messages.");for(var t=0;t<e;t++)this.nextSent();return this},e}();export{D as Fixtures,A as StreamApi,h as WebSocketClientImpl,L as WebSocketClientMock,m as currentDateAsProtoTimestamp,f as decode,l as encode,y as protoToDate,g as toProtoDuration,v as toProtoTimestamp};
import{vertexvis as e,google as t}from"@vertexvis/frame-streaming-protos";import{__awaiter as n,__generator as r,__extends as o,__assign as s,__spreadArray as i}from"tslib";import{UUID as u,EventDispatcher as a,Uri as c,Objects as d}from"@vertexvis/utils";import p from"long";function l(t){return e.protobuf.stream.StreamMessage.encode(t).finish()}function f(t){var n=t instanceof ArrayBuffer?new Uint8Array(t):t;return e.protobuf.stream.StreamMessage.decode(n)}var h=function(){function e(){var e=this;this.listeners={},this.onMessageDispatcher=new a,this.onCloseDispatcher=new a,this.addWebSocketListeners=function(t,n,r,o){var s=function(){return e.onOpen(r)},i=function(){return o()},u=function(t){return e.handleClose(t,n)};return t.addEventListener("message",e.handleMessage),t.addEventListener("open",s),t.addEventListener("error",i),t.addEventListener("close",u),{dispose:function(){t.removeEventListener("message",e.handleMessage),t.removeEventListener("open",s),t.removeEventListener("error",i),t.removeEventListener("close",u)}}},this.handleMessage=function(t){e.onMessageDispatcher.emit(t)},this.handleClose=function(t,n){e.onCloseDispatcher.emit(t),e.removeWebSocketListeners(n)}}return e.prototype.close=function(){null!=this.webSocket&&this.webSocket.close()},e.prototype.connect=function(e){return n(this,void 0,void 0,(function(){var t,n=this;return r(this,(function(r){return t=u.create(),this.webSocket=new WebSocket(e.url,e.protocols),this.webSocket.binaryType="arraybuffer",[2,new Promise((function(e,r){null!=n.webSocket&&(n.listeners[t]=n.addWebSocketListeners(n.webSocket,t,e,r))}))]}))}))},e.prototype.onMessage=function(e){return this.onMessageDispatcher.on(e)},e.prototype.onClose=function(e){return this.onCloseDispatcher.on(e)},e.prototype.send=function(e){null!=this.webSocket&&this.webSocket.send(e)},e.prototype.removeWebSocketListeners=function(e){var t;null===(t=this.listeners[e])||void 0===t||t.dispose()},e.prototype.onOpen=function(e){e()},e}();function v(e){var n=e.getTime();return t.protobuf.Timestamp.create(b(n))}function m(){return v(new Date)}function g(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(2===e.length){var r=e[0],o=e[1],s=o.getTime()-r.getTime();return t.protobuf.Duration.create(b(s))}if(1===e.length){s=e[0];return t.protobuf.Duration.create(b(s))}throw new Error("Expected input to be a number or start and end date.")}function y(e){if(null!=e.seconds&&null!=e.nanos){var t=p.isLong(e.seconds)?e.seconds.toNumber():e.seconds;return new Date(1e3*t+e.nanos/1e6)}}function b(e){return{seconds:Math.floor(e/1e3),nanos:e%1e3*1e6}}var w=function(e){function t(t,n,r,o){var s=e.call(this,null!=r&&r.length>0?"Stream request failed ("+r+")":"Stream request failed")||this;return s.requestId=t,s.requestPayload=n,s.summary=r,s.details=o,s}return o(t,e),t}(Error);function q(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return e.reduce((function(e,n){return s(s({},e),n(t))}),{})}}function S(e,t){return M(e,t,(function(e){return"boolean"==typeof e?e?"on":"off":void 0}))}function E(e,t){return M(e,t,(function(e){return"number"==typeof e?e.toString():void 0}))}function R(e,t){return M(e,t,(function(e){return"string"==typeof e?e:void 0}))}function M(e,t,n){return function(r){var o,s=n(r[t]);return null!=s?((o={})[e]=s,o):{}}}function T(e,t){var n={},r=c.parse(e),o=q(function(e){return A((function(e){return e.EXPERIMENTAL_frameDelivery}),e,q(S("frame-delivery.rate-limit-enabled","rateLimitingEnabled"),E("frame-delivery.packet-loss-threshold","packetLossThreshold"),E("frame-delivery.history-max-size","historyMaxSize"),R("frame-delivery.timeout","timeout"),E("frame-delivery.timeout-ratio-threshold","timeoutRatioThreshold")))}(n.EXPERIMENTAL_frameDelivery),function(e){return A((function(e){return e.EXPERIMENTAL_adaptiveRendering}),e,q(S("adaptive-rendering.enabled","enabled"),R("adaptive-rendering.method","method"),E("adaptive-rendering.jpeg-quality-min","jpegMinQuality"),E("adaptive-rendering.jpeg-quality-max","jpegMaxQuality"),E("adaptive-rendering.image-scale-min","imageMinScale"),E("adaptive-rendering.image-scale-max","imageMaxScale"),E("adaptive-rendering.window-size","windowSize")))}(n.EXPERIMENTAL_adaptiveRendering),function(e){return A((function(e){return e.EXPERIMENTAL_qualityOfService}),e,q(E("qos.history-max-size","historyMaxSize")))}(n.EXPERIMENTAL_qualityOfService))(t);return c.toString(c.addQueryParams(o,r))}function A(e,t,n){return function(r){var o=d.defaults(e(r)||{},t);return n(o)}}var I=function(){function e(e,t){void 0===e&&(e=new h),void 0===t&&(t=!1),this.websocket=e,this.loggingEnabled=t,this.onResponseDispatcher=new a,this.onRequestDispatcher=new a,this.onEventDispatcher=new a}return e.prototype.connect=function(e,t){return void 0===t&&(t={}),n(this,void 0,void 0,(function(){var n,o=this;return r(this,(function(r){switch(r.label){case 0:return n=s(s({},e),{url:T(e.url,t)}),[4,this.websocket.connect(n)];case 1:return r.sent(),this.messageSubscription=this.websocket.onMessage((function(e){o.handleMessage(e)})),[2,{dispose:function(){return o.dispose()}}]}}))}))},e.prototype.dispose=function(){var e;this.websocket.close(),null===(e=this.messageSubscription)||void 0===e||e.dispose()},e.prototype.onRequest=function(e){return this.onRequestDispatcher.on(e)},e.prototype.onEvent=function(e){return this.onEventDispatcher.on(e)},e.prototype.startStream=function(e,t){return void 0===t&&(t=!0),this.sendRequest({startStream:e},t)},e.prototype.reconnect=function(e,t){return void 0===t&&(t=!0),n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,this.sendRequest({reconnect:e},t)]}))}))},e.prototype.updateStream=function(e,t){return void 0===t&&(t=!1),n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,this.sendRequest({updateStream:e},t)]}))}))},e.prototype.beginInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({beginInteraction:{}},e)},e.prototype.replaceCamera=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateCamera:e},t)},e.prototype.flyTo=function(e,t){return void 0===t&&(t=!0),this.sendRequest({flyTo:e},t)},e.prototype.updateDimensions=function(e,t){return void 0===t&&(t=!0),this.sendRequest({updateDimensions:e},t)},e.prototype.hitItems=function(e,t){return void 0===t&&(t=!0),this.sendRequest({hitItems:e},t)},e.prototype.createSceneAlteration=function(e,t){return void 0===t&&(t=!0),this.sendRequest({createSceneAlteration:e},t)},e.prototype.endInteraction=function(e){return void 0===e&&(e=!0),this.sendRequest({endInteraction:{}},e)},e.prototype.syncTime=function(e,t){return void 0===t&&(t=!0),this.sendRequest({syncTime:e},t)},e.prototype.recordPerformance=function(e,t){return void 0===t&&(t=!0),this.sendRequest({recordPerformance:e},t)},e.prototype.loadSceneViewState=function(e,t){return void 0===t&&(t=!0),this.sendRequest({loadSceneViewState:e},t)},e.prototype.replyResult=function(e,t){this.sendResponse(s({requestId:{value:e}},t))},e.prototype.replyError=function(e,t){this.sendResponse({requestId:{value:e},error:t})},e.prototype.handleMessage=function(e){var t=f(e.data);this.log("WS message received",t),null!=(null==t?void 0:t.sentAtTime)&&(null!=t.response&&this.onResponseDispatcher.emit({sentAtTime:t.sentAtTime,response:t.response}),null!=t.request&&this.onRequestDispatcher.emit({sentAtTime:t.sentAtTime,request:t.request}),null!=t.event&&this.onEventDispatcher.emit({sentAtTime:t.sentAtTime,event:t.event}))},e.prototype.onResponse=function(e){return this.onResponseDispatcher.on(e)},e.prototype.log=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];this.loggingEnabled&&console.debug.apply(console,i([e],t))},e.prototype.sendRequest=function(e,t){var n=this,r=m();if(t){var o=u.create(),i=s(s({},e),{requestId:{value:o}});return new Promise((function(t,s){var u=n.onResponse((function(n){var r;if(o===(null===(r=n.response.requestId)||void 0===r?void 0:r.value)){if(null==n.response.error)t(n.response);else{var i=n.response.error,a=i.message,c=i.details;s(new w(o,e,null==a?void 0:a.value,null==c?void 0:c.value))}u.dispose()}}));n.sendMessage({sentAtTime:r,request:i})}))}return this.sendMessage({sentAtTime:r,request:e}),Promise.resolve({})},e.prototype.sendMessage=function(e){this.websocket.send(l(e)),this.log("WS message sent",e)},e.prototype.sendResponse=function(e){var t=m();this.websocket.send(l({sentAtTime:t,response:e}))},e}();function D(e,t){return s(s({sentAtTime:m()},t),{request:s({requestId:null!=e.requestId?{value:e.requestId}:void 0},e.payload)})}var k=Object.freeze({__proto__:null,drawFrame:function(e,t){void 0===e&&(e={});var n={sequenceNumber:1,sceneAttributes:{camera:{position:{x:0,y:0,z:1},lookAt:{x:0,y:0,z:0},up:{x:0,y:1,z:0}}},imageAttributes:{frameDimensions:{width:200,height:150},imageRect:{x:0,y:0,width:200,height:150},scaleFactor:1},frameCorrelationIds:["123"],image:new Uint8Array};return D({requestId:e.requestId,payload:{drawFrame:d.defaults(e.payload,n)}},t)},gracefulReconnect:function(e,t){void 0===e&&(e={});var n={streamId:{hex:u.create()},timeToReconnectDuration:{seconds:1,nanos:0}};return D({requestId:e.requestId,payload:{reconnect:d.defaults(e.payload,n)}},t)}});var x=Object.freeze({__proto__:null,animationCompleted:function(e){var t,n;return t={animationCompleted:s({},{animationId:{hex:e}})},s({sentAtTime:m(),event:s({},t)},n)}}),L=Object.freeze({__proto__:null,Requests:k,Events:x}),_=function(){function e(){this.handlers=new Set,this.sentMessages=new Array}return e.prototype.close=function(){},e.prototype.connect=function(e){return Promise.resolve()},e.prototype.onMessage=function(e){var t=this;return this.handlers.add(e),{dispose:function(){return t.handlers.delete(e)}}},e.prototype.send=function(e){this.sentMessages.push(e)},e.prototype.reconnect=function(e){return Promise.resolve()},e.prototype.receiveMessage=function(e){this.handlers.forEach((function(t){return t(new MessageEvent("message",{data:e}))}))},e.prototype.reset=function(){this.sentMessages=[],this.handlers.clear()},e.prototype.hasNextSent=function(){return this.sentMessages.length>0},e.prototype.nextSent=function(e){var t=this.sentMessages.shift();if(null!=t)return null!=e?e(t):t;throw new Error("Sent messages is empty")},e.prototype.skipSent=function(e){if(void 0===e&&(e=1),!(e<=this.sentMessages.length))throw new Error("Cannot skip the next "+e+" messages. Sent message queue only has "+this.sentMessages.length+" messages.");for(var t=0;t<e;t++)this.nextSent();return this},e}();export{L as Fixtures,I as StreamApi,h as WebSocketClientImpl,_ as WebSocketClientMock,m as currentDateAsProtoTimestamp,f as decode,l as encode,y as protoToDate,g as toProtoDuration,v as toProtoTimestamp};
//# sourceMappingURL=bundle.esm.min.js.map
import { WebSocketClient } from './webSocketClient';
import { ConnectionDescriptor } from './connection';
import { HitItemsPayload, ReconnectPayload, ReplaceCameraPayload, StartStreamPayload, ResponseResult, ResponseError, RequestMessage, ResponseMessage, SyncTimePayload, RecordPerformancePayload, UpdateDimensionsPayload, UpdateStreamPayload, LoadSceneViewStatePayload } from './types';
import { HitItemsPayload, ReconnectPayload, ReplaceCameraPayload, StartStreamPayload, ResponseResult, ResponseError, RequestMessage, ResponseMessage, SyncTimePayload, RecordPerformancePayload, UpdateDimensionsPayload, UpdateStreamPayload, LoadSceneViewStatePayload, EventMessage } from './types';
import { vertexvis } from '@vertexvis/frame-streaming-protos';

@@ -9,2 +9,3 @@ import { Disposable } from '@vertexvis/utils';

export declare type ResponseMessageHandler = (msg: ResponseMessage) => void;
export declare type EventMessageHandler = (msg: EventMessage) => void;
/**

@@ -18,2 +19,3 @@ * The API client to interact with Vertex's streaming API.

private onRequestDispatcher;
private onEventDispatcher;
private messageSubscription?;

@@ -43,2 +45,9 @@ constructor(websocket?: WebSocketClient, loggingEnabled?: boolean);

/**
* Adds a callback that is invoked when the client receives an event from the
* server. Returns a `Disposable` that can be used to remove the listener.
*
* @param handler - A handler function.
*/
onEvent(handler: EventMessageHandler): Disposable;
/**
* Sends a request to initiate a streaming session.

@@ -45,0 +54,0 @@ *

import * as Requests from './requests';
export { Requests };
import * as Events from './events';
export { Requests, Events };

@@ -5,2 +5,3 @@ import { DeepRequired, RequiredAndNonNullable } from '@vertexvis/utils';

export declare type ResponseMessage = RequiredAndNonNullable<Pick<vertexvis.protobuf.stream.IStreamMessage, 'response' | 'sentAtTime'>>;
export declare type EventMessage = RequiredAndNonNullable<Pick<vertexvis.protobuf.stream.IStreamMessage, 'event' | 'sentAtTime'>>;
export declare type StreamAttributes = vertexvis.protobuf.stream.IStreamAttributes;

@@ -35,1 +36,3 @@ export declare type StartStreamPayload = DeepRequired<vertexvis.protobuf.stream.IStartStreamPayload, [

export declare type ResponseError = vertexvis.protobuf.stream.IError;
export declare type AnimationCompletedEvent = DeepRequired<Pick<vertexvis.protobuf.stream.IAnimationCompletedEvent, 'animationId'>, [
]>;
{
"name": "@vertexvis/stream-api",
"version": "0.9.24-canary.1",
"version": "0.9.24-canary.2",
"description": "A websocket client for interacting with Vertex's stream API.",

@@ -39,3 +39,3 @@ "license": "MIT",

"@vertexvis/frame-streaming-protos": "^0.4.1",
"@vertexvis/utils": "^0.9.24-canary.1"
"@vertexvis/utils": "^0.9.24-canary.2"
},

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

"@vertexvis/jest-config-vertexvis": "^0.5.0",
"@vertexwebsdk/build": "^0.9.24-canary.1",
"@vertexwebsdk/build": "^0.9.24-canary.2",
"eslint": "^7.20.0",

@@ -59,3 +59,3 @@ "jest": "^26.6.3",

},
"gitHead": "b66ee70240522dccc53c45c71c740727a97dbb8e"
"gitHead": "221553826149cba4398e9a03b6256309e5fd6546"
}

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