Skip to content

Commit

Permalink
1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
billylindeman committed May 12, 2021
1 parent 2cd134d commit a7d06d2
Show file tree
Hide file tree
Showing 13 changed files with 430 additions and 431 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ion-sdk-js",
"version": "1.7.0",
"version": "1.7.1",
"description": "A js sdk for ion sfu",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
14 changes: 7 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export interface Trickle {
}

export interface ActiveLayer {
streamId: string,
activeLayer: string,
availableLayers: string[]
streamId: string;
activeLayer: string;
availableLayers: string[];
}

enum Role {
Expand Down Expand Up @@ -244,23 +244,23 @@ export default class Client {
private processChannelMessage(msg: any) {
if (msg.method !== undefined && msg.params !== undefined) {
switch (msg.method) {
case "audioLevels":
case 'audioLevels':
if (this.onspeaker) {
this.onspeaker(msg.params);
}
break;
case "activeLayer":
case 'activeLayer':
if (this.onactivelayer) {
this.onactivelayer(msg.params);
}
break;
default:
// do nothing
// do nothing
}
} else {
// legacy channel message - payload contains audio levels
if (this.onspeaker) {
this.onspeaker(msg)
this.onspeaker(msg);
}
}
}
Expand Down
244 changes: 122 additions & 122 deletions src/ion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,151 +6,151 @@ import { Signal, Trickle } from './signal';
export { Client, LocalStream, RemoteStream, Constraints, Signal, Trickle };

export interface JoinResult {
success: boolean;
reason: string;
}
success: boolean;
reason: string;
}

export enum PeerState {
NONE,
JOIN,
UPDATE,
LEAVE,
NONE,
JOIN,
UPDATE,
LEAVE,
}

export interface Peer {
uid: string;
sid: string;
info: Map<string, any>;
uid: string;
sid: string;
info: Map<string, any>;
}

export interface PeerEvent {
state: PeerState;
peer: Peer;
state: PeerState;
peer: Peer;
}

export enum StreamState {
NONE,
ADD,
REMOVE,
NONE,
ADD,
REMOVE,
}

export interface StreamEvent {
uid: string;
state: StreamState;
streams: Stream[];
uid: string;
state: StreamState;
streams: Stream[];
}

export interface Track {
id: string;
label: string;
kind: string;
simulcast: Map<string,string>;
id: string;
label: string;
kind: string;
simulcast: Map<string, string>;
}

export interface Stream {
id: string;
tracks: Track[];
id: string;
tracks: Track[];
}

export interface Message {
from: string ;
to: string;
data: Map<string, any>;
from: string;
to: string;
data: Map<string, any>;
}

export class IonConnector {
private _biz: BizClient;
private _sfu: Client | undefined;
private _sid: string;
private _uid: string;

onerror?:(err: Error) => void;

onjoin?:(success: boolean, reason: string) => void;

onleave?:(reason: string) => void;

onpeerevent?: (ev: PeerEvent) => void;

onstreamevent?: (ev: StreamEvent) => void;

onmessage?:(msg: Message) => void;

ontrack?: (track: MediaStreamTrack, stream: RemoteStream) => void;

ondatachannel?: (ev: RTCDataChannelEvent) => void;

onspeaker?: (ev: string[]) => void;

constructor(url: string, config?: Configuration) {
this._sid = "";
this._uid = "";
this._sfu = undefined;
this._biz = new BizClient(url);
this._biz.on("join-reply", async (success: boolean, reason: string) => {
if (this.onjoin) {
this.onjoin(success, reason);
}
if (success && !this._sfu) {
const signal = new IonSFUGRPCWebSignal(url);
const sfu = new Client(signal, config);

sfu.ontrack = (track: MediaStreamTrack, stream: RemoteStream) =>
this.ontrack?.call(this, track, stream);
sfu.ondatachannel = (ev: RTCDataChannelEvent) =>
this.ondatachannel?.call(this, ev);
sfu.onspeaker = (ev: string[]) => this.onspeaker?.call(this, ev);

this._sfu = sfu;

await sfu.join(this._sid, this._uid);
}
});

this._biz.on("leave-reply", (reason: string) => {
if (this.onleave) {
this.onleave(reason);
}
});

this._biz.on("peer-event", (ev: PeerEvent) => {
if(this.onpeerevent) {
this.onpeerevent(ev);
}
})

this._biz.on("stream-event", (ev: StreamEvent) => {
if(this.onstreamevent) {
this.onstreamevent(ev);
}
})

this._biz.on("message", (msg: Message) => {
if(this.onmessage) {
this.onmessage(msg);
}
})
}

get sfu() { return this._sfu; }

async join(sid: string, uid: string, info: Map<string, any>, token: string | undefined): Promise<JoinResult> {
this._sid = sid;
this._uid = uid;
return this._biz.join(sid, uid, info, token);
}

async leave(uid: string): Promise<string> {
return this._biz.leave(uid)
}

async message(from: string, to: string, data: Map<string, any>): Promise<void> {
return this._biz.sendMessage(from, to, data);
}

close() {
this._sfu?.close();
this._biz.close();
}
}
private _biz: BizClient;
private _sfu: Client | undefined;
private _sid: string;
private _uid: string;

onerror?: (err: Error) => void;

onjoin?: (success: boolean, reason: string) => void;

onleave?: (reason: string) => void;

onpeerevent?: (ev: PeerEvent) => void;

onstreamevent?: (ev: StreamEvent) => void;

onmessage?: (msg: Message) => void;

ontrack?: (track: MediaStreamTrack, stream: RemoteStream) => void;

ondatachannel?: (ev: RTCDataChannelEvent) => void;

onspeaker?: (ev: string[]) => void;

constructor(url: string, config?: Configuration) {
this._sid = '';
this._uid = '';
this._sfu = undefined;
this._biz = new BizClient(url);

this._biz.on('join-reply', async (success: boolean, reason: string) => {
if (this.onjoin) {
this.onjoin(success, reason);
}
if (success && !this._sfu) {
const signal = new IonSFUGRPCWebSignal(url);
const sfu = new Client(signal, config);

sfu.ontrack = (track: MediaStreamTrack, stream: RemoteStream) => this.ontrack?.call(this, track, stream);
sfu.ondatachannel = (ev: RTCDataChannelEvent) => this.ondatachannel?.call(this, ev);
sfu.onspeaker = (ev: string[]) => this.onspeaker?.call(this, ev);

this._sfu = sfu;

await sfu.join(this._sid, this._uid);
}
});

this._biz.on('leave-reply', (reason: string) => {
if (this.onleave) {
this.onleave(reason);
}
});

this._biz.on('peer-event', (ev: PeerEvent) => {
if (this.onpeerevent) {
this.onpeerevent(ev);
}
});

this._biz.on('stream-event', (ev: StreamEvent) => {
if (this.onstreamevent) {
this.onstreamevent(ev);
}
});

this._biz.on('message', (msg: Message) => {
if (this.onmessage) {
this.onmessage(msg);
}
});
}

get sfu() {
return this._sfu;
}

async join(sid: string, uid: string, info: Map<string, any>, token: string | undefined): Promise<JoinResult> {
this._sid = sid;
this._uid = uid;
return this._biz.join(sid, uid, info, token);
}

async leave(uid: string): Promise<string> {
return this._biz.leave(uid);
}

async message(from: string, to: string, data: Map<string, any>): Promise<void> {
return this._biz.sendMessage(from, to, data);
}

close() {
this._sfu?.close();
this._biz.close();
}
}
Loading

0 comments on commit a7d06d2

Please sign in to comment.