video.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Video = void 0;
  6. var _utils = require("../utils");
  7. /**
  8. * Copyright (c) Microsoft Corporation.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. class Video {
  23. constructor(page, connection) {
  24. this._artifact = null;
  25. this._artifactReadyPromise = new _utils.ManualPromise();
  26. this._isRemote = false;
  27. this._isRemote = connection.isRemote();
  28. this._artifact = page._closedOrCrashedScope.safeRace(this._artifactReadyPromise);
  29. }
  30. _artifactReady(artifact) {
  31. this._artifactReadyPromise.resolve(artifact);
  32. }
  33. async path() {
  34. if (this._isRemote) throw new Error(`Path is not available when connecting remotely. Use saveAs() to save a local copy.`);
  35. const artifact = await this._artifact;
  36. if (!artifact) throw new Error('Page did not produce any video frames');
  37. return artifact._initializer.absolutePath;
  38. }
  39. async saveAs(path) {
  40. const artifact = await this._artifact;
  41. if (!artifact) throw new Error('Page did not produce any video frames');
  42. return await artifact.saveAs(path);
  43. }
  44. async delete() {
  45. const artifact = await this._artifact;
  46. if (artifact) await artifact.delete();
  47. }
  48. }
  49. exports.Video = Video;