TV.js 2.5 KB

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