@koi-design/callkit 2.1.4 → 2.1.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -476,7 +476,7 @@ declare class Connect {
476
476
  force?: boolean;
477
477
  }): Promise<void>;
478
478
  private getAduioReference;
479
- permission(): Promise<void>;
479
+ permission(): Promise<boolean>;
480
480
  /**
481
481
  * Making connection
482
482
  * @returns
@@ -3880,13 +3880,13 @@ var WebCall = (() => {
3880
3880
  // package.json
3881
3881
  var package_default = {
3882
3882
  name: "@koi-design/callkit",
3883
- version: "2.1.4",
3883
+ version: "2.1.5-beta.1",
3884
3884
  description: "callkit",
3885
3885
  author: "koi",
3886
3886
  license: "ISC",
3887
3887
  scripts: {
3888
3888
  build: "tsup",
3889
- start: "vite",
3889
+ start: "vite --host 0.0.0.0",
3890
3890
  dev: "tsup --watch",
3891
3891
  lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
3892
3892
  release: "tsup && node scripts/pkg.js"
@@ -18608,36 +18608,66 @@ ${log}` : log;
18608
18608
  return {};
18609
18609
  }
18610
18610
  };
18611
-
18612
- // core/connect.ts
18613
- function convertObjectStringToJSON(input) {
18614
- const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
18615
- return corrected;
18616
- }
18617
18611
  var closeStream = (stream) => {
18618
18612
  if (stream)
18619
18613
  stream.getTracks().forEach((track) => track.stop());
18620
18614
  };
18621
- var initUserMedia = () => {
18622
- if (typeof navigator.mediaDevices === "undefined") {
18615
+ async function checkPermission() {
18616
+ if (!navigator.mediaDevices) {
18623
18617
  navigator.mediaDevices = {};
18624
18618
  }
18625
- if (typeof navigator.mediaDevices.getUserMedia === "undefined") {
18626
- navigator.mediaDevices.getUserMedia = (constraints) => {
18627
- const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
18628
- if (!getUserMedia) {
18629
- return Promise.reject(
18630
- new Error(
18631
- "Unable to obtain device permissions. Please check your browser settings or device permissions."
18632
- )
18633
- );
18619
+ if (navigator.mediaDevices.getUserMedia) {
18620
+ return navigator.mediaDevices.getUserMedia({ audio: true });
18621
+ }
18622
+ const legacyGetUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
18623
+ if (!legacyGetUserMedia) {
18624
+ const err = Object.assign(
18625
+ new Error(
18626
+ "Unable to obtain device permissions. Please check your browser settings or device permissions."
18627
+ ),
18628
+ {
18629
+ name: "NotSupportedError"
18634
18630
  }
18635
- return new Promise((resolve, reject) => {
18636
- getUserMedia.call(navigator, constraints, resolve, reject);
18637
- });
18638
- };
18631
+ );
18632
+ return Promise.reject(err);
18633
+ }
18634
+ return new Promise((resolve, reject) => {
18635
+ legacyGetUserMedia.call(navigator, { audio: true }, resolve, reject);
18636
+ });
18637
+ }
18638
+ var permissionError = (err) => {
18639
+ const errorName = err?.name || "UnknownError";
18640
+ const errorMessage = err?.message;
18641
+ switch (errorName) {
18642
+ case "NotAllowedError":
18643
+ return {
18644
+ type: "permission-denied",
18645
+ reason: "User or browser denied microphone permission"
18646
+ };
18647
+ case "NotFoundError":
18648
+ return {
18649
+ type: "no-device",
18650
+ reason: "No microphone detected"
18651
+ };
18652
+ case "NotReadableError":
18653
+ return {
18654
+ type: "device-busy",
18655
+ reason: "Microphone is being used by another application"
18656
+ };
18657
+ default:
18658
+ return {
18659
+ name: errorName,
18660
+ type: errorName,
18661
+ reason: errorMessage || "Unknown error"
18662
+ };
18639
18663
  }
18640
18664
  };
18665
+
18666
+ // core/connect.ts
18667
+ function convertObjectStringToJSON(input) {
18668
+ const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
18669
+ return corrected;
18670
+ }
18641
18671
  var Connect = class {
18642
18672
  callKit;
18643
18673
  /**
@@ -18822,15 +18852,31 @@ ${log}` : log;
18822
18852
  return audioRef;
18823
18853
  }
18824
18854
  async permission() {
18825
- this.callKit.logger.info("permission", {
18826
- caller: "Connect.permission",
18827
- content: {
18828
- permission: true
18829
- }
18830
- });
18831
- initUserMedia();
18832
- const _stream = await navigator.mediaDevices.getUserMedia({ audio: true });
18833
- closeStream(_stream);
18855
+ try {
18856
+ this.callKit.logger.info("permission", {
18857
+ caller: "Connect.permission",
18858
+ content: {
18859
+ permission: true
18860
+ }
18861
+ });
18862
+ await checkPermission();
18863
+ return true;
18864
+ } catch (err) {
18865
+ this.callKit.reset();
18866
+ const error = permissionError(err);
18867
+ this.callKit.logger.error(err, {
18868
+ caller: "Connect.permission",
18869
+ content: {
18870
+ permission: false,
18871
+ errCode: ErrorCode.WEBRTC_USER_MEDIA_ERROR,
18872
+ errName: error.name,
18873
+ type: error.type,
18874
+ reason: error.reason,
18875
+ errRaw: err
18876
+ }
18877
+ });
18878
+ return false;
18879
+ }
18834
18880
  }
18835
18881
  /**
18836
18882
  * Making connection
@@ -19084,15 +19130,10 @@ ${log}` : log;
19084
19130
  connectStatus: this.connectStatus
19085
19131
  }
19086
19132
  });
19087
- await this.permission().catch((err) => {
19088
- this.callKit.reset();
19089
- this.callKit.logger.error(err, {
19090
- caller: "Connect.register",
19091
- content: {
19092
- errCode: ErrorCode.WEBRTC_USER_MEDIA_ERROR
19093
- }
19094
- });
19095
- });
19133
+ const permissionResult = await this.permission();
19134
+ if (!permissionResult) {
19135
+ return;
19136
+ }
19096
19137
  const { userInfo, constrains } = this.callKit.config.getConfig();
19097
19138
  const localStreamFactory = async () => {
19098
19139
  this.mediaStream = await navigator.mediaDevices.getUserMedia(constrains);