@oriient/session-emulator
v2.4.0
Published
Enables real time session emulation against real time server
Downloads
42,101
Readme
@oriient/session-emulator
Package for emulating sessions against our Backend, either with remote engine or OnDevice engine
Basic usage
Can be used for monitoring or stress testing, or performing sessions from a developer machine. There are three modes that the emulator can be used: ###1. OnDevice simulation In this mode, the emulation will behave as OnDevice SDK. It will call all the REST API calls and will upload sensors / positions / events / validation chunks. It also has the ability to perform dummy "EventTags" (see options below). ####1.1 with pre-saved session data (default) In this mode, the session data is pre-saved. No need in MongoDB communication or GCP bucket access. You must supply the "oriientEnv" parameter. ######Usage example
const { sessionEmulator: getEmulator, Envs } = require('@oriient/session-emulator');
const emulator = getEmulator({
username: 'session-emulator-ondevice',
oriientEnv: Envs[envName],
});
emulator.runFullSession(); // will run a full session flow####1.2 with DB session data In this mode, the session data will be pulled from the MongoDB and GCP buckets. You must have MongoDB communication (don't forget VPN) and GCP bucket access. The env that the session will be performed against will be decided by the sessionId details. Make sure the originalSessionId you provide indeed exist in the MongoDB URI you are providing. ######Usage example
const { sessionEmulator: getEmulator, Envs } = require('@oriient/session-emulator');
const emulator = getEmulator({
username: 'session-emulator-ondevice',
originalSessionId: '862984f6-a6e1-4fa3-9262-b3bf37dd2663',
});
emulator.runFullSession(); // will run a full session flow###2. Remote Engine simulation In this mode, the emulation will be performed against the RTS, like an old SDK. In this mode, pre-saved data is not supported, only supplying originalSessionId. You can perform either positioning or calibration. You must have MongoDB communication (don't forget VPN) and GCP bucket access. It does NOT have the ability to perform dummy "EventTags". You must supply ipsAddress in order to perform the session against it. ######Usage example
const { sessionEmulator: getEmulator, Envs } = require('@oriient/session-emulator');
const emulator = getEmulator({
username: 'emulatorPackageTest',
originalSessionId: '789d95fa-5d62-4db7-9f11-bbcd7d284223',
ipsAddress: 'wss://ips.oriient.me',
simulateOnDevice: false,
});
emulator.runFullSession(); // will run a full session flowAPI reference
In general, you can call functions to perform actions against the server and listen to events (the emulator is EventEmmiter) in order to gain more control over the emulation. There is also the convince method of runFullSession to run the whole session without intervention.
getEmulator(options: Object)
The options objects can contain the following properties:
| Param | Description | |-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------| | simulateOnDevice | Whether to simulate OnDevice session. Default true. If false / not supplied will simulate Remote Engine session. | | oriientEnv | Which env to work against. Taken from Envs enum. OnDevice with pre-saved data only | | simulateEventTags | Whether to simulate event tags during the session. Only in OnDevice mode. Default false. | | eventTagsSimulationInterval | The interval to send event tags. Only in OnDevice mode and if simulateEventTags is true. Default 1000 ms. | | useJwtAuth | Whether to use JWT authentication to communicate with the services. Default is false and it will use api key authentication. | | ipsAddress | Address of real time server to emulate against. Needed only if simulateOnDevice is false. Env var: IPS_ADDRESS. Default: ws://ipspp.oriient.me | | mongoUri | URI for the mongodb access. Needed only if originalSessionId is supplied. Otherwise will work with sample session. Env var: MONGO_URI. No Default. | | username | Username to send to the server. Default: RealTimeSessionEmulator | | newSessionId | If you want to control the uuid the session will get, you can pass it here. | | recordsBucket | The bucket name where the session records exist. Env var: RECORDS_BUCKET. No default. Needed only in Remote Engine emulation | | originalSessionId | The sessionId to emulate against the server. Needed only in OnDevice without pre-saved data. In Remote Engine it is a must | | msgTimeout | The timeout for a message to get response from the RTS. Only for Remote Engine emulation. Env var: MSG_TIMEOUT. Default: 30000 ms |
async runFullSession()
Convenient function to run a full session.
async prepareSessionData()
Prepare the session data. If not using sample data, downloads the relevant data.
Emit event: 'session-data-ready'
async login()
Perform login operations. In Remote Engine does nothing.
Emit event: 'LOGIN_SUCCESS'
async startPositioning()
Performs positioning operations
Emit event: 'START_POSITIONING_SUCCESS'
async startStreamingSessionData()
Start sending data to the server (either uploads chunks / streaming sensor data)
In all modes emit events:
- 'SESSION_DATA_STREAM_END' when streaming of the data is over
In OnDevice mode emit events:
- 'CHUNKS_UPLOAD' with data that included an object: { type, data, timeMs }. Type can be 'START_CHUNK' / 'CHUNK_UPLOADED' / 'END_CHUNK'. data will include the data returned from the operation and timeMs will include the time it took to upload.
In Remote Engine mode emit events:
- 'position-update' for each position update
- 'frame-sent' for each frame being sent
async stopPositioning()
Stops the positioning. In OnDevice does nothing.
Emit event: 'STOP_POSITIONING_SUCCESS'
stopStreamingSessionData()
Stops the streaming of the session data. Does not stop the session. Not relevant in OnDevice.
Emit event: 'session-data-stream-stopped'
