Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haythem/sip.js #348

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/js-sip/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "@telnyx/sip",
"version": "1.0.0",
"main": "dist/js-sip/src/index.js",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rm -rf ./dist && mkdir ./dist && tsc",
"release": "release-it"
},
"dependencies": {
"sip.js": "^0.15.4"
"eventemitter3": "^5.0.1",
"sip.js": "^0.21.2"
},
"devDependencies": {
"typescript": "^5.4.2"
}
}
75 changes: 0 additions & 75 deletions packages/js-sip/src/SipCall.ts

This file was deleted.

105 changes: 0 additions & 105 deletions packages/js-sip/src/SipClient.ts

This file was deleted.

132 changes: 132 additions & 0 deletions packages/js-sip/src/call.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { Session } from "sip.js";
import {
SessionDescriptionHandler,
SessionManager,
} from "sip.js/lib/platform/web";
import { SwEvent } from "./constant";
import { eventBus } from "./events";
import { CallState, ICall } from "./types";

export class Call implements ICall {
public direction: "inbound" | "outbound";
public prevState: CallState;
public state: CallState;
public destinationNumber: string;

private _session: Session;
private _sessionManager: SessionManager;

constructor(
session: Session,
manager: SessionManager,
direction: "inbound" | "outbound",
destinationNumber: string
) {
session.dialog?.id;
this._session = session;
this._sessionManager = manager;
this.direction = direction;
this.destinationNumber = destinationNumber;
}

public get id() {
return this._session.id;
}
public get localStream(): MediaStream | null {
return this._sessionManager.getLocalMediaStream(this._session) ?? null;
}

public get remoteStream(): MediaStream | null {
return this._sessionManager.getRemoteMediaStream(this._session) ?? null;
}

public telnyxIDs: {};

public hangup(): Promise<void> {
return this._sessionManager.hangup(this._session).then(() => {
this.setState("hangup");
});
}

public setState(nextState: CallState) {
this.prevState = this.state;
this.state = nextState;

eventBus.emit(SwEvent.Notification, { call: this, type: "callUpdate" });
}

public answer(): Promise<void> {
return this._sessionManager.answer(this._session).then(() => {
this.setState("active");
});
}
public deaf(): void {
const handler = this._session.sessionDescriptionHandler;
if (!(handler instanceof SessionDescriptionHandler)) {
return;
}
handler.enableReceiverTracks(false);
}
dtmf(dtmf: any): Promise<void> {
throw new Error("Method not implemented.");
}
hold(): Promise<void> {
return this._sessionManager.hold(this._session);
}
muteAudio(): Promise<void> {
throw new Error("Method not implemented.");
}
muteVideo(): Promise<void> {
throw new Error("Method not implemented.");
}
setAudioInDevice(deviceId: string): Promise<void> {
throw new Error("Method not implemented.");
}
setAudioOutDevice(deviceId: string): Promise<void> {
throw new Error("Method not implemented.");
}
setVideoDevice(deviceId: any): Promise<void> {
throw new Error("Method not implemented.");
}
toggleAudioMute(): void {
throw new Error("Method not implemented.");
}
toggleDeaf(): void {
throw new Error("Method not implemented.");
}
toggleHold(): Promise<void> {
throw new Error("Method not implemented.");
}
toggleVideoMute(): void {
throw new Error("Method not implemented.");
}
undeaf(): void {
const handler = this._session.sessionDescriptionHandler;
if (!(handler instanceof SessionDescriptionHandler)) {
return;
}
handler.enableReceiverTracks(true);
}
unhold(): Promise<void> {
return this._sessionManager.unhold(this._session);
}

unmuteAudio(): void {
const handler = this._session.sessionDescriptionHandler;
if (!(handler instanceof SessionDescriptionHandler)) {
return;
}
handler.enableSenderTracks(true);
}
unmuteVideo(): void {
const handler = this._session.sessionDescriptionHandler;
if (!(handler instanceof SessionDescriptionHandler)) {
return;
}
handler.enableSenderTracks(true);
}

getStats() {
console.log("getStats");
}
}
Loading
Loading