TV.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import XDecalManager from "./XDecalManager.js"
  2. export default class TV extends XTelevision {
  3. constructor(e, t, r, n) {
  4. super(r.scene, t, r.sceneManager, n);
  5. E(this, "decal");
  6. E(this, "id");
  7. E(this, "imageUrl");
  8. E(this, "mode", "video");
  9. E(this, "room");
  10. E(this, "setVideo", (e,t=!1,r=!0)=>super.setVideo(e, t, r).then(()=>this));
  11. this.id = e,
  12. this.room = r,
  13. this.decal = new XDecalManager(r.sceneManager)
  14. }
  15. show() {
  16. this.mode === "video" ? this.toggle(!0) : this.mode === "poster" && this.showPoster()
  17. }
  18. hide() {
  19. this.mode === "video" ? this.toggle(!1) : this.mode === "poster" && this.hidePoster()
  20. }
  21. showVideo() {
  22. this.mode = "video",
  23. this.toggle(!0)
  24. }
  25. hideVideo() {
  26. this.toggle(!1)
  27. }
  28. showPoster() {
  29. const e = this.imageUrl;
  30. if (!e)
  31. return Promise.reject("set poster url before show it");
  32. if (!this.decal)
  33. return Promise.reject("decal was not found");
  34. const t = this.id;
  35. return this.decal.addDecal({
  36. id: t,
  37. meshPath: this.meshPath
  38. }).then(()=>{
  39. var r;
  40. this.mode = "poster",
  41. (r = this.decal) == null || r.setDecalTexture({
  42. id: t,
  43. buffer: e
  44. }).then(()=>{
  45. var n;
  46. (n = this.decal) == null || n.toggle(t, !0)
  47. }
  48. )
  49. }
  50. )
  51. }
  52. setPoster(e) {
  53. return this.imageUrl = e,
  54. this.showPoster()
  55. }
  56. hidePoster() {
  57. return this.decal ? this.decal.toggle(this.id, !1) : Promise.reject("decal was not found")
  58. }
  59. setUrl(e) {
  60. const {url: t, loop: r, muted: n} = e || {};
  61. return t ? super.setUrl({
  62. url: t,
  63. bLoop: r,
  64. bMuted: n
  65. }).then(()=>(this.videoElement && (this.videoElement.crossOrigin = "anonymous",
  66. this.videoElement.playsInline = !0,
  67. this.videoElement.load()),
  68. this.mode = "video",
  69. this)) : Promise.reject("tv url is required")
  70. }
  71. mirrorFrom(e) {
  72. const t = e.getVideoMat();
  73. return this.setSameVideo(t).then(()=>{
  74. this.toggle(!0)
  75. }
  76. )
  77. }
  78. clean() {
  79. var e;
  80. this.cleanTv(!1, !0),
  81. (e = this.decal) == null || e.deleteDecal(this.id)
  82. }
  83. }