= T extends T ? keyof T : never;
export type Exact = P extends Builtin ? P
: P & { [K in keyof P]: Exact
} & { [K in Exclude>]: never };
+function longToNumber(long: Long): number {
+ if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
+ throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
+ }
+ return long.toNumber();
+}
+
+if (_m0.util.Long !== Long) {
+ _m0.util.Long = Long as any;
+ _m0.configure();
+}
+
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}
diff --git a/packages/sdk-core/src/sip_incoming.ts b/packages/sdk-core/src/sip_incoming.ts
index 256092a..314a4f2 100644
--- a/packages/sdk-core/src/sip_incoming.ts
+++ b/packages/sdk-core/src/sip_incoming.ts
@@ -1,4 +1,4 @@
-import { IncomingCallData, IncomingCallData_IncomingCallRequest_Accept2, IncomingCallData_IncomingCallResponse_Accept2 } from "./generated/protobuf/sip_gateway";
+import { IncomingCallData } from "./generated/protobuf/sip_gateway";
import { EventEmitter } from "./utils";
export interface IncomingSipCallStatus {
@@ -13,7 +13,7 @@ export class SipIncomingCall extends EventEmitter {
reqIdSeed = 1;
reqs: Map void, (err: Error) => void]> = new Map();
- constructor(private callWs: string) {
+ constructor(callWs: string) {
super()
this.wsConn = new WebSocket(callWs);
this.wsConn.binaryType = "arraybuffer";
@@ -64,7 +64,7 @@ export class SipIncomingCall extends EventEmitter {
if (response.error) {
reject(new Error(response.error.message))
} else {
- resolve(response.accept || response.end || response.end || response.ring || response.accept2)
+ resolve(response.accept || response.end || response.end || response.ring || response.continue)
}
} else {
console.error("Invalid response:", response);
@@ -105,20 +105,6 @@ export class SipIncomingCall extends EventEmitter {
});
}
- async accept2(room: string, peer: string, record: boolean): Promise {
- return new Promise((resolve, reject) => {
- const buf = IncomingCallData.encode({
- request: {
- reqId: this.reqIdSeed,
- accept2: {}
- }
- }).finish();
- this.reqs.set(this.reqIdSeed, [resolve, reject]);
- this.reqIdSeed += 1;
- this.wsConn.send(buf);
- });
- }
-
async reject() {
return new Promise((resolve, reject) => {
const buf = IncomingCallData.encode({
diff --git a/packages/sdk-react-hooks/package.json b/packages/sdk-react-hooks/package.json
index 114aa51..f5fd7e6 100644
--- a/packages/sdk-react-hooks/package.json
+++ b/packages/sdk-react-hooks/package.json
@@ -1,6 +1,6 @@
{
"name": "@atm0s-media-sdk/react-hooks",
- "version": "1.0.0-alpha.8",
+ "version": "1.0.0-alpha.9",
"main": "./dist/lib.js",
"module": "./dist/lib.mjs",
"types": "./dist/lib.d.ts",
@@ -9,7 +9,7 @@
"src/*"
],
"dependencies": {
- "@atm0s-media-sdk/core": "1.0.0-alpha.7"
+ "@atm0s-media-sdk/core": "1.0.0-alpha.8"
},
"peerDependencies": {
"react": "^18.2.0"
diff --git a/packages/sdk-react-ui/package.json b/packages/sdk-react-ui/package.json
index 3faae90..8d7c949 100644
--- a/packages/sdk-react-ui/package.json
+++ b/packages/sdk-react-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@atm0s-media-sdk/react-ui",
- "version": "1.0.0-alpha.8",
+ "version": "1.0.0-alpha.9",
"main": "./dist/lib.js",
"module": "./dist/lib.mjs",
"types": "./dist/lib.d.ts",
@@ -11,8 +11,8 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
- "@atm0s-media-sdk/core": "1.0.0-alpha.7",
- "@atm0s-media-sdk/react-hooks": "1.0.0-alpha.7"
+ "@atm0s-media-sdk/core": "1.0.0-alpha.8",
+ "@atm0s-media-sdk/react-hooks": "1.0.0-alpha.9"
},
"peerDependencies": {
"react": "^18.2.0"
diff --git a/packages/sdk-react-ui/src/panels/sip_incoming.tsx b/packages/sdk-react-ui/src/panels/sip_incoming.tsx
index 5713544..97f9a5b 100644
--- a/packages/sdk-react-ui/src/panels/sip_incoming.tsx
+++ b/packages/sdk-react-ui/src/panels/sip_incoming.tsx
@@ -7,8 +7,12 @@ export interface SipIncomingCallProps {
callFrom: string,
callWs: string;
room: string,
+ sipPeer: string,
record: boolean,
- onEnd: () => void;
+ onAccept?: () => void;
+ onCancel?: () => void;
+ onReject?: () => void;
+ onEnd?: () => void;
}
type AcceptState = "Connecting" | "Accepting" | "Accepted";
@@ -30,21 +34,51 @@ export function SipIncomingCallWidget(props: SipIncomingCallProps): JSX.Element
};
}, [session]);
+ useEffect(() => {
+ switch (status.sipState) {
+ case "Bye": {
+ if (props.onEnd) {
+ props.onEnd();
+ }
+ break;
+ }
+ case "Cancelled": {
+ if (props.onCancel) {
+ props.onCancel();
+ }
+ break;
+ }
+ }
+ }, [status])
+
const accept = useCallback(() => {
setAcceptState("Connecting")
session.connect().then(() => {
setAcceptState("Accepting")
- return call.accept(props.room, props.callFrom, props.record).then(() => {
+ if (props.onAccept) {
+ props.onAccept();
+ }
+ return call.accept(props.room, props.sipPeer, props.record).then(() => {
setAcceptState("Accepted")
}).catch(() => setAcceptError("SipFailed"))
}).catch(() => setAcceptError("MediaFailed"))
- }, [call]);
+ }, [session, call, props.onAccept]);
const reject = useCallback(() => {
call.reject()
session.disconnect();
- props.onEnd()
+ if (props.onReject) {
+ props.onReject();
+ }
+ }, [session, call, props.onReject]);
+
+ const end = useCallback(() => {
+ call.end()
+ session.disconnect();
+ if (props.onEnd) {
+ props.onEnd();
+ }
}, [session, call, props.onEnd]);
return (
@@ -58,8 +92,8 @@ export function SipIncomingCallWidget(props: SipIncomingCallProps): JSX.Element
{/* Time Counting */}
{status.startedAt && }
- {/* Destination Number Info */}
- Destination: {props.callFrom}
+ {/* From Number Info */}
+ From: {props.callFrom}
@@ -82,7 +116,7 @@ export function SipIncomingCallWidget(props: SipIncomingCallProps): JSX.Element
{/* Reject Button */}
{showHangup && }
diff --git a/packages/sdk-react-ui/src/panels/sip_outgoing.tsx b/packages/sdk-react-ui/src/panels/sip_outgoing.tsx
index 5fe41b9..93f9e76 100644
--- a/packages/sdk-react-ui/src/panels/sip_outgoing.tsx
+++ b/packages/sdk-react-ui/src/panels/sip_outgoing.tsx
@@ -6,7 +6,9 @@ import { ClockTimer } from "../components/uis/clock_timer";
export interface SipOutgoingCallProps {
callTo: string,
callWs: string;
- onEnd: () => void;
+ onAccept?: () => void;
+ onEnd?: () => void;
+ onFailed?: () => void;
}
export function SipOutgoingCallWidget(props: SipOutgoingCallProps): JSX.Element {
@@ -20,9 +22,34 @@ export function SipOutgoingCallWidget(props: SipOutgoingCallProps): JSX.Element
};
}, [session]);
+ useEffect(() => {
+ switch (status.sipState) {
+ case "Accepted": {
+ if (props.onAccept) {
+ props.onAccept();
+ }
+ break;
+ }
+ case "Failure": {
+ if (props.onFailed) {
+ props.onFailed();
+ }
+ break;
+ }
+ case "Bye": {
+ if (props.onEnd) {
+ props.onEnd();
+ }
+ break;
+ }
+ }
+ }, [status])
+
const hangUp = useCallback(() => {
session.disconnect();
- props.onEnd()
+ if (props.onEnd) {
+ props.onEnd();
+ }
}, [session, props.onEnd]);
return (
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8038ac2..ede3524 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -151,6 +151,9 @@ importers:
packages/sdk-core:
dependencies:
+ long:
+ specifier: ^5.2.3
+ version: 5.2.3
protobufjs:
specifier: ^7.3.0
version: 7.3.0
@@ -186,7 +189,7 @@ importers:
packages/sdk-react-hooks:
dependencies:
'@atm0s-media-sdk/core':
- specifier: 1.0.0-alpha.7
+ specifier: 1.0.0-alpha.8
version: link:../sdk-core
react:
specifier: ^18.2.0
@@ -226,10 +229,10 @@ importers:
packages/sdk-react-ui:
dependencies:
'@atm0s-media-sdk/core':
- specifier: 1.0.0-alpha.7
+ specifier: 1.0.0-alpha.8
version: link:../sdk-core
'@atm0s-media-sdk/react-hooks':
- specifier: 1.0.0-alpha.7
+ specifier: 1.0.0-alpha.9
version: link:../sdk-react-hooks
'@emotion/react':
specifier: ^11.11.4