From af3d341d76c5683ed5b06408aeda46a7575dae4e Mon Sep 17 00:00:00 2001 From: balzack Date: Sun, 7 Jul 2024 13:26:14 -0700 Subject: [PATCH] connecting ring module --- app/sdk/__mocks__/connection.ts | 9 +++++---- app/sdk/src/connection.ts | 15 ++++++++------- app/sdk/src/ring.ts | 3 +++ app/sdk/src/session.ts | 8 +++++--- app/sdk/src/types.ts | 3 --- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/sdk/__mocks__/connection.ts b/app/sdk/__mocks__/connection.ts index 594849b6..e4fadae9 100644 --- a/app/sdk/__mocks__/connection.ts +++ b/app/sdk/__mocks__/connection.ts @@ -1,5 +1,6 @@ import { EventEmitter } from 'eventemitter3'; -import { Revision, Ringing } from '../src/entities'; +import { Revision } from '../src/entities'; +import { Call } from '../src/types'; export class MockConnection { private emitter: EventEmitter; @@ -19,11 +20,11 @@ export class MockConnection { this.emitter.off('revision', ev); } - public addRingListener(ev: (ringing: Ringing) => void): void { + public addRingListener(ev: (ringing: Call) => void): void { this.emitter.on('ringing', ev); } - public removeRingListener(ev: (ringing: Ringing) => void): void { + public removeRingListener(ev: (ringing: Call) => void): void { this.emitter.off('ringing', ev); } @@ -39,7 +40,7 @@ export class MockConnection { this.emitter.emit('revision', revision); } - public emitRing(ring: Ringing): void { + public emitRing(ring: Call): void { this.emitter.emit('ringing', ring); } diff --git a/app/sdk/src/connection.ts b/app/sdk/src/connection.ts index bbbfade4..5802a280 100644 --- a/app/sdk/src/connection.ts +++ b/app/sdk/src/connection.ts @@ -1,5 +1,6 @@ import { EventEmitter } from 'eventemitter3'; -import { Revision, Ringing } from './entities'; +import { Revision } from './entities'; +import { Call } from './types'; export class Connection { @@ -28,12 +29,12 @@ export class Connection { this.emitter.off('revision', ev); } - public addRingListener(ev: (ringing: Ringing) => void): void { - this.emitter.on('ringing', ev); + public addRingListener(ev: (call: Call) => void): void { + this.emitter.on('call', ev); } - public removeRingListener(ev: (ringing: Ringing) => void): void { - this.emitter.off('ringing', ev); + public removeRingListener(ev: (call: Call) => void): void { + this.emitter.off('call', ev); } public addStatusListener(ev: (status: string) => void): void { @@ -65,8 +66,8 @@ export class Connection { } else if (activity.ring) { const { cardId, callId, calleeToken, ice, iceUrl, iceUsername, icePassword } = activity.ring; - const ringing: Ringing = { cardId, callId, calleeToken, ice: ice ? ice : [{ urls: iceUrl, username: iceUsername, credential: icePassword }] }; - this.emitter.emit('ring', ringing); + const call: Call = { cardId, callId, calleeToken, ice: ice ? ice : [{ urls: iceUrl, username: iceUsername, credential: icePassword }] }; + this.emitter.emit('call', call); } else { this.emitter.emit('revision', activity as Revision); diff --git a/app/sdk/src/ring.ts b/app/sdk/src/ring.ts index 596cf5b9..11054c7e 100644 --- a/app/sdk/src/ring.ts +++ b/app/sdk/src/ring.ts @@ -26,6 +26,9 @@ export class RingModule implements Ring { this.emitter.off('call', ev); } + public ring(call: Call): void { + } + public accept(callId: string): void { } diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index 6859cf85..1e1f816e 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -13,7 +13,8 @@ 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'; -import { Revision, Ringing } from './entities'; +import { Revision } from './entities'; +import { Call } from './types'; export class SessionModule implements Session { @@ -52,6 +53,7 @@ export class SessionModule implements Session { this.content = new ContentModule(token, url, this.account); this.stream = new StreamModule(this.contact, this.content); this.ring = new RingModule(); + this.connection = new Connection(token, url); const onStatus = (ev: string) => { this.status = ev; @@ -77,10 +79,10 @@ export class SessionModule implements Session { } } - const onRing = (ev: Ringing) => { + const onRing = (ev: Call) => { + this.ring.ring(ev); } - this.connection = new Connection(token, url); this.connection.addStatusListener(onStatus); this.connection.addRevisionListener(onRevision); this.connection.addRingListener(onRing); diff --git a/app/sdk/src/types.ts b/app/sdk/src/types.ts index 19524b3b..db49dc5b 100644 --- a/app/sdk/src/types.ts +++ b/app/sdk/src/types.ts @@ -20,9 +20,6 @@ export type Call = { callId: string, calleeToken: string, ice?: { urls: string, username: string, credential: string}[], - iceUrl: string, // deprecated - iceUsername: string, // deprecated - icePassword: string, // deprecated } export type Revision = {