zmp-sdk 2.38.0 → 2.38.2
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/apis/apis/createCameraContext.js +1 -0
- package/apis/apis/downloadFile.js +1 -0
- package/apis/apis/getFileInfo.js +1 -0
- package/apis/apis/getSavedFileList.js +1 -0
- package/apis/apis/getUserInfo.js +1 -1
- package/apis/apis/removeSavedFile.js +1 -0
- package/apis/apis/saveFile.js +1 -0
- package/apis/common/apis/general/getFileInfo.js +1 -0
- package/apis/common/apis/general/getSavedFileList.js +1 -0
- package/apis/common/apis/general/getUserInfo.js +1 -1
- package/apis/common/apis/general/lfsSaveFile.js +1 -0
- package/apis/common/apis/general/media/camera.js +1 -0
- package/apis/common/apis/general/removeSavedFile.js +1 -0
- package/apis/common/apis/general/saveFile.js +1 -0
- package/apis/index.d.ts +3 -0
- package/apis/media/camera.js +1 -0
- package/apis/media/zmaCamera.js +1 -0
- package/apis/package.json.js +1 -1
- package/apis/types/media.js +1 -0
- package/browser.min.js +2 -2
- package/index.d.ts +3 -0
- package/index.es.js +2 -2
- package/index.js +2 -2
- package/index.umd.js +2 -2
- package/package.json +1 -1
- package/apis/apis/openWidget.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o,{object as e}from'./../external/zod/lib/index.mjs.js';import{functionHandler as n}from"../utils/decorator.js";import{ZMACameraImp as i}from"../media/zmaCamera.js";var t=e({play:o.function(),pause:o.function()}).refine((function(o){return"play"in o&&"pause"in o}),{message:"Invalid HTMLVideoElement"}),a=[e({videoElement:t,mediaConstraints:o.object({width:o.number().min(100).optional(),height:o.number().min(100).optional(),facingMode:o.string().optional(),audio:o.boolean().optional(),video:o.boolean().optional(),deviceId:o.string().optional(),mirrored:o.boolean().optional()}).nullish()}).optional()];function r(o){return n("createCameraContext",a,[o],(function(o){return console.log("createCameraContext",o),new i(o.videoElement,o.mediaConstraints)}))}export{r as createCameraContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import o,{object as e}from'./../external/zod/lib/index.mjs.js';import t from"../appEnv/index.js";import n from"../common/notFound.js";import{functionHandler as s}from"../utils/decorator.js";import i from"../common/apis/general/saveFile.js";import{__generator as m}from'./../external/tslib/tslib.es6.js';var u=[e({url:o.string()}).optional()];function l(r){return a.apply(this,arguments)}function a(){return a=r((function(o){return m(this,(function(e){return[2,s("downloadFile",u,[o],(l=r((function(r){var o;return m(this,(function(e){switch(e.label){case 0:return t.isMp?(o=r.url,[4,i(o)]):[3,2];case 1:return[2,e.sent()];case 2:return t.isMpWeb?[2,Promise.resolve()]:[2,Promise.reject(n("saveFile",{}))]}}))})),function(r){return l.apply(this,arguments)}))];var l}))})),a.apply(this,arguments)}export{l as downloadFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import t,{object as o}from'./../external/zod/lib/index.mjs.js';import r from"../appEnv/index.js";import i from"../common/notFound.js";import{functionHandler as n}from"../utils/decorator.js";import s from"../common/apis/general/getFileInfo.js";import{__generator as m}from'./../external/tslib/tslib.es6.js';var l=[o({filePath:t.string(),digestAlgorithm:t.enum(["sha1","md5"])}).optional()];function p(e){return u.apply(this,arguments)}function u(){return u=e((function(t){return m(this,(function(o){return[2,n("getFileInfo",l,[t],(p=e((function(e){return m(this,(function(t){switch(t.label){case 0:return r.isMp?[4,s(e.filePath,e.digestAlgorithm)]:[3,2];case 1:return[2,t.sent()];case 2:return r.isMpWeb?[2,Promise.resolve({size:"",digest:"",type:""})]:[2,Promise.reject(i("getFileInfo",{}))]}}))})),function(e){return p.apply(this,arguments)}))];var p}))})),u.apply(this,arguments)}export{p as getFileInfo};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from"../appEnv/index.js";import r from"../common/notFound.js";import{functionHandler as o}from"../utils/decorator.js";import s from"../common/apis/general/getSavedFileList.js";import{__generator as n}from'./../external/tslib/tslib.es6.js';function i(e){return m.apply(this,arguments)}function m(){return m=e((function(i){return n(this,(function(m){return[2,o("getSavedFileList",[],[i],(u=e((function(e){return n(this,(function(e){switch(e.label){case 0:return t.isMp?[4,s()]:[3,2];case 1:return[2,e.sent()];case 2:return t.isMpWeb?[2,Promise.resolve()]:[2,Promise.reject(r("getSavedFileList",{}))]}}))})),function(e){return u.apply(this,arguments)}))];var u}))})),m.apply(this,arguments)}export{i as getSavedFileList};
|
package/apis/apis/getUserInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import o,{object as r}from'./../external/zod/lib/index.mjs.js';import t from"../appEnv/index.js";import n from"../common/notFound.js";import{functionHandler as s}from"../utils/decorator.js";import a from"../common/apis/general/getUserInfo.js";import{__generator as i}from'./../external/tslib/tslib.es6.js';var m=[r({avatarType:o.enum(["small","normal","large"]).optional(),autoRequestPermission:o.boolean().default(!1).optional()}).optional()];function u(e){return l.apply(this,arguments)}function l(){return l=e((function(o){return i(this,(function(r){return[2,s("getUserInfo",m,[o],(u=e((function(e){var o,r;return i(this,(function(s){switch(s.label){case 0:return t.isMp?(o=null==e?void 0:e.avatarType,r=null==e?void 0:e.autoRequestPermission,[4,a(o,r)]):[3,2];case 1:return[2,{userInfo:s.sent()}];case 2:return t.isMpWeb?[2,Promise.resolve({userInfo:{id:"3368637342326461234",name:"User Name",avatar:"https://h5.zdn.vn/static/images/avatar.png"}})]:[2,Promise.reject(n("getUserInfo",{}))]}}))})),function(e){return u.apply(this,arguments)}))];var u}))})),l.apply(this,arguments)}export{u as getUserInfo};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import r,{object as o}from'./../external/zod/lib/index.mjs.js';import t from"../appEnv/index.js";import n from"../common/notFound.js";import{functionHandler as i}from"../utils/decorator.js";import s from"../common/apis/general/removeSavedFile.js";import{__generator as m}from'./../external/tslib/tslib.es6.js';var a=[o({filePath:r.string()}).optional()];function l(e){return p.apply(this,arguments)}function p(){return p=e((function(r){return m(this,(function(o){return[2,i("removeSavedFile",a,[r],(l=e((function(e){return m(this,(function(r){switch(r.label){case 0:return t.isMp?[4,s(e.filePath)]:[3,2];case 1:return[2,r.sent()];case 2:return t.isMpWeb?[2,Promise.resolve()]:[2,Promise.reject(n("removeSavedFile",{}))]}}))})),function(e){return l.apply(this,arguments)}))];var l}))})),p.apply(this,arguments)}export{l as removeSavedFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import e,{object as o}from'./../external/zod/lib/index.mjs.js';import t from"../appEnv/index.js";import s from"../common/notFound.js";import{functionHandler as n}from"../utils/decorator.js";import i from"../common/apis/general/lfsSaveFile.js";import{__generator as m}from'./../external/tslib/tslib.es6.js';var a=[o({filePath:e.string()}).optional()];function l(r){return p.apply(this,arguments)}function p(){return p=r((function(e){return m(this,(function(o){return[2,n("saveFile",a,[e],(l=r((function(r){var e;return m(this,(function(o){switch(o.label){case 0:return t.isMp?(e=r.filePath,[4,i(e)]):[3,2];case 1:return[2,o.sent()];case 2:return t.isMpWeb?[2,Promise.resolve()]:[2,Promise.reject(s("saveFile",{}))]}}))})),function(r){return l.apply(this,arguments)}))];var l}))})),p.apply(this,arguments)}export{l as saveFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import n from"../../call/index.js";import{__generator as o}from'./../../../external/tslib/tslib.es6.js';var s,e=(s=t((function(t,s){return o(this,(function(o){return[2,new Promise((function(o,e){n("LFS_FILE_INFO",{file_path:t,digest_algorithm:s},{success:function(t){o(t)},fail:function(t){e(t)}},{})}))]}))})),function(t,n){return s.apply(this,arguments)});export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from'./../../../external/@swc/helpers/src/_object_spread.mjs.js';import r from"../../call/index.js";import{__generator as s}from'./../../../external/tslib/tslib.es6.js';var o=e((function(){return s(this,(function(e){return[2,new Promise((function(e,s){r("LFS_LIST",{},{success:function(r){var s=r.map((function(e){var r=t({},e);try{r.filePath=r.file_path,r.createTime=r.created_time,delete r.file_path,delete r.created_time}catch(e){}return r}));e({list:s})},fail:function(e){s(e)}},{})}))]}))}));export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from"../../token.js";import{APIS as n}from"../../../constants.js";import{canUseAccessTokenByDefault as
|
|
1
|
+
import e from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from"../../token.js";import{APIS as n,APP_ID as s}from"../../../constants.js";import{canUseAccessTokenByDefault as i}from"../../../utils/common.js";import{__generator as r}from'./../../../external/tslib/tslib.es6.js';var o,c=(o=e((function(o,c){var a,u,l,d;return r(this,(function(m){switch(m.label){case 0:return(u=c)?[3,2]:[4,i()];case 1:u=!m.sent(),m.label=2;case 2:return a=u,[4,t.getAccessToken(a)];case 3:return l=m.sent(),d="id,name,user_id_by_oa,is_sensitive",d=o?"".concat(d,",picture.type(").concat(o,")"):"".concat(d,",picture"),[4,fetch("".concat(n.GET_USER_INFO,"?fields=").concat(d,"&miniapp_id=").concat(s),{headers:{access_token:l||""}}).then(function(){var t=e((function(e){var t,n,s,i;return r(this,(function(r){switch(r.label){case 0:return[4,e.json()];case 1:return s=r.sent(),i=null==s?void 0:s.user_id_by_oa,[2,{id:null==s?void 0:s.id,name:(null==s?void 0:s.name)||"",avatar:(null==s||null===(t=s.picture)||void 0===t||null===(n=t.data)||void 0===n?void 0:n.url)||"",idByOA:i,followedOA:!!i,isSensitive:null==s?void 0:s.is_sensitive}]}}))}));return function(e){return t.apply(this,arguments)}}())];case 4:return[2,m.sent()]}}))})),function(e,t){return o.apply(this,arguments)});export{c as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import n from"../../call/index.js";import{__generator as s}from'./../../../external/tslib/tslib.es6.js';var e,o=(e=t((function(t){return s(this,(function(s){return[2,new Promise((function(s,e){n("LFS_FILE_SAVE",{file_path:t},{success:function(t){s({savedPath:t})},fail:function(t){e(t)}},{})}))]}))})),function(t){return e.apply(this,arguments)});export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from'./../../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from'./../../../../external/@swc/helpers/src/_class_call_check.mjs.js';import i from'./../../../../external/@swc/helpers/src/_create_class.mjs.js';import{MPEEmitter as n}from"../../../eventEmitter.js";import{__generator as s}from'./../../../../external/tslib/tslib.es6.js';var a="image/png",o=function(){function o(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"user",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=this;t(this,o),this.tick=function(){if(console.log("DUNGNN tick",s._userRequestFrameCallback,s.haveVideoStream()),s.haveVideoStream()&&s._userRequestFrameCallback){var e=s.getCanvas();s.drawFrame(),e?(e.toDataURL("image/png"),requestAnimationFrame(s.tick)):console.log("canvas not found")}},console.log("DUNGNN constructor",e,i,n),this._videoElement=e,this._videoElement.width=this._videoElement.width||640,this._videoElement.height=this._videoElement.height||360,this._facingMode=null!=i?i:"user",this._cameraList=[],this._streamList=[],this._selectedDeviceId="",this._canvasElement=n,this._ctx=null,this._hasUserMedia=!1,this._userRequestFrameCallback=!1,console.log("DUNGNN end const")}var r=o.prototype;return r.on=function(e,t){console.log("DUNGNN on",n,e,t)},r.off=function(e){console.log("DUNGNN off",n,e)},r.getQualityNumber=function(e){switch(e){case"high":return.8;case"normal":default:return.5;case"low":return.2}},r.getVideoInputs=function(e){var t=this;return this._cameraList=[],e.forEach((function(e){"videoinput"===e.kind&&t._cameraList.push(e)})),1==this._cameraList.length&&(this._facingMode="user"),this._cameraList},r.getMediaConstraints=function(){var e={};return""==this._selectedDeviceId?e.facingMode=this._facingMode:e.deviceId={exact:this._selectedDeviceId},e.width={exact:this._videoElement.width},e.height={exact:this._videoElement.height},{video:e,audio:!1}},r.selectCamera=function(){var e=!0,t=!1,i=void 0;try{for(var n,s=this._cameraList[Symbol.iterator]();!(e=(n=s.next()).done);e=!0){var a=n.value;if("user"==this._facingMode&&a.label.toLowerCase().includes("front")||"environment"==this._facingMode&&a.label.toLowerCase().includes("back")){this._selectedDeviceId=a.deviceId;break}}}catch(e){t=!0,i=e}finally{try{e||null==s.return||s.return()}finally{if(t)throw i}}},r.flip=function(){this._facingMode="user"==this._facingMode?"environment":"user",this._videoElement.style.transform="",this.selectCamera()},r.start=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],i=this;return e((function(){return s(this,(function(e){return[2,new Promise((function(e,n){i.stop(),navigator.mediaDevices.getUserMedia(i.getMediaConstraints()).then((function(s){console.log("DUNGNN callback stream",s),i._streamList.push(s),i.info().then((function(s){console.log("DUNGNN info",s),i.selectCamera(),t?i.stream().then((function(t){e(i._facingMode)})).catch((function(e){n(e)})):e(i._selectedDeviceId)})).catch((function(e){n(e)}))})).catch((function(e){i._hasUserMedia=!1,n(e)}))}))]}))}))()},r.info=function(){var t=this;return e((function(){return s(this,(function(e){return[2,new Promise((function(e,i){navigator.mediaDevices.enumerateDevices().then((function(i){t.getVideoInputs(i),e(t._cameraList)})).catch((function(e){i(e)}))}))]}))}))()},r.stream=function(){var t=this;return e((function(){return s(this,(function(e){return[2,new Promise((function(e,i){navigator.mediaDevices.getUserMedia(t.getMediaConstraints()).then((function(i){t._streamList.push(i),t._videoElement.srcObject=i,"user"==t._facingMode&&(t._videoElement.style.transform="scale(-1,1)"),t._videoElement.play(),t._hasUserMedia=!0,t._userRequestFrameCallback&&t.tick(),e(t._facingMode)})).catch((function(e){t._hasUserMedia=!1,i(e)}))}))]}))}))()},r.stop=function(){this._streamList.forEach((function(e){e.getTracks().forEach((function(e){e.stop()}))})),this._hasUserMedia=!1},r.takePhoto=function(e){if(!this._hasUserMedia)return null;var t=e||{};console.log("DUNGNN takePhoto",t);var i,n=this.getCanvas(t);return this.drawFrame(t),n&&n.toDataURL(null!==(i=t.format)&&void 0!==i?i:a,this.getQualityNumber(t.quality))},r.haveVideoStream=function(){var e=this._videoElement;return e&&e.videoHeight>0&&this._hasUserMedia},r.getCanvas=function(e){var t=this._videoElement,i=e||{};if(!this.haveVideoStream())return null;if(!this._ctx){var n=t.videoWidth,s=t.videoHeight;if(!i.useVideoSourceSize){var a=n/s;s=(n=i.minScreenshotWidth||t.clientWidth)/a,i.minScreenshotHeight&&s<i.minScreenshotHeight&&(n=(s=i.minScreenshotHeight)*a)}this._canvasElement=document.createElement("canvas"),this._canvasElement.width=(null==i?void 0:i.width)||n,this._canvasElement.height=(null==i?void 0:i.height)||s,this._ctx=this._canvasElement.getContext("2d")}return this._canvasElement},r.drawFrame=function(e){var t=this._videoElement,i=e||{};if(t&&this._ctx&&this._canvasElement){var n=this._canvasElement,s=this._ctx;n.width=(null==i?void 0:i.width)||n.width,n.height=(null==i?void 0:i.height)||n.height,(null==i?void 0:i.mirrored)&&(s.translate(n.width,0),s.scale(-1,1)),s.clearRect(0,0,n.width,n.height),s.drawImage(t,0,0,n.width,n.height),(null==i?void 0:i.mirrored)&&(s.scale(-1,1),s.translate(-n.width,0))}},i(o,[{key:"facingMode",get:function(){return this._facingMode},set:function(e){this._facingMode=e}},{key:"cameraList",get:function(){return this._cameraList}},{key:"cameraCount",get:function(){return this._cameraList.length}},{key:"selectedDeviceId",get:function(){return this._selectedDeviceId}}]),o}();export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import n from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from"../../call/index.js";import{__generator as o}from'./../../../external/tslib/tslib.es6.js';var s,e=(s=n((function(n){return o(this,(function(o){return[2,new Promise((function(o,s){t("LFS_FILE_REMOVE",{file_path:n},{success:function(n){o(n)},fail:function(n){s(n)}},{})}))]}))})),function(n){return s.apply(this,arguments)});export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import n from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import s from"../../call/index.js";import{__generator as t}from'./../../../external/tslib/tslib.es6.js';var e,o=(e=n((function(n){return t(this,(function(t){return[2,new Promise((function(t,e){s("SAVE_FILE",{fileUrl:n},{success:function(n){t({saved_path:n})},fail:function(n){e(n)}},{})}))]}))})),function(n){return e.apply(this,arguments)});export{o as default};
|
package/apis/index.d.ts
CHANGED
|
@@ -1248,10 +1248,13 @@ declare function clearStorage(args: AsyncVoidCallback & TypeOf<(typeof clearStor
|
|
|
1248
1248
|
|
|
1249
1249
|
declare const getUserInfoArgs: ZodOptional<ZodObject<{
|
|
1250
1250
|
avatarType: ZodOptional<ZodEnum<["small", "normal", "large"]>>;
|
|
1251
|
+
autoRequestPermission: ZodOptional<ZodDefault<ZodBoolean>>;
|
|
1251
1252
|
}, "strip", ZodTypeAny, {
|
|
1252
1253
|
avatarType?: "normal" | "small" | "large" | undefined;
|
|
1254
|
+
autoRequestPermission?: boolean | undefined;
|
|
1253
1255
|
}, {
|
|
1254
1256
|
avatarType?: "normal" | "small" | "large" | undefined;
|
|
1257
|
+
autoRequestPermission?: boolean | undefined;
|
|
1255
1258
|
}>>[];
|
|
1256
1259
|
declare function getUserInfo(args?: AsyncCallback<GetUserInfoReturns> & TypeOf<(typeof getUserInfoArgs)[0]>): Promise<GetUserInfoReturns>;
|
|
1257
1260
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o;!function(o){o.VIDEO="video",o.AUDIO="audio"}(o||(o={}));export{o as StreamType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import t from'./../external/@swc/helpers/src/_class_call_check.mjs.js';import{MPEEmitter as i}from"../common/eventEmitter.js";import n from"../utils/lodash.js";import{CameraEvents as a,FacingMode as r,PhotoFormat as s,PhotoQuality as o,StreamType as c}from"../types/media.js";import{__generator as l}from'./../external/tslib/tslib.es6.js';import{Events as d}from"../types/enum.js";var u="ZMACameraImp",h={format:s.JPEG,quality:o.NORMAL,mirrored:!1,useVideoSourceSize:!1},m={width:1024,height:768,facingMode:r.FRONT,mirrored:!1,audio:!1,video:!0},v=function(){function o(e){var n,r,c,l,d,h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,v=this;t(this,o),this._videoEnabled=!0,this._audioEnabled=null,this.tick=function(){if(v.haveVideoStream()&&v._userRequestFrameCallback){var e=v.getCanvas();if(v.drawFrame(),e){var t={data:e.toDataURL(s.PNG),width:e.width,height:e.height};i.getInstance().emit(a.OnFrameCallback,0,t),requestAnimationFrame(v.tick)}}},this._videoElement=e,this._mediaConstraints=null!=h?h:null,this._facingMode=null!==(n=null==h?void 0:h.facingMode)&&void 0!==n?n:m.facingMode,console.log("".concat(u," ZMACameraImp"),h,this._facingMode),this._cameraList=[],this._stream=null,this._selectedDeviceId=null!==(r=null==h?void 0:h.deviceId)&&void 0!==r?r:"",this._canvasElement=null,this._ctx=null,this._hasUserMedia=!1,this._mirror=null!==(c=null==h?void 0:h.mirrored)&&void 0!==c?c:m.mirrored,this._userRequestFrameCallback=!1,this._audioEnabled=null!==(l=null==h?void 0:h.audio)&&void 0!==l?l:m.audio,this._videoEnabled=null!==(d=null==h?void 0:h.video)&&void 0!==d?d:m.video}var v=o.prototype;return v.on=function(e,t){i.getInstance().on(e,(function(e){t(e)})),e===a.OnFrameCallback&&(this._userRequestFrameCallback=!0,this.tick())},v.off=function(e){i.getInstance().off(e),e===a.OnFrameCallback&&(this._userRequestFrameCallback=!1)},v.getQualityNumber=function(e){switch(e){case"high":return.9;case"normal":default:return.6;case"low":return.2}},v.getFacingMode=function(){return this._facingMode},v.getCameraList=function(){return this._cameraList},v.getCameraCount=function(){return this._cameraList.length},v.getSelectedDeviceId=function(){return this._selectedDeviceId},v.setDeviceId=function(t){var i=this;return e((function(){return l(this,(function(e){switch(e.label){case 0:return i._selectedDeviceId=t,i._hasUserMedia?[4,i.stream()]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))()},v.getVideoInputs=function(e){var t=this;return this._cameraList=[],e.forEach((function(e){"videoinput"===e.kind&&t._cameraList.push(e)})),this._cameraList},v.updateMediaConstraints=function(t){var i=this;return e((function(){var e,a,r,s,o,c;return l(this,(function(l){switch(l.label){case 0:return n.isEmpty(t)?(console.log("".concat(u," constraints empty")),[2]):JSON.stringify(t)!==JSON.stringify(i._mediaConstraints)?(console.log("".concat(u," updateMediaConstraints"),JSON.stringify(i._mediaConstraints),JSON.stringify(t)),i._mediaConstraints=t,i._facingMode=null!==(e=null==t?void 0:t.facingMode)&&void 0!==e?e:i._facingMode,i._selectedDeviceId=null!==(a=null==t?void 0:t.deviceId)&&void 0!==a?a:i._selectedDeviceId,i._mirror=null!==(r=null==t?void 0:t.mirrored)&&void 0!==r?r:i._mirror,i._audioEnabled=null!==(s=null==t?void 0:t.audio)&&void 0!==s?s:i._audioEnabled,i._videoEnabled=null!==(o=null==t?void 0:t.video)&&void 0!==o?o:i._videoEnabled,i._selectedDeviceId=null!==(c=null==t?void 0:t.deviceId)&&void 0!==c?c:i._selectedDeviceId,i._hasUserMedia?[4,i.stream()]:[3,2]):(console.log("".concat(u," constraints not changed")),[2]);case 1:l.sent(),l.label=2;case 2:return[2]}}))}))()},v.getCurrentMediaConstraints=function(){var e=this._mediaConstraints,t={};this._videoElement.width=(null==e?void 0:e.width)||this._videoElement.width||m.width,this._videoElement.height=(null==e?void 0:e.height)||this._videoElement.height||m.height;var i=!1!==this._videoEnabled,n=!1!==this._audioEnabled;return i&&(""==this._selectedDeviceId&&null!==this._facingMode?t.facingMode=this._facingMode:t.deviceId={exact:this._selectedDeviceId},t.width={exact:this._videoElement.width},t.height={exact:this._videoElement.height}),{video:!!i&&t,audio:n}},v.selectCamera=function(){var e=!0,t=!1,i=void 0;try{for(var n,a=this._cameraList[Symbol.iterator]();!(e=(n=a.next()).done);e=!0){var s=n.value;if(this._facingMode==r.FRONT&&s.label.toLowerCase().includes("front")||this._facingMode==r.BACK&&s.label.toLowerCase().includes("back")){this._selectedDeviceId=s.deviceId;break}}}catch(e){t=!0,i=e}finally{try{e||null==a.return||a.return()}finally{if(t)throw i}}},v.flip=function(){var t=this;return e((function(){return l(this,(function(e){switch(e.label){case 0:return t._facingMode=t._facingMode==r.FRONT?r.BACK:r.FRONT,t._videoElement.style.transform="",t.selectCamera(),t._hasUserMedia?[4,t.stream()]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))()},v.start=function(){var t=this;return e((function(){var n,r;return l(this,(function(s){return n=i.getInstance(),r=function(e){try{t._hasUserMedia&&t.stop()}catch(e){}},n.off(d.AppPaused,r),n.on(d.AppPaused,r),[2,new Promise((o=e((function(e,n){var r;return l(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,t.stream()];case 1:return s.sent(),i.getInstance().emit(a.OnStartCallback,0),e(t._selectedDeviceId),[3,3];case 2:return r=s.sent(),n(r),[3,3];case 3:return[2]}}))})),function(e,t){return o.apply(this,arguments)}))];var o}))}))()},v.info=function(){var t=this;return e((function(){return l(this,(function(e){return[2,new Promise((function(e,i){navigator.mediaDevices.enumerateDevices().then((function(i){t.getVideoInputs(i),e(t._cameraList)})).catch((function(e){i(e)}))}))]}))}))()},v.stream=function(){var t=this;return e((function(){return l(this,(function(i){return[2,new Promise((function(i,n){try{t._stop();var a=t.getCurrentMediaConstraints();if(console.log("".concat(u," stream"),a),!1===a.video&&!a.audio)return void i(t._facingMode);navigator.mediaDevices.getUserMedia(a).then((r=e((function(e){return l(this,(function(n){switch(n.label){case 0:return[4,t.info()];case 1:return n.sent(),t.selectCamera(),t.handleUserMedia(null,e),i(t._facingMode),[2]}}))})),function(e){return r.apply(this,arguments)})).catch((function(e){console.log("".concat(u," DUNGNN 2"),e),t.handleUserMedia(e),n(e)}))}catch(e){n(e)}var r}))]}))}))()},v.handleUserMedia=function(e,t){var i=this;if(!e&&t){this._stream=t;try{this._videoElement&&(this._videoElement.srcObject=t,(this._facingMode==r.FRONT||this._mirror)&&(this._videoElement.style.transform="scale(-1,1)"),this._videoElement.onloadedmetadata=function(){i._userRequestFrameCallback&&i.tick()},this._videoElement.play().then((function(){i._hasUserMedia=!0})).catch((function(e){console.log("".concat(u," DUNGNN 3"),e),i._hasUserMedia=!1})))}catch(e){console.log("".concat(u," DUNGNN 1"),e),this._hasUserMedia=!1}}else this._hasUserMedia=!1},v.updateTrackEnable=function(t,i){var n=this;return e((function(){return l(this,(function(e){switch(e.label){case 0:if(t===c.VIDEO){if(n._videoEnabled===i)return[2];n._videoEnabled=i}else{if(n._audioEnabled===i)return[2];n._audioEnabled=i}return[4,n.stream()];case 1:return e.sent(),[2]}}))}))()},v.pause=function(t){var i=this;return e((function(){return l(this,(function(e){switch(e.label){case 0:return[4,i.updateTrackEnable(t,!1)];case 1:return e.sent(),[2]}}))}))()},v.resume=function(t){var i=this;return e((function(){return l(this,(function(e){switch(e.label){case 0:return[4,i.updateTrackEnable(t,!0)];case 1:return e.sent(),[2]}}))}))()},v.isUsing=function(){return this._hasUserMedia},v.stop=function(){this._stop(),i.getInstance().emit(a.OnStopCallback,0)},v._stop=function(){o.stopMediaStream(this._stream),this._hasUserMedia=!1},v.setFacingMode=function(e){this._facingMode=e},v.setMirror=function(e){this._mirror=e,this._videoElement&&(this._videoElement.style.transform=e?"scale(-1,1)":"")},v.takePhoto=function(e){if(!this._hasUserMedia)return null;var t=e||{},i=this.getCanvas(t);if(this.drawFrame(t),i){var n=t.format||h.format;return{data:i.toDataURL(n,this.getQualityNumber(t.quality)),width:i.width,height:i.height}}return null},v.haveVideoStream=function(){var e=this._videoElement;return e&&e.videoHeight>0&&this._hasUserMedia},v.getCanvas=function(e){var t=this._videoElement,i=e||{};if(!this.haveVideoStream())return null;if(!this._ctx){var n=t.videoWidth,a=t.videoHeight;if(!i.useVideoSourceSize){var r=n/a;a=(n=i.minScreenshotWidth||t.clientWidth)/r,i.minScreenshotHeight&&a<i.minScreenshotHeight&&(n=(a=i.minScreenshotHeight)*r)}this._canvasElement=document.createElement("canvas"),this._canvasElement.width=(null==i?void 0:i.width)||n,this._canvasElement.height=(null==i?void 0:i.height)||a,this._ctx=this._canvasElement.getContext("2d")}return this._canvasElement},v.drawFrame=function(e){var t=this._videoElement,i=e||{};if(t&&this._ctx&&this._canvasElement){var n=this._canvasElement,a=this._ctx;n.width=(null==i?void 0:i.width)||n.width,n.height=(null==i?void 0:i.height)||n.height,((null==i?void 0:i.mirrored)||this._mirror||this._facingMode===r.FRONT)&&(a.translate(n.width,0),a.scale(-1,1)),console.log("".concat(u," drawFrame ").concat(n.width,"x").concat(n.height)),a.drawImage(t,0,0,n.width,n.height),((null==i?void 0:i.mirrored)||this._mirror||this._facingMode===r.FRONT)&&(a.scale(-1,1),a.translate(-n.width,0))}},o.stopMediaStream=function(e){e&&e.getTracks().map((function(t){e.removeTrack(t),t.stop()}))},o}();export{v as ZMACameraImp};
|
package/apis/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var r="2.38.
|
|
1
|
+
var r="2.38.2";export{r as version};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a,e,n,t,o;!function(a){a.OnFrameCallback="h5.event.camera.frame",a.OnStartCallback="h5.event.camera.start",a.OnStopCallback="h5.event.camera.stop"}(a||(a={})),function(a){a.FRONT="user",a.BACK="environment"}(e||(e={})),function(a){a.WEBP="image/webp",a.PNG="image/png",a.JPEG="image/jpeg"}(n||(n={})),function(a){a.HIGH="high",a.NORMAL="normal",a.LOW="low"}(t||(t={})),function(a){a.VIDEO="video",a.AUDIO="audio"}(o||(o={}));export{a as CameraEvents,e as FacingMode,n as PhotoFormat,t as PhotoQuality,o as StreamType};
|