From e04a085fc403275c60e917cae9f8a0fb61c57287 Mon Sep 17 00:00:00 2001 From: balzack Date: Sat, 6 Jul 2024 00:32:03 -0700 Subject: [PATCH] adding websocket class --- app/sdk/__tests__/session.tests.ts | 6 +++++- app/sdk/src/entities.ts | 16 ++++++++++++++++ app/sdk/src/index.ts | 4 ++-- app/sdk/src/session.ts | 22 +++++++++++++--------- app/sdk/src/types.ts | 16 +++++++++++++++- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/app/sdk/__tests__/session.tests.ts b/app/sdk/__tests__/session.tests.ts index fb99c4f3..4522f4d2 100644 --- a/app/sdk/__tests__/session.tests.ts +++ b/app/sdk/__tests__/session.tests.ts @@ -1,10 +1,14 @@ import { DatabagSDK } from '../src/index'; import { type SessionParams } from '../src/types'; +import { Connection } from '../src/connection'; + +jest.mock('../src/connection'); + test('allocates session correctly', async () => { const sdk = new DatabagSDK(null); const params: SessionParams = { topicBatch: 0, tagBatch: 0, channelTypes: [], pushType: '', deviceToken: '', notifications: [], deviceId: '', version: '', appName: '' }; - const session = await sdk.login('handle', 'password', 'url', params); + const session = await sdk.login('handle', 'password', 'url', null, params); const account = session.getAccount(); account.enableNotifications(); //expect(r).toBe(5); diff --git a/app/sdk/src/entities.ts b/app/sdk/src/entities.ts index 21cf4355..81dec7d3 100644 --- a/app/sdk/src/entities.ts +++ b/app/sdk/src/entities.ts @@ -170,3 +170,19 @@ export type ProfileEntity = { node: string, } +export type Ringing = { + cardId: string, + callId: string, + calleeToken: string, + ice: { urls: string, username: string, credential: string }[], +} + +export type Revision = { + account: number, + profile: number, + article: number, + group: number, + channel: number, + card: number +} + diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index df9e383b..3da02142 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -34,11 +34,11 @@ export class DatabagSDK { return new SessionModule(this.store, this.crypto, '', ''); } - public async access(token: string, url: string, params: SessionParams): Promise { + public async access(url: string, token: string, params: SessionParams): Promise { return new SessionModule(this.store, this.crypto, '', ''); } - public async create(handle: string, password: string, url: string, token: string, params: SessionParams): Promise { + public async create(handle: string, password: string, url: string, token: string | null, params: SessionParams): Promise { return new SessionModule(this.store, this.crypto, '', ''); } diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index b7eb996d..f9743247 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -10,6 +10,8 @@ import { StreamModule } from './stream'; import { FocusModule } from './focus'; import { RingModule } from './ring'; +import { Connection } from './connection'; + import type { Session, SqlStore, WebStore, Crypto, Account, Identity, Contact, Ring, Alias, Attribute, Content, Stream, Focus } from './api'; export class SessionModule implements Session { @@ -20,15 +22,15 @@ export class SessionModule implements Session { private token: string; private url: string; private sync: boolean; - - public account: AccountModule; - public identity: IdentityModule; - public contact: ContactModule; - public alias: AliasModule; - public attribute: AttributeModule; - public content: ContentModule; - public stream: StreamModule; - public ring: RingModule; + private account: AccountModule; + private identity: IdentityModule; + private contact: ContactModule; + private alias: AliasModule; + private attribute: AttributeModule; + private content: ContentModule; + private stream: StreamModule; + private ring: RingModule; + private connection: Connection; constructor(store: SqlStore | WebStore | null, crypto: Crypto | null, token: string, url: string) { this.store = store; @@ -45,6 +47,7 @@ export class SessionModule implements Session { this.content = new ContentModule(token, url, this.setSync, this.account); this.stream = new StreamModule(this.contact, this.content); this.ring = new RingModule(); + this.connection = new Connection(token, url); } public addStatusListener(ev: (status: string) => void): void { @@ -64,6 +67,7 @@ export class SessionModule implements Session { } public close() { + this.connection.close(); this.stream.close(); this.content.close(); this.attribute.close(); diff --git a/app/sdk/src/types.ts b/app/sdk/src/types.ts index 3b72d485..19524b3b 100644 --- a/app/sdk/src/types.ts +++ b/app/sdk/src/types.ts @@ -19,12 +19,26 @@ export type Call = { cardId: string, callId: string, calleeToken: string, - ice: { urls: string, username: string, credential: string}[], + ice?: { urls: string, username: string, credential: string}[], iceUrl: string, // deprecated iceUsername: string, // deprecated icePassword: string, // deprecated } +export type Revision = { + account: number, + profile: number, + article: number, + group: number, + channel: number, + card: number +} + +export type Activity = { + revision?: Revision, + phone?: Call, +} + export type Channel = { id: string, cardId: string | null,