connecting ring module

This commit is contained in:
balzack 2024-07-07 13:26:14 -07:00
parent a22e412214
commit af3d341d76
5 changed files with 21 additions and 17 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -26,6 +26,9 @@ export class RingModule implements Ring {
this.emitter.off('call', ev);
}
public ring(call: Call): void {
}
public accept(callId: string): void {
}

View File

@ -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);

View File

@ -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 = {