tim-upload-plugin
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).TIMUploadPlugin=t()}(this,(function(){function e(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function t(t){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?e(Object(n),!0).forEach((function(e){s(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function a(e,t,o){return t&&r(e.prototype,t),o&&r(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function i(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},a=Object.keys(e);for(n=0;n<a.length;n++)o=a[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)o=a[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}var u="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting),f="undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting),c="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),d="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),p="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),y="undefined"!=typeof uni&&"undefined"==typeof window&&"function"==typeof uni.requireNativePlugin,h=y&&"ios"===uni.getDeviceInfo().platform.toLocaleLowerCase(),g=(y&&uni.getDeviceInfo().platform.toLocaleLowerCase(),l||f||c||d||p||y),m=void 0!==u&&(void 0!==u.nativeModuleProxy||void 0!==u.ReactNative),v=f?qq:c?tt:d?swan:p?my:l?wx:y?uni:{},b=function(e){if("object"!==o(e)||null===e)return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;for(var n=t;null!==Object.getPrototypeOf(n);)n=Object.getPrototypeOf(n);return t===n};function w(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(b(e)){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}return!1}var O=function(){function e(){n(this,e),this._n="WebRequest"}return a(e,[{key:"request",value:function(e,o){var n=this,r="".concat(this._n,".request"),a=e.downloadUrl||"",s=(e.method||"PUT").toUpperCase(),i=e.url;if(console.log("%c tim-upload-plugin %c","background:#0abf5b; padding:1px; border-radius:3px; color: #fff","background:transparent","".concat(r," URL:").concat(i)),e.qs){var u=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"&",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"=";return w(e)?"":b(e)?Object.keys(e).map((function(n){var r=encodeURIComponent(n)+o;return Array.isArray(e[n])?e[n].map((function(e){return r+encodeURIComponent(e)})).join(t):r+encodeURIComponent(e[n])})).filter(Boolean).join(t):void 0}(e.qs);u&&(i+="".concat(-1===i.indexOf("?")?"?":"&").concat(u))}var l=new XMLHttpRequest;l.open(s,i,!0),l.responseType=e.dataType||"text";var f=e.headers||{};if(e.uploadByIP&&(f=t(t({},f),{},{host:e.uploadIP})),!w(f))for(var c in f)f.hasOwnProperty(c)&&"content-length"!==c.toLowerCase()&&"user-agent"!==c.toLowerCase()&&"origin"!==c.toLowerCase()&&"host"!==c.toLowerCase()&&l.setRequestHeader(c,f[c]);return l.onload=function(){if(200===l.status)o(null,n._xhrRes(l,n._xhrBody(l,a,e.uploadByIP&&e.uploadIP),f));else{if(e.uploadIP&&-1===e.url.indexOf(e.uploadIP))return e.url=function(e,t){return e.replace(/^http(s)?:\/\/(.*?)\//,"https://".concat(t,"/"))}(e.url,e.uploadIP),e.uploadByIP=!0,n.request(e,o);var t={code:l.status,message:JSON.stringify(l.responseText)};o(t,n._xhrRes(l,n._xhrBody(l,a,e.uploadByIP&&e.uploadIP),f))}},l.onerror=function(t){var r=n._xhrBody(l,a,e.uploadByIP&&e.uploadIP),s={code:l.status,message:JSON.stringify(l.responseText)};r||l.statusText||0!==l.status||(t.message="CORS blocked or network error"),o(s,n._xhrRes(l,r)),s=null},e.onProgress&&l.upload&&(l.upload.onprogress=function(t){var o=t.total,n=t.loaded,r=Math.floor(100*n/o);e.onProgress({total:o,loaded:n,percent:(r>=100?100:r)/100})}),l.send(e.resources),l}},{key:"_xhrRes",value:function(e,t){var o={};return e.getAllResponseHeaders().trim().split("\n").forEach((function(e){if(e){var t=e.indexOf(":"),n=e.substr(0,t).trim().toLowerCase(),r=e.substr(t+1).trim();o[n]=r}})),{statusCode:e.status,statusMessage:e.statusText,headers:o,data:t}}},{key:"_xhrBody",value:function(e,t,o){return 200===e.status&&t?{location:t,uploadIP:o}:{response:e.responseText,uploadIP:o}}}]),e}(),S=["unknown","image","video","audio","log"],P=["name"],I=function(){function e(){n(this,e)}return a(e,[{key:"request",value:function(e,o){var n=this,r=e.resources,a=void 0===r?"":r,s=e.headers,u=void 0===s?{}:s,l=e.url,f=e.downloadUrl,c=void 0===f?"":f,d=l,y=null,g=c.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/),m=decodeURIComponent(g[3]),b=m.indexOf("?")>-1?m.split("?")[0]:m,w={key:e.fileKey?e.fileKey:b,success_action_status:200,"Content-Type":""},O={};if(h){var I=l.split("?sign=");if(I.length>1){var C=I[1];d="".concat(I[0],"?sign=").concat(encodeURIComponent("".concat(C))),O.sign=decodeURIComponent(C),O.signature=decodeURIComponent(C)}}var k={url:d,header:u,name:"file",filePath:a,formData:t(t({},w),O),timeout:e.timeout||3e5};if(p){var x=k;x.name;k=t(t({},i(x,P)),{},{fileName:"file",fileType:S[e.fileType]})}return(y=v.uploadFile(t(t({},k),{},{success:function(e){n._handleResponse({response:e,downloadUrl:c,callback:o})},fail:function(e){n._handleResponse({response:e,downloadUrl:c,callback:o})}}))).onProgressUpdate&&y.onProgressUpdate((function(t){e.onProgress&&e.onProgress({total:t.totalBytesExpectedToSend,loaded:t.totalBytesSent,percent:Math.floor(t.progress)/100})})),y}},{key:"_handleResponse",value:function(e){var o=e.downloadUrl,n=e.response,r=e.callback,a=n.header,s={};if(a)for(var i in a)a.hasOwnProperty(i)&&(s[i.toLowerCase()]=a[i]);var u=+n.statusCode;200===u?r(null,{statusCode:u,headers:s,data:t(t({},n.data),{},{location:o})}):r({code:u,message:JSON.stringify(n.data)},{statusCode:u,headers:s,data:void 0})}}]),e}(),C=function(){function e(){n(this,e)}return a(e,[{key:"request",value:function(e,t){var o=this,n=e.resources,r=void 0===n?"":n,a=e.fileKey,s=void 0===a?"":a,i=e.url,u=e.downloadUrl,l=void 0===u?"":u,f=new FormData;f.append("key",s),f.append("success_action_status",200),f.append("file",{uri:r,type:"application/octet-stream",name:"uploaded_file"}),fetch(i,{method:"POST",headers:{"Content-Type":"multipart/form-data"},body:f}).then((function(e){o._handleResponse({response:e,downloadUrl:l,callback:t})})).catch((function(e){o._handleResponse({response:e,downloadUrl:l,callback:t})}))}},{key:"_handleResponse",value:function(e){var t=e.downloadUrl,o=e.response,n=e.callback,r=o.headers,a=o.status,s=r&&r.map||{};200===a?n(null,{statusCode:200,headers:s,data:{location:t}}):n({code:a,message:JSON.stringify(o)},{statusCode:a,headers:s,data:void 0})}}]),e}();return function(){function e(){n(this,e),this.retry=1,this.tryCount=0,this.systemClockOffset=0,this.httpRequest=g?new I:m?new C:new O,console.log("TIMUploadPlugin.VERSION: ".concat("1.4.1"))}return a(e,[{key:"uploadFile",value:function(e,t){var o=this;return this.httpRequest.request(e,(function(n,r){n&&o.tryCount<o.retry&&o.allowRetry(n)?(o.tryCount++,o.uploadFile(e,t)):(o.tryCount=0,t(n,r))}))}},{key:"allowRetry",value:function(e){var t=!1,o=!1;if(e){var n=e.headers&&(e.headers.date||e.headers.Date)||e.error&&e.error.ServerTime;try{var r=e.error&&e.error.Code,a=e.error&&e.error.Message;("RequestTimeTooSkewed"===r||"AccessDenied"===r&&"Request has expired"===a)&&(o=!0)}catch(u){}if(o&&n){var s=Date.now(),i=Date.parse(n);Math.abs(s+this.systemClockOffset-i)>=3e4&&(this.systemClockOffset=i-s,t=!0)}else 5===Math.floor(e.statusCode/100)&&(t=!0)}return t}}],[{key:"getVersion",value:function(){return"1.4.1"}}]),e}()})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).TIMUploadPlugin=t()}(this,(function(){function e(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function t(t){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?e(Object(n),!0).forEach((function(e){s(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function a(e,t,o){return t&&r(e.prototype,t),o&&r(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function i(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},a=Object.keys(e);for(n=0;n<a.length;n++)o=a[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)o=a[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}var u="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting),f="undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting),c="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),d="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),p="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),y="undefined"!=typeof uni&&"undefined"==typeof window&&"function"==typeof uni.requireNativePlugin,h=y&&"ios"===uni.getDeviceInfo().platform.toLocaleLowerCase(),g=(y&&uni.getDeviceInfo().platform.toLocaleLowerCase(),l||f||c||d||p||y),m=void 0!==u&&(void 0!==u.nativeModuleProxy||void 0!==u.ReactNative),v=f?qq:c?tt:d?swan:p?my:l?wx:y?uni:{},b=function(e){if("object"!==o(e)||null===e)return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;for(var n=t;null!==Object.getPrototypeOf(n);)n=Object.getPrototypeOf(n);return t===n};function w(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(b(e)){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}return!1}var O=function(){function e(){n(this,e),this._n="WebRequest"}return a(e,[{key:"request",value:function(e,o){var n=this,r="".concat(this._n,".request"),a=e.downloadUrl||"",s=(e.method||"PUT").toUpperCase(),i=e.url;if(console.log("%c tim-upload-plugin %c","background:#0abf5b; padding:1px; border-radius:3px; color: #fff","background:transparent","".concat(r," URL:").concat(i)),e.qs){var u=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"&",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"=";return w(e)?"":b(e)?Object.keys(e).map((function(n){var r=encodeURIComponent(n)+o;return Array.isArray(e[n])?e[n].map((function(e){return r+encodeURIComponent(e)})).join(t):r+encodeURIComponent(e[n])})).filter(Boolean).join(t):void 0}(e.qs);u&&(i+="".concat(-1===i.indexOf("?")?"?":"&").concat(u))}var l=new XMLHttpRequest;l.open(s,i,!0),l.responseType=e.dataType||"text";var f=e.headers||{};if(e.uploadByIP&&(f=t(t({},f),{},{host:e.uploadIP})),!w(f))for(var c in f)f.hasOwnProperty(c)&&"content-length"!==c.toLowerCase()&&"user-agent"!==c.toLowerCase()&&"origin"!==c.toLowerCase()&&"host"!==c.toLowerCase()&&l.setRequestHeader(c,f[c]);return l.onload=function(){if(200===l.status)o(null,n._xhrRes(l,n._xhrBody(l,a,e.uploadByIP&&e.uploadIP),f));else{if(e.uploadIP&&-1===e.url.indexOf(e.uploadIP))return e.url=function(e,t){return e.replace(/^http(s)?:\/\/(.*?)\//,"https://".concat(t,"/"))}(e.url,e.uploadIP),e.uploadByIP=!0,n.request(e,o);var t={code:l.status,message:JSON.stringify(l.responseText)};o(t,n._xhrRes(l,n._xhrBody(l,a,e.uploadByIP&&e.uploadIP),f))}},l.onerror=function(t){var r=n._xhrBody(l,a,e.uploadByIP&&e.uploadIP),s={code:l.status,message:JSON.stringify(l.responseText)};r||l.statusText||0!==l.status||(t.message="CORS blocked or network error"),o(s,n._xhrRes(l,r)),s=null},e.onProgress&&l.upload&&(l.upload.onprogress=function(t){var o=t.total,n=t.loaded,r=Math.floor(100*n/o);e.onProgress({total:o,loaded:n,percent:(r>=100?100:r)/100})}),l.send(e.resources),l}},{key:"_xhrRes",value:function(e,t){var o={};return e.getAllResponseHeaders().trim().split("\n").forEach((function(e){if(e){var t=e.indexOf(":"),n=e.substr(0,t).trim().toLowerCase(),r=e.substr(t+1).trim();o[n]=r}})),{statusCode:e.status,statusMessage:e.statusText,headers:o,data:t}}},{key:"_xhrBody",value:function(e,t,o){return 200===e.status&&t?{location:t,uploadIP:o}:{response:e.responseText,uploadIP:o}}}]),e}(),S=["unknown","image","video","audio","log"],P=["name"],I=function(){function e(){n(this,e)}return a(e,[{key:"request",value:function(e,o){var n=this,r=e.resources,a=void 0===r?"":r,s=e.headers,u=void 0===s?{}:s,l=e.url,f=e.downloadUrl,c=void 0===f?"":f,d=l,y=null,g=c.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/),m=decodeURIComponent(g[3]),b=m.indexOf("?")>-1?m.split("?")[0]:m,w={key:e.fileKey?e.fileKey:b,success_action_status:200,"Content-Type":""},O={};if(h){var I=l.split("?sign=");if(I.length>1){var C=I[1];d="".concat(I[0],"?sign=").concat(encodeURIComponent("".concat(C))),O.sign=decodeURIComponent(C),O.signature=decodeURIComponent(C)}}var k={url:d,header:u,name:"file",filePath:a,formData:t(t({},w),O),timeout:e.timeout||3e5};if(p){var x=k;x.name;k=t(t({},i(x,P)),{},{fileName:"file",fileType:S[e.fileType]})}return(y=v.uploadFile(t(t({},k),{},{success:function(e){n._handleResponse({response:e,downloadUrl:c,callback:o})},fail:function(e){n._handleResponse({response:e,downloadUrl:c,callback:o})}}))).onProgressUpdate&&y.onProgressUpdate((function(t){e.onProgress&&e.onProgress({total:t.totalBytesExpectedToSend,loaded:t.totalBytesSent,percent:Math.floor(t.progress)/100})})),y}},{key:"_handleResponse",value:function(e){var o=e.downloadUrl,n=e.response,r=e.callback,a=n.header,s={};if(a)for(var i in a)a.hasOwnProperty(i)&&(s[i.toLowerCase()]=a[i]);var u=+n.statusCode;200===u?r(null,{statusCode:u,headers:s,data:t(t({},n.data),{},{location:o})}):r({code:u,message:JSON.stringify(n.data)},{statusCode:u,headers:s,data:void 0})}}]),e}(),C=function(){function e(){n(this,e)}return a(e,[{key:"request",value:function(e,t){var o=this,n=e.resources,r=void 0===n?"":n,a=e.fileKey,s=void 0===a?"":a,i=e.url,u=e.downloadUrl,l=void 0===u?"":u,f=new FormData;f.append("key",s),f.append("success_action_status",200),f.append("file",{uri:r,type:"application/octet-stream",name:"uploaded_file"}),fetch(i,{method:"POST",headers:{"Content-Type":"multipart/form-data"},body:f}).then((function(e){o._handleResponse({response:e,downloadUrl:l,callback:t})})).catch((function(e){o._handleResponse({response:e,downloadUrl:l,callback:t})}))}},{key:"_handleResponse",value:function(e){var t=e.downloadUrl,o=e.response,n=e.callback,r=o.headers,a=o.status,s=r&&r.map||{};200===a?n(null,{statusCode:200,headers:s,data:{location:t}}):n({code:a,message:JSON.stringify(o)},{statusCode:a,headers:s,data:void 0})}}]),e}();return function(){function e(){n(this,e),this.retry=1,this.tryCount=0,this.systemClockOffset=0,this.httpRequest=g?new I:m?new C:new O,console.log("TIMUploadPlugin.VERSION: ".concat("1.4.2"))}return a(e,[{key:"uploadFile",value:function(e,t){var o=this;return this.httpRequest.request(e,(function(n,r){n&&o.tryCount<o.retry&&o.allowRetry(n)?(o.tryCount++,o.uploadFile(e,t)):(o.tryCount=0,t(n,r))}))}},{key:"allowRetry",value:function(e){var t=!1,o=!1;if(e){var n=e.headers&&(e.headers.date||e.headers.Date)||e.error&&e.error.ServerTime;try{var r=e.error&&e.error.Code,a=e.error&&e.error.Message;("RequestTimeTooSkewed"===r||"AccessDenied"===r&&"Request has expired"===a)&&(o=!0)}catch(u){}if(o&&n){var s=Date.now(),i=Date.parse(n);Math.abs(s+this.systemClockOffset-i)>=3e4&&(this.systemClockOffset=i-s,t=!0)}else 5===Math.floor(e.statusCode/100)&&(t=!0)}return t}}],[{key:"getVersion",value:function(){return"1.4.2"}}]),e}()})); |
{ | ||
"name": "tim-upload-plugin", | ||
"version": "1.4.1", | ||
"description": "Tencent Cloud Upload To COS SDK for IM", | ||
"version": "1.4.2", | ||
"description": "Official Upload Plugin for Tencent Cloud Chat", | ||
"main": "index.js", | ||
"keywords": ["腾讯云IM", "即时通讯", "通信", "COS"], | ||
"keywords": ["Chat", "trtc", "ReactNative", "IM", "real-time chat"], | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -1,80 +0,42 @@ | ||
### 简介 | ||
### Introduction | ||
腾讯云即时通信 IM 上传插件,用来上传图片、语音、视频、文件等类型的消息,支持 Web 和微信、QQ、百度、头条、支付宝小程序平台。 | ||
Tencent Cloud Chat provides globally interconnected chat APIs, multi-platform SDKs, and UIKit components to help you quickly bring messaging capabilities such as one-to-one chat, group chat, chat rooms, and system notifications to your applications and websites. | ||
### 优势 | ||
Tencent Cloud Chat upload plugin is used to upload messages of types such as images, voice, video, and files. It supports platforms including Web, ReactNative, WeChat, QQ, Baidu, Toutiao, and Alipay Mini Programs. | ||
使用 tim-upload-plugin 有以下4个优势: | ||
### Advantages | ||
- 应用数据更安全 | ||
- 上传文件速度较 cos-js-sdk 和 cos-wx-sdk 快10%~50% | ||
- 同时支持 Web 和微信、QQ、百度、头条、支付宝小程序平台 | ||
- 体积非常小,仅26KB,对小程序应用更友好 | ||
Using tim-upload-plugin has the following 2 advantages: | ||
### 注意事项 | ||
- More secure application data | ||
- Very small size, only 9KB, which is more friendly to Mini Program applications | ||
使用 tim-upload-plugin 需要注意以下2点: | ||
### How to Use | ||
1、使用前请将 [tim-js-sdk](https://www.npmjs.com/package/tim-js-sdk) 或 [tim-wx-sdk](https://www.npmjs.com/package/tim-wx-sdk) 升级到v2.9.2或更高版本 | ||
2、小程序端使用 tim-upload-plugin,请在小程序管理后台将以下域名添加到 uploadFile 合法域名: | ||
Use npm to install the corresponding Chat SDK dependencies in your project. | ||
```javascript | ||
npm install @tencentcloud/chat --save | ||
npm install tim-upload-plugin --save | ||
``` | ||
- `https://cos.ap-shanghai.myqcloud.com` | ||
- `https://cos.ap-shanghai.tencentcos.cn` | ||
- `https://cos.ap-guangzhou.myqcloud.com` | ||
将以下域名添加到 downloadFile 合法域名: | ||
- `https://cos.ap-shanghai.myqcloud.com` | ||
- `https://cos.ap-shanghai.tencentcos.cn` | ||
- `https://cos.ap-guangzhou.myqcloud.com` | ||
### 使用方式 | ||
#### npm 引入 | ||
```javascript | ||
// 下载依赖 | ||
npm i tim-upload-plugin --save | ||
// tim-js-sdk 的版本请使用 v2.9.2 或更高版本才能集成 tim-upload-plugin | ||
npm i tim-js-sdk@latest --save | ||
// 在项目脚本里引入模块,并初始化 | ||
import TIM from 'tim-js-sdk'; | ||
import TencentCloudChat from '@tencentcloud/chat'; | ||
import TIMUploadPlugin from 'tim-upload-plugin'; | ||
let options = { | ||
SDKAppID: 0 // 接入时需要将0替换为您的云通信应用的 SDKAppID,类型为 Number | ||
SDKAppID: 0 // Replace 0 with the SDKAppID of your Chat application when connecting. | ||
}; | ||
// 创建 SDK 实例,`TIM.create()`方法对于同一个 `SDKAppID` 只会返回同一份实例 | ||
let tim = TIM.create(options); // SDK 实例通常用 tim 表示 | ||
// Create an SDK instance. | ||
// The `TencentCloudChat.create()` method returns the same instance for the same `SDKAppID`. | ||
// The SDK instance is usually represented by chat. | ||
let chat = TencentCloudChat.create(options); | ||
// 设置 SDK 日志输出级别,详细分级请参见 setLogLevel 接口的说明 | ||
tim.setLogLevel(0); // 普通级别,日志量较多,接入时建议使用 | ||
// tim.setLogLevel(1); // release级别,SDK 输出关键信息,生产环境时建议使用 | ||
// Set the SDK log level. | ||
// 0: Common level. You are advised to use this level during access as it covers more logs. | ||
// 1: Release level. You are advised to use this level for key information in a production environment. | ||
chat.setLogLevel(0); | ||
// chat.setLogLevel(1); | ||
// 注册 COS SDK 插件 | ||
tim.registerPlugin({'tim-upload-plugin': TIMUploadPlugin}); | ||
// Register the Tencent Cloud Chat upload plugin. | ||
chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin}); | ||
``` | ||
#### script 标签引入 | ||
```javascript | ||
<!-- tim-js.js 和 tim-upload-plugin.js 可以从 https://github.com/TencentCloud/TIMSDK/tree/master/Web/IMSDK 获取 --> | ||
<script src='./tim-js.js'></script> | ||
<script src='./tim-upload-plugin.js'></script> | ||
<script> | ||
let options = { | ||
SDKAppID: 0 // 接入时需要将0替换为您的云通信应用的 SDKAppID,类型为 Number | ||
}; | ||
// 创建 SDK 实例,`TIM.create()`方法对于同一个 `SDKAppID` 只会返回同一份实例 | ||
let tim = TIM.create(options); | ||
// 设置 SDK 日志输出级别,详细分级请参见 setLogLevel 接口的说明 | ||
tim.setLogLevel(0); // 普通级别,日志量较多,接入时建议使用 | ||
// tim.setLogLevel(1); // release级别,SDK 输出关键信息,生产环境时建议使用 | ||
// 注册 COS SDK 插件 | ||
tim.registerPlugin({'tim-upload-plugin': TIMUploadPlugin}); | ||
// 接下来可以通过 tim 进行事件绑定和构建 IM 应用 | ||
</script> | ||
``` |
11348
43