Skip to content

Commit

Permalink
Release 1.2.0 (#10)
Browse files Browse the repository at this point in the history
* Reconnect improvements (#5)

* fix: Remove outfile from test command

* fix: Add missing paths to .npmignore

* fix: Replace dynamic `convertToInworldPacket` to static method

* feat: Allow users to save session and scene in externally provided storage

* feat: Use one getter/setter to save session

* fix: Remove not actual examples README (docs should be used instead)

* feat: Improve test coverage

* feat: Allow to serialize/deserialize session

* feat: Mark some methods as depricated

* fix: Allow to return any for GetterSetter

* feat: Add additional eslint rules

* Add phoneme and silence event support (#9)

* feat: Add phonemes support

* feat: Add silence event support

* chore: Release 1.2.0
  • Loading branch information
tshashkova authored Apr 20, 2023
1 parent f3c399b commit 3427cb4
Show file tree
Hide file tree
Showing 27 changed files with 760 additions and 473 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,29 @@
"simple-import-sort"
],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-console": ["error", { "allow": ["warn", "error"] }],
"no-throw-literal": "off"
},
"overrides": [
{
"files": [
"examples/**/*.ts",
"examples/**/*.tsx"
],
"rules": {
"no-console": "off"
}
}
],
"ignorePatterns": ["proto", "build"]
}
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.github
.husky
coverage
examples
__tests__
Expand All @@ -6,7 +8,7 @@ __tests__
*/**/.eslintcache
.eslintrc.json
.prettierrc.json
jest.config.js
jest.config.json
/tsconfig.json
/tsconfig.paths.json
build/jest-result.json
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2022-04-20 v1.2.0

* Add phonemes event support
* Add silence event support
* Improve manual reconnect latency

## 2022-04-06 v1.1.8

* Remove deprecated emotions attributes: joy, fear, trust and surprise
Expand Down
13 changes: 10 additions & 3 deletions __tests__/clients/inworld.client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { InworldClient } from '../../src/clients/inworld.client';
import { GetterSetter } from '../../src/common/interfaces';
import { Session } from '../../src/entities/session.entity';
import { TokenClientGrpcService } from '../../src/services/gprc/token_client_grpc.service';
import {
capabilitiesProps,
KEY,
SCENE,
SECRET,
session,
sessionProto,
sessionToken,
user,
} from '../helpers';

Expand All @@ -16,6 +18,10 @@ describe('should finish with success', () => {
const onMessage = jest.fn();
const onDisconnect = jest.fn();
const generateSessionTokenFn = jest.fn();
const sessionGetterSetter = {
get: jest.fn(),
set: jest.fn(),
} as GetterSetter<Session>;

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -28,7 +34,8 @@ describe('should finish with success', () => {
.setOnDisconnect(onDisconnect)
.setOnMessage(onMessage)
.setOnError(onError)
.setGenerateSessionToken(generateSessionTokenFn);
.setGenerateSessionToken(generateSessionTokenFn)
.setOnSession(sessionGetterSetter);
});

test('should generate session token', async () => {
Expand All @@ -39,7 +46,7 @@ describe('should finish with success', () => {
const result = await client.generateSessionToken();

expect(generateSessionToken).toHaveBeenCalledTimes(1);
expect(result).toEqual(session);
expect(result).toEqual(sessionToken);
});

test('should build', async () => {
Expand Down
19 changes: 19 additions & 0 deletions __tests__/entities/character.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ test('should get character fields', () => {
};
const character = new Character({ id, assets, resourceName, displayName });

expect(character.id).toEqual(id);
expect(character.resourceName).toEqual(resourceName);
expect(character.displayName).toEqual(displayName);
expect(character.assets).toEqual(assets);
});

test('should get character fields in the deprecated way', () => {
const id = v4();
const resourceName = v4();
const displayName = v4();
const assets: Assets = {
avatarImg: v4(),
avatarImgOriginal: v4(),
rpmModelUri: v4(),
rpmImageUriPortrait: v4(),
rpmImageUriPosture: v4(),
};
const character = new Character({ id, assets, resourceName, displayName });

expect(character.getId()).toEqual(id);
expect(character.getResourceName()).toEqual(resourceName);
expect(character.getDisplayName()).toEqual(displayName);
Expand Down
14 changes: 14 additions & 0 deletions __tests__/entities/inworld_packet.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ test('should get emotion packet fields', () => {
expect(packet.packetId).toEqual(packetId);
});

test('should get silence packet fields', () => {
const packet = new InworldPacket({
packetId,
routing,
date,
type: InworldPacketType.SILENCE,
});

expect(packet.isSilence()).toEqual(true);
expect(packet.routing).toEqual(routing);
expect(packet.date).toEqual(date);
expect(packet.packetId).toEqual(packetId);
});

describe('control', () => {
test('should get interaction end packet fields', () => {
const packet = new InworldPacket({
Expand Down
50 changes: 50 additions & 0 deletions __tests__/entities/scene.entity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { v4 } from 'uuid';

import { LoadSceneResponse } from '../../proto/world-engine_pb';
import { Character } from '../../src/entities/character.entity';
import { Scene } from '../../src/entities/scene.entity';
import { createAgent, createCharacter } from '../helpers';

let key: string;
let characters: Array<Character> = [];
let scene: Scene;
let json: string;

beforeEach(() => {
jest.clearAllMocks();

key = v4();
characters = [createCharacter(), createCharacter()];
scene = new Scene({
characters,
key,
});
json = JSON.stringify(scene);
});

test('should return scene fields', () => {
expect(scene.characters).toEqual(characters);
expect(scene.key).toEqual(key);
});

test('should serialize', () => {
expect(Scene.serialize(scene)).toEqual(json);
});

test('should deserialize', () => {
const result = Scene.deserialize(json);

expect(result.key).toEqual(scene.key);
expect(result.characters).toEqual(scene.characters);
});

test('should convert proto to scene', () => {
const agents = [createAgent(), createAgent(false)];
const proto = new LoadSceneResponse().setAgentsList(agents).setKey(key);
const scene = Scene.fromProto(proto);

expect(scene.key).toEqual(key);
expect(scene.characters[0].id).toEqual(agents[0].getAgentId());
expect(scene.characters[1].id).toEqual(agents[1].getAgentId());
expect(scene.characters[1].assets.avatarImg).toEqual(undefined);
});
38 changes: 38 additions & 0 deletions __tests__/entities/session.entity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { v4 } from 'uuid';

import { Scene } from '../../src/entities/scene.entity';
import { Session } from '../../src/entities/session.entity';
import { createCharacter, sessionToken } from '../helpers';

let scene: Scene = {
key: v4(),
characters: [createCharacter(), createCharacter()],
};
let session: Session;
let json: string;

beforeEach(() => {
jest.clearAllMocks();

session = new Session({
scene,
sessionToken,
});
json = JSON.stringify(session);
});

test('should return session fields', () => {
expect(session.scene).toEqual(scene);
expect(session.sessionToken).toEqual(sessionToken);
});

test('should serialize', () => {
expect(Session.serialize(session)).toEqual(json);
});

test('should deserialize', () => {
const result = Session.deserialize(json);

expect(result.scene).toEqual(session.scene);
expect(result.sessionToken).toEqual(session.sessionToken);
});
78 changes: 78 additions & 0 deletions __tests__/entities/session_token.entity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { SessionAccessToken } from '@proto/ai/inworld/studio/v1alpha/tokens_pb';
import { v4 } from 'uuid';

import { protoTimestamp } from '../../src/common/helpers';
import { SessionToken } from '../../src/entities/session_token.entity';
import { sessionToken } from '../helpers';

const json = JSON.stringify(sessionToken);

test('should get session fields', () => {
const token = v4();
Expand All @@ -15,8 +20,81 @@ test('should get session fields', () => {
expirationTime,
});

expect(session.token).toEqual(token);
expect(session.type).toEqual(type);
expect(session.sessionId).toEqual(sessionId);
expect(session.expirationTime).toEqual(expirationTime);
});

test('should get session fields in the deprecated way', () => {
const token = v4();
const type = v4();
const sessionId = v4();
const expirationTime = new Date();

const session = new SessionToken({
token,
type,
sessionId,
expirationTime,
});

expect(session.getToken()).toEqual(token);
expect(session.getType()).toEqual(type);
expect(session.getSessionId()).toEqual(sessionId);
expect(session.getExpirationTime()).toEqual(expirationTime);
});

test('should serialize', () => {
expect(SessionToken.serialize(sessionToken)).toEqual(json);
});

test('should deserialize', () => {
const result = SessionToken.deserialize(json);

expect(result.token).toEqual(sessionToken.token);
expect(result.type).toEqual(sessionToken.type);
expect(result.sessionId).toEqual(sessionToken.sessionId);
expect(result.expirationTime).toEqual(sessionToken.expirationTime);
});

test('should convert proto to token', () => {
const token = v4();
const type = v4();
const sessionId = v4();
const expirationTime = new Date();

const proto = new SessionAccessToken()
.setToken(token)
.setType(type)
.setSessionId(sessionId)
.setExpirationTime(protoTimestamp(expirationTime));
const scene = SessionToken.fromProto(proto);

expect(scene.token).toEqual(proto.getToken());
expect(scene.type).toEqual(proto.getType());
expect(scene.sessionId).toEqual(proto.getSessionId());
expect(scene.expirationTime).toEqual(proto.getExpirationTime().toDate());
});

describe('isExpired', () => {
test('should detect expired session', () => {
const token = v4();
const type = v4();
const sessionId = v4();
const expirationTime = new Date();

const session = new SessionToken({
token,
type,
sessionId,
expirationTime,
});

expect(SessionToken.isExpired(session)).toEqual(true);
});

test('should not detect expired session', () => {
expect(SessionToken.isExpired(sessionToken)).toEqual(false);
});
});
Loading

0 comments on commit 3427cb4

Please sign in to comment.