main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import Xverse from "./Xverse.js"
  2. import Codes from "./enum/Codes.js"
  3. import Tip from "./Tip.js";
  4. const xverse = new Xverse({
  5. env: "DEV",
  6. appId:"10016",
  7. releaseId:'2203181838_1375a0'
  8. });
  9. const l = async()=>{
  10. var R;
  11. try {
  12. await ((R = xverse.preload) == null ? void 0 : R.start('full', (M,x)=>{
  13. const I = `(${M}/${x})`;
  14. //s(I)
  15. }
  16. ))
  17. } catch (M) {
  18. if (console.error(M),
  19. M.code === Codes.PreloadCanceled) {
  20. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88"); //预加载被取消
  21. return
  22. }
  23. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5"); //进入失败, 请重试
  24. return
  25. }
  26. let nickname = Math.random().toString(16).slice(2)
  27. try {
  28. let room = await xverse.joinRoom({
  29. canvas: document.getElementById('canvas'),
  30. skinId: '0000000001',
  31. //skinId: '10089',
  32. avatarId: 'My_Actor',
  33. roomId: 'aea5406a-3099-48db-b428-30917872e58a',
  34. userId: nickname,
  35. //wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  36. //wsServerUrl: "ws://localhost:6688/ws",
  37. //wsServerUrl: "ws://192.168.1.100:6688/ws",
  38. //wsServerUrl: "wss://meta-socket.4dage.com/ws",
  39. // wsServerUrl: "wss://meta-socket1.4dage.com/ws",
  40. wsServerUrl: "wss://meta-socket2.4dage.com/ws",
  41. //appId: "10016",
  42. appId: "0000000008", //"0000000003", //"0000000007",
  43. token: " ",
  44. nickname: nickname,
  45. firends: ["user1"],
  46. viewMode: "full",
  47. resolution: {
  48. width: 1728,
  49. height: 720
  50. },
  51. pathName: 'thirdwalk',
  52. objectFit: null,
  53. hasAvatar: !0,
  54. syncToOthers: !0
  55. });
  56. window.room = room;
  57. u();
  58. c();
  59. f();
  60. //e(!1);
  61. } catch (M) {
  62. M = String(M).split(",")[1]
  63. console.error(M);
  64. new Tip(M) // alert(M);
  65. return
  66. }
  67. }
  68. const u = ()=>{
  69. window.room.on("_coreClick", ({point: f})=>{
  70. window.room._userAvatar.moveTo({
  71. point: f
  72. })
  73. }
  74. )
  75. }
  76. const c = ()=>{
  77. window.room.on("repeatLogin", function() {
  78. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", { //该用户已经在其他地点登录
  79. duration: 1e4
  80. })
  81. }),
  82. window.room.on("reconnecting", function({count: f}) {
  83. toast(`\u5C1D\u8BD5\u7B2C${f}\u6B21\u91CD\u8FDE`) //尝试第 ${f} 次重连
  84. }),
  85. window.room.on("reconnected", function() {
  86. toast("\u91CD\u8FDE\u6210\u529F") //重连成功
  87. }),
  88. window.room.on("disconnected", function() {
  89. const f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", { //连接失败,手动点击重试
  90. duration: 1e5,
  91. onClick() {
  92. f.hideToast(),
  93. window.room.reconnect()
  94. }
  95. })
  96. })
  97. }
  98. const f = async ()=>{
  99. const T = (await room.modelManager.findAssetList(String(room.skinId))).filter(E=>E.typeName === "MEDIA").map(E=>E.url);
  100. // a(T),
  101. room.tv && room.tv.setUrl({
  102. url: "./assets/4.mp4",
  103. loop: !0
  104. }).then(async()=>{
  105. try {
  106. if(room.tv.videoElement) {
  107. // room.tv.videoElement.muted = false
  108. await room.tv.videoElement.play()
  109. console.log("\u64AD\u653E\u6210\u529F") // 播放成功
  110. }
  111. } catch (S) {
  112. console.log("\u64AD\u653E\u5931\u8D25\uFF1A", S) // 播放失败
  113. document.addEventListener("touchstart", () => {
  114. room.tv.videoElement.play()
  115. })
  116. }
  117. }).catch(E=>{
  118. console.error(E)
  119. })
  120. }
  121. l();