Browse Source

Merge pull request #15 from ForeverHYH/master

添加加载失败和组件销毁回调
hujinliang 5 years ago
parent
commit
678d21f883

+ 2 - 0
web/README.md

@@ -39,6 +39,8 @@ height | 高度
 fps | 动画播放帧数(可用:15、20、30、60)
 mute | 是否对视频静音
 precache | 是否预加载视频资源(默认关闭,即边下边播)
+onDestory | 组件销毁时回调
+onLoadError | 加载失败回调
 ext(无固定名) | 融合参数(和json配置文件中保持一致)
 
 ### 二、素材

+ 4 - 4
web/dist/gl-util.d.ts

@@ -1,4 +1,4 @@
-export declare function createShader(gl: any, type: any, source: any): any;
-export declare function createProgram(gl: any, vertexShader: any, fragmentShader: any): any;
-export declare function createTexture(gl: any, index: number, imgData?: TexImageSource): any;
-export declare function cleanWebGL(gl: any, shaders: any, program: any, textures: any, buffers: any): void;
+export declare function createShader(gl: any, type: any, source: any): any;
+export declare function createProgram(gl: any, vertexShader: any, fragmentShader: any): any;
+export declare function createTexture(gl: any, index: number, imgData?: TexImageSource): any;
+export declare function cleanWebGL(gl: any, shaders: any, program: any, textures: any, buffers: any): void;

+ 8 - 8
web/dist/index.d.ts

@@ -1,8 +1,8 @@
-import { VapConfig } from "./type";
-import WebglRenderVap from './webgl-render-vap';
-/**
- * @param options
- * @constructor
- * @return {null}
- */
-export default function (options: VapConfig): WebglRenderVap;
+import { VapConfig } from "./type";
+import WebglRenderVap from './webgl-render-vap';
+/**
+ * @param options
+ * @constructor
+ * @return {null}
+ */
+export default function (options: VapConfig): WebglRenderVap;

+ 15 - 13
web/dist/type.d.ts

@@ -1,13 +1,15 @@
-export interface VapConfig {
-    container: HTMLElement;
-    src: string;
-    config: string | {
-        [key: string]: any;
-    };
-    width: number;
-    height: number;
-    fps?: number;
-    mute?: boolean;
-    precache?: boolean;
-    [key: string]: any;
-}
+export interface VapConfig {
+    container: HTMLElement;
+    src: string;
+    config: string | {
+        [key: string]: any;
+    };
+    width: number;
+    height: number;
+    fps?: number;
+    mute?: boolean;
+    precache?: boolean;
+    onLoadError?: (e: ErrorEvent) => void;
+    onDestory?: () => void;
+    [key: string]: any;
+}

+ 32 - 32
web/dist/vap-frame-parser.d.ts

@@ -1,32 +1,32 @@
-export default class FrameParser {
-    constructor(source: any, headData: any);
-    private config;
-    private headData;
-    private frame;
-    private textureMap;
-    private canvas;
-    private ctx;
-    private srcData;
-    init(): Promise<this>;
-    initCanvas(): void;
-    loadImg(url: string): Promise<unknown>;
-    parseSrc(dataJson: any): Promise<[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>;
-    /**
-     * 下载json文件
-     * @param jsonUrl json外链
-     * @returns {Promise}
-     */
-    getConfigBySrc(jsonUrl: string): Promise<unknown>;
-    /**
-     * 文字转换图片
-     * @param {*} param0
-     */
-    makeTextImg({ textStr, w, h, color, style }: {
-        textStr: any;
-        w: any;
-        h: any;
-        color: any;
-        style: any;
-    }): ImageData;
-    getFrame(frame: any): any;
-}
+export default class FrameParser {
+    constructor(source: any, headData: any);
+    private config;
+    private headData;
+    private frame;
+    private textureMap;
+    private canvas;
+    private ctx;
+    private srcData;
+    init(): Promise<this>;
+    initCanvas(): void;
+    loadImg(url: string): Promise<unknown>;
+    parseSrc(dataJson: any): Promise<[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>;
+    /**
+     * 下载json文件
+     * @param jsonUrl json外链
+     * @returns {Promise}
+     */
+    getConfigBySrc(jsonUrl: string): Promise<unknown>;
+    /**
+     * 文字转换图片
+     * @param {*} param0
+     */
+    makeTextImg({ textStr, w, h, color, style }: {
+        textStr: any;
+        w: any;
+        h: any;
+        color: any;
+        style: any;
+    }): ImageData;
+    getFrame(frame: any): any;
+}

+ 79 - 88
web/dist/vap.js

@@ -828,7 +828,7 @@
   }
   });
 
-  var D__project_vapSource_web_node_modules__babel_runtime_regenerator = runtime_1;
+  var regenerator = runtime_1;
 
   function _classCallCheck(instance, Constructor) {
     if (!(instance instanceof Constructor)) {
@@ -972,56 +972,45 @@
 
   var possibleConstructorReturn = _possibleConstructorReturn;
 
-  var getPrototypeOf$1 = createCommonjsModule(function (module) {
-  function _getPrototypeOf(o) {
-    module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
-      return o.__proto__ || Object.getPrototypeOf(o);
-    };
-    return _getPrototypeOf(o);
-  }
-
-  module.exports = _getPrototypeOf;
-  });
-
-  /*! *****************************************************************************
-  Copyright (c) Microsoft Corporation.
-
-  Permission to use, copy, modify, and/or distribute this software for any
-  purpose with or without fee is hereby granted.
-
-  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-  REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-  AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-  INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-  PERFORMANCE OF THIS SOFTWARE.
-  ***************************************************************************** */
-
-  function __awaiter(thisArg, _arguments, P, generator) {
-      function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
-      return new (P || (P = Promise))(function (resolve, reject) {
-          function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
-          function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
-          function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
-          step((generator = generator.apply(thisArg, _arguments || [])).next());
-      });
+  /*! *****************************************************************************
+  Copyright (c) Microsoft Corporation.
+
+  Permission to use, copy, modify, and/or distribute this software for any
+  purpose with or without fee is hereby granted.
+
+  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+  REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+  AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+  INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+  PERFORMANCE OF THIS SOFTWARE.
+  ***************************************************************************** */
+
+  function __awaiter(thisArg, _arguments, P, generator) {
+      function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+      return new (P || (P = Promise))(function (resolve, reject) {
+          function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+          function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+          function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+          step((generator = generator.apply(thisArg, _arguments || [])).next());
+      });
   }
 
-  /*
-   * Tencent is pleased to support the open source community by making vap available.
-   *
-   * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
-   *
-   * Licensed under the MIT License (the "License"); you may not use this file except in
-   * compliance with the License. You may obtain a copy of the License at
-   *
-   * http://opensource.org/licenses/MIT
-   *
-   * Unless required by applicable law or agreed to in writing, software distributed under the License is
-   * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
-   * either express or implied. See the License for the specific language governing permissions and
-   * limitations under the License.
+  /*
+   * Tencent is pleased to support the open source community by making vap available.
+   *
+   * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
+   *
+   * Licensed under the MIT License (the "License"); you may not use this file except in
+   * compliance with the License. You may obtain a copy of the License at
+   *
+   * http://opensource.org/licenses/MIT
+   *
+   * Unless required by applicable law or agreed to in writing, software distributed under the License is
+   * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+   * either express or implied. See the License for the specific language governing permissions and
+   * limitations under the License.
    */
 
   var FrameParser = /*#__PURE__*/function () {
@@ -1037,8 +1026,8 @@
     createClass(FrameParser, [{
       key: "init",
       value: function init() {
-        return __awaiter(this, void 0, void 0, /*#__PURE__*/D__project_vapSource_web_node_modules__babel_runtime_regenerator.mark(function _callee() {
-          return D__project_vapSource_web_node_modules__babel_runtime_regenerator.wrap(function _callee$(_context) {
+        return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
+          return regenerator.wrap(function _callee$(_context) {
             while (1) {
               switch (_context.prev = _context.next) {
                 case 0:
@@ -1109,10 +1098,10 @@
 
         var src = this.srcData = {};
         return Promise.all((dataJson.src || []).map(function (item) {
-          return __awaiter(_this, void 0, void 0, /*#__PURE__*/D__project_vapSource_web_node_modules__babel_runtime_regenerator.mark(function _callee2() {
+          return __awaiter(_this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
             var _this2 = this;
 
-            return D__project_vapSource_web_node_modules__babel_runtime_regenerator.wrap(function _callee2$(_context2) {
+            return regenerator.wrap(function _callee2$(_context2) {
               while (1) {
                 switch (_context2.prev = _context2.next) {
                   case 0:
@@ -1176,10 +1165,10 @@
           }));
         }));
       }
-      /**
-       * 下载json文件
-       * @param jsonUrl json外链
-       * @returns {Promise}
+      /**
+       * 下载json文件
+       * @param jsonUrl json外链
+       * @returns {Promise}
        */
 
     }, {
@@ -1202,9 +1191,9 @@
           xhr.send();
         });
       }
-      /**
-       * 文字转换图片
-       * @param {*} param0
+      /**
+       * 文字转换图片
+       * @param {*} param0
        */
 
     }, {
@@ -1247,20 +1236,20 @@
     return FrameParser;
   }();
 
-  /*
-   * Tencent is pleased to support the open source community by making vap available.
-   *
-   * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
-   *
-   * Licensed under the MIT License (the "License"); you may not use this file except in
-   * compliance with the License. You may obtain a copy of the License at
-   *
-   * http://opensource.org/licenses/MIT
-   *
-   * Unless required by applicable law or agreed to in writing, software distributed under the License is
-   * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
-   * either express or implied. See the License for the specific language governing permissions and
-   * limitations under the License.
+  /*
+   * Tencent is pleased to support the open source community by making vap available.
+   *
+   * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
+   *
+   * Licensed under the MIT License (the "License"); you may not use this file except in
+   * compliance with the License. You may obtain a copy of the License at
+   *
+   * http://opensource.org/licenses/MIT
+   *
+   * Unless required by applicable law or agreed to in writing, software distributed under the License is
+   * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+   * either express or implied. See the License for the specific language governing permissions and
+   * limitations under the License.
    */
   function createShader(gl, type, source) {
     var shader = gl.createShader(type);
@@ -1496,6 +1485,7 @@
         }
 
         this.cancelRequestAnimation();
+        this.options.onDestory && this.options.onDestory();
       }
     }, {
       key: "clear",
@@ -1532,13 +1522,14 @@
       value: function onerror(err) {
         console.error('[Alpha video]: play error: ', err);
         this.destroy();
+        this.options.onLoadError && this.options.onLoadError(err);
       }
     }]);
 
     return VapVideo;
   }();
 
-  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = getPrototypeOf$1(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = getPrototypeOf$1(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return possibleConstructorReturn(this, result); }; }
+  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return possibleConstructorReturn(this, result); }; }
 
   function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
   var clearTimer = null;
@@ -1581,8 +1572,8 @@
     createClass(WebglRenderVap, [{
       key: "init",
       value: function init() {
-        return __awaiter(this, void 0, void 0, /*#__PURE__*/D__project_vapSource_web_node_modules__babel_runtime_regenerator.mark(function _callee() {
-          return D__project_vapSource_web_node_modules__babel_runtime_regenerator.wrap(function _callee$(_context) {
+        return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
+          return regenerator.wrap(function _callee$(_context) {
             while (1) {
               switch (_context.prev = _context.next) {
                 case 0:
@@ -1679,8 +1670,8 @@
           return gl;
         }
       }
-      /**
-       * 顶点着色器
+      /**
+       * 顶点着色器
        */
 
     }, {
@@ -1689,8 +1680,8 @@
         var gl = this.instance.gl;
         return createShader(gl, gl.VERTEX_SHADER, "attribute vec2 a_position; // \u63A5\u53D7\u9876\u70B9\u5750\u6807\n             attribute vec2 a_texCoord; // \u63A5\u53D7\u7EB9\u7406\u5750\u6807\n             attribute vec2 a_alpha_texCoord; // \u63A5\u53D7\u7EB9\u7406\u5750\u6807\n             varying vec2 v_alpha_texCoord; // \u63A5\u53D7\u7EB9\u7406\u5750\u6807\n             varying   vec2 v_texcoord; // \u4F20\u9012\u7EB9\u7406\u5750\u6807\u7ED9\u7247\u5143\u7740\u8272\u5668\n             void main(void){\n                gl_Position = vec4(a_position, 0.0, 1.0); // \u8BBE\u7F6E\u5750\u6807\n                v_texcoord = a_texCoord; // \u8BBE\u7F6E\u7EB9\u7406\u5750\u6807\n                v_alpha_texCoord = a_alpha_texCoord; // \u8BBE\u7F6E\u7EB9\u7406\u5750\u6807\n             }");
       }
-      /**
-       * 片元着色器
+      /**
+       * 片元着色器
        */
 
     }, {
@@ -1808,7 +1799,7 @@
         var gl = this.instance.gl;
 
         if (!gl) {
-          get(getPrototypeOf$1(WebglRenderVap.prototype), "drawFrame", this).call(this);
+          get(getPrototypeOf(WebglRenderVap.prototype), "drawFrame", this).call(this);
 
           return;
         }
@@ -1856,7 +1847,7 @@
 
         gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
 
-        get(getPrototypeOf$1(WebglRenderVap.prototype), "drawFrame", this).call(this);
+        get(getPrototypeOf(WebglRenderVap.prototype), "drawFrame", this).call(this);
       }
     }, {
       key: "destroy",
@@ -1876,7 +1867,7 @@
         } // glUtil.cleanWebGL(gl, this.shaders, this.program, this.textures, this.buffers)
 
 
-        get(getPrototypeOf$1(WebglRenderVap.prototype), "destroy", this).call(this);
+        get(getPrototypeOf(WebglRenderVap.prototype), "destroy", this).call(this);
 
         this.clearMemoryCache();
       }
@@ -1897,10 +1888,10 @@
   }(VapVideo);
 
   var isCanWebGL;
-  /**
-   * @param options
-   * @constructor
-   * @return {null}
+  /**
+   * @param options
+   * @constructor
+   * @return {null}
    */
 
   function index (options) {

File diff suppressed because it is too large
+ 0 - 0
web/dist/vap.min.js


+ 27 - 27
web/dist/video.d.ts

@@ -1,27 +1,27 @@
-/// <reference types="node" />
-import { VapConfig } from "./type";
-export default class VapVideo {
-    constructor(options: any);
-    options: VapConfig;
-    private fps;
-    requestAnim: Function;
-    container: HTMLElement;
-    video: HTMLVideoElement;
-    private events;
-    private _drawFrame;
-    private animId;
-    private firstPlaying;
-    precacheSource(source: any): Promise<string>;
-    initVideo(): void;
-    drawFrame(): void;
-    play(): void;
-    requestAnimFunc(): ((cb: any) => number) | ((cb: any) => NodeJS.Timeout);
-    cancelRequestAnimation(): void;
-    destroy(): void;
-    clear(): void;
-    on(event: any, callback: EventListenerObject): this;
-    onplaying(): void;
-    onpause(): void;
-    onended(): void;
-    onerror(err: any): void;
-}
+/// <reference types="node" />
+import { VapConfig } from "./type";
+export default class VapVideo {
+    constructor(options: any);
+    options: VapConfig;
+    private fps;
+    requestAnim: Function;
+    container: HTMLElement;
+    video: HTMLVideoElement;
+    private events;
+    private _drawFrame;
+    private animId;
+    private firstPlaying;
+    precacheSource(source: any): Promise<string>;
+    initVideo(): void;
+    drawFrame(): void;
+    play(): void;
+    requestAnimFunc(): ((cb: any) => number) | ((cb: any) => NodeJS.Timeout);
+    cancelRequestAnimation(): void;
+    destroy(): void;
+    clear(): void;
+    on(event: any, callback: EventListenerObject): this;
+    onplaying(): void;
+    onpause(): void;
+    onended(): void;
+    onerror(err: any): void;
+}

+ 34 - 34
web/dist/webgl-render-vap.d.ts

@@ -1,34 +1,34 @@
-import { VapConfig } from "./type";
-import VapVideo from './video';
-export default class WebglRenderVap extends VapVideo {
-    constructor(options: VapConfig);
-    private insType;
-    private textures;
-    private buffers;
-    private shaders;
-    private vapFrameParser;
-    private resources;
-    private instance;
-    private program;
-    private videoTexture;
-    private aPosition;
-    private aTexCoord;
-    private aAlphaTexCoord;
-    private _imagePos;
-    init(): Promise<void>;
-    setCanvas(): void;
-    initWebGL(): any;
-    /**
-     * 顶点着色器
-     */
-    initVertexShader(): any;
-    /**
-     * 片元着色器
-     */
-    initFragmentShader(): any;
-    initTexture(): void;
-    initVideoTexture(): void;
-    drawFrame(): void;
-    destroy(): void;
-    clearMemoryCache(): void;
-}
+import { VapConfig } from "./type";
+import VapVideo from './video';
+export default class WebglRenderVap extends VapVideo {
+    constructor(options: VapConfig);
+    private insType;
+    private textures;
+    private buffers;
+    private shaders;
+    private vapFrameParser;
+    private resources;
+    private instance;
+    private program;
+    private videoTexture;
+    private aPosition;
+    private aTexCoord;
+    private aAlphaTexCoord;
+    private _imagePos;
+    init(): Promise<void>;
+    setCanvas(): void;
+    initWebGL(): any;
+    /**
+     * 顶点着色器
+     */
+    initVertexShader(): any;
+    /**
+     * 片元着色器
+     */
+    initFragmentShader(): any;
+    initTexture(): void;
+    initVideoTexture(): void;
+    drawFrame(): void;
+    destroy(): void;
+    clearMemoryCache(): void;
+}

+ 2 - 0
web/src/type.ts

@@ -7,5 +7,7 @@ export interface VapConfig {
   fps?: number;
   mute?: boolean;
   precache?: boolean;
+  onLoadError?: (e: ErrorEvent) => void;
+  onDestory?: () => void;
   [key:string]:any;
 }

+ 2 - 0
web/src/video.ts

@@ -193,6 +193,7 @@ export default class VapVideo {
       this.video = null
     }
     this.cancelRequestAnimation();
+    this.options.onDestory && this.options.onDestory();
   }
 
   clear() {
@@ -223,5 +224,6 @@ export default class VapVideo {
   onerror(err) {
     console.error('[Alpha video]: play error: ', err);
     this.destroy();
+    this.options.onLoadError && this.options.onLoadError(err);
   }
 }

Some files were not shown because too many files changed in this diff