"use strict"; const common_vendor = require("../../common/vendor.js"); const api_home = require("../../api/home.js"); const common_assets = require("../../common/assets.js"); var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; var pingpangTimes = null; var isSocketOpen = false; var socket = null; const _sfc_main = { data() { return { icon: "公告:", icon2: "广播:", text1: "组件功能丰富多端兼容让您快速集成开箱即用", text2: "丰富多端兼容让您快速集成开箱即用", srcAvatar: "", acttab: 0, value: "", talkdisabled: false, //是否禁用 placeholderText: "请输入内容", showadd: false, autoplay: true, //自动播放 userinfo: "", //用户信息 path: "http://192.168.10.170/dev-api", livedata: {}, bufferRate: 0, // 缓冲时间 playDuration: 0, //视频播放时间 videoContext: "", thistime: common_vendor.index.$u.timeFormat(/* @__PURE__ */ new Date(), "yyyy-mm-dd hh:MM:ss"), codeimg: "", userid: "4", liveId: "5", upDown: true, //是否视频显示隐藏 isLongPress: false, // 是否长按 timeout: null, // 计时器 list1: [ { name: "讨论" }, // { // name: '问答' // }, { name: "资料" } ], talklist: [], scrollIntoView: "", showWelcomeMessage: false, messageContent: "" }; }, mounted() { this.initSocket(); var that = this; common_vendor.index.$on("initSocket", () => { that.initSocket(); }); common_vendor.index.$on("sendMsg", (item) => { that.sendMsg(item); }); common_vendor.index.$on("closeWebSocket", () => { that.closeWebSocket(); }); this.getEWechatSdk(); this.userinfo = JSON.parse(common_vendor.index.getStorageSync("userInfo")); this.getliving(); this.gettalklist(); }, onReady: function(res) { this.videoContext = common_vendor.index.createVideoContext("myVideo"); }, onLoad() { }, methods: { gettalklist() { const param = { id: this.liveId }; api_home.gettextlist(param).then((res) => { if (res.code == 200) { this.talklist = res.data; this.$nextTick(() => { this.scrollIntoView = `list_${this.talklist.length - 1}`; }); } }); }, longPress() { this.timeout = setTimeout(() => { this.isLongPress = true; common_vendor.index.saveImageToPhotosAlbum({ filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径 success: () => { common_vendor.index.showToast({ title: "保存成功" }); }, fail: () => { common_vendor.index.showToast({ title: "保存失败", icon: "none" }); } }); }, 500); }, cancelLongPress() { clearTimeout(this.timeout); this.isLongPress = false; }, getliving() { this.gettalklist(); const param = { id: this.liveId }; api_home.getlive(param).then((res) => { if (res.code == 200) { this.livedata = res.data; this.codeimg = res.data.qwQrCode; if (this.livedata.status == 2) { this.autoplay = true; this.videoContext.seek(this.livedata.nowDuration); } else { this.autoplay = false; this.placeholderText = "直播开始才能发言讨论"; this.talkdisabled = true; } } else { common_vendor.index.showToast({ title: res.msg, icon: "none", duration: 2e3 }); } }); }, addwechat() { this.showadd = !this.showadd; }, open() { }, close() { this.showadd = !this.showadd; }, tabClick(e) { this.acttab = e.index; if (e.index == 0) { this.$nextTick(() => { this.gettalklist(); }); } }, getEWechatSdk() { let eWechatSdk = ""; if (/(Android)/i.test(navigator.userAgent)) { eWechatSdk = "jWeixin"; } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { eWechatSdk = "wx"; } else { eWechatSdk = "jWeixin"; } common_vendor.index.setStorageSync("wxSdk", eWechatSdk); }, closeWebSocket() { if (socket != null) { common_vendor.index.closeSocket(); } clearInterval(pingpangTimes); }, reConnect() { var that = this; try { common_vendor.index.closeSocket(); } catch (e) { } setTimeout(function() { that.initSocket(); }, 1e4); }, initSocket() { var that = this; socket = common_vendor.index.connectSocket({ // url: wsUrl+"?userId=40486&liveId=2", // url: wsUrl + "?userId=" + this.userid + "&liveId=" + // this.liveId+"&AppToken="+'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI0IiwiaWF0IjoxNzQwNzIxMDQ1LCJleHAiOjE3NDEzMjU4NDV9.PgS83JTMSJgVFD6vGAhUsEPbS6Az4yMyX8wVug61TZNTB3092CtvANo-AB9ZG4NdSBLgLrf4litM3vvTk-FK0g', url: wsUrl + "?userId=666&liveId=777&AppToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI2NjYiLCJpYXQiOjE3NTE4NzQ0NzEsImV4cCI6MTc4MzQxMDQ3MX0.3uxTTb0qXygmaY9ItovMclxJCNhNEi6kFEqmfLGg4lP2PYzCPODsVjW4PjXNu6EYsl5eYyESltHWcwBnaNkilQ&signature=ff21bfb41ddd5f2e31d6f5bf32ec565aab9c518614d139fa26727468ce701237&userType=0×tamp=666", multiple: true, success: (res) => { clearInterval(pingpangTimes); common_vendor.index.onSocketMessage((res2) => { const redata = JSON.parse(res2.data); this.talklist.push(redata.data); this.$nextTick(() => { this.scrollIntoView = `list_${this.talklist.length - 1}`; }); if (redata.cmd == "deleteId") { common_vendor.index.$emit("deleteId"); } else if (redata.cmd == "init") { common_vendor.index.$emit("init", redata.data); } else if (redata.cmd == "reload") { common_vendor.index.$emit("reload"); } else if (redata.cmd == "sendStatus") { common_vendor.index.$emit("sendStatus", redata.data); } else if (redata.data.cmd == "entry") { this.showWelcomeMessage = true; common_vendor.index.$emit("entry", redata.data); console.log(redata.data); } }); }, error: (res) => { common_vendor.index.$emit("websocket", 0); } }); common_vendor.index.onSocketOpen(() => { isSocketOpen = true; console.log("WebSocket连接已打开!!"); common_vendor.index.showToast({ title: "插件已打开", icon: "none" }); }); common_vendor.index.onSocketClose(() => { isSocketOpen = false; clearInterval(pingpangTimes); console.log("WebSocket连接已关闭!"); common_vendor.index.showToast({ title: "插件离线", icon: "none" }); that.reConnect(); }); common_vendor.index.onSocketError(() => { isSocketOpen = false; clearInterval(pingpangTimes); console.log("WebSocket连接打开失败"); common_vendor.index.showToast({ title: "插件离线", icon: "none" }); common_vendor.index.showModal({ content: "聊天连接失败是否重新尝试连接", success() { that.reConnect(); } }); }); }, sendMsg() { if (isSocketOpen) { const data = { liveId: this.livedata.liveId, userId: this.userinfo.userId, userType: 0, cmd: "sendMsg", msg: this.value, nickName: this.userinfo.nickName, avatar: this.userinfo.avatar }; if (this.value == "") { common_vendor.index.showToast({ title: "不能发送空消息", icon: "none" }); } else { socket.send({ data: JSON.stringify(data), success: () => { console.log("发送成功"); this.value = ""; }, fail: () => { console.log("发送失败"); } }); } } } } }; if (!Array) { const _easycom_u_tabs2 = common_vendor.resolveComponent("u-tabs"); const _easycom_u_avatar2 = common_vendor.resolveComponent("u-avatar"); const _easycom_u_input2 = common_vendor.resolveComponent("u-input"); const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon"); const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup"); (_easycom_u_tabs2 + _easycom_u_avatar2 + _easycom_u_input2 + _easycom_u_icon2 + _easycom_u_popup2)(); } const _easycom_u_tabs = () => "../../uni_modules/uview-plus/components/u-tabs/u-tabs.js"; const _easycom_u_avatar = () => "../../uni_modules/uview-plus/components/u-avatar/u-avatar.js"; const _easycom_u_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js"; const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js"; const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js"; if (!Math) { (_easycom_u_tabs + _easycom_u_avatar + _easycom_u_input + _easycom_u_icon + _easycom_u_popup)(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: $data.upDown }, $data.upDown ? common_vendor.e({ b: $data.path + $data.livedata.videoUrl, c: $data.autoplay, d: $data.livedata.liveImgUrl, e: !$data.autoplay }, !$data.autoplay ? common_vendor.e({ f: $data.livedata.status == 1 }, $data.livedata.status == 1 ? {} : {}, { g: $data.livedata.status == 3 }, $data.livedata.status == 3 ? {} : {}, { h: common_vendor.o(($event) => $data.showadd = !$data.showadd) }) : {}) : {}, { i: common_vendor.o($options.tabClick), j: common_vendor.p({ list: $data.list1, inactiveStyle: "color:#888", itemStyle: "width:120rpx;height: 80rpx;" }), k: common_vendor.o(($event) => $options.getliving()), l: common_assets._imports_0$3, m: $data.upDown, n: common_vendor.o(($event) => $data.upDown = !$data.upDown), o: common_assets._imports_1$1, p: !$data.upDown, q: common_vendor.o(($event) => $data.upDown = !$data.upDown), r: $data.acttab == 0 }, $data.acttab == 0 ? common_vendor.e({ s: common_vendor.f($data.talklist, (item, index, i0) => { return common_vendor.e({ a: "81fcd0c9-1-" + i0, b: common_vendor.p({ src: item.avatar, size: "30" }), c: item.userId == $data.userinfo.userId && item.cmd == "sendMsg" }, item.userId == $data.userinfo.userId && item.cmd == "sendMsg" ? {} : {}, { d: item.userType == 1 }, item.userType == 1 ? {} : {}, { e: common_vendor.t(item.nickName), f: common_vendor.t(item.msg), g: item.index, h: `list_${index}`, i: item.cmd == "sendMsg" }); }), t: $data.showWelcomeMessage }, $data.showWelcomeMessage ? { v: common_vendor.f($data.talklist, (item, index, i0) => { return common_vendor.e({ a: item.userType == 1 }, item.userType == 1 ? {} : {}, { b: common_vendor.t(item.nickName), c: common_vendor.t(item.msg), d: item.index, e: `list_${index}`, f: item.cmd == "entry" || item.cmd == "out" }); }) } : {}, { w: $data.scrollIntoView, x: common_vendor.o(($event) => $data.value = $event), y: common_vendor.p({ placeholder: $data.placeholderText, border: "none", customStyle: "background:#f1f7f7;padding:12rpx;padding-left:40rpx", shape: "circle", modelValue: $data.value }), z: common_vendor.o((...args) => $options.sendMsg && $options.sendMsg(...args)) }) : {}, { A: $data.acttab == 1 }, $data.acttab == 1 ? { B: $data.livedata.liveDesc, C: !$data.livedata.liveDesc } : {}, { D: common_assets._imports_2$1, E: common_vendor.o((...args) => $options.addwechat && $options.addwechat(...args)), F: common_vendor.o(($event) => $data.showadd = !$data.showadd), G: common_vendor.p({ name: "close", size: "18" }), H: $data.codeimg, I: common_vendor.o((...args) => $options.longPress && $options.longPress(...args)), J: common_vendor.o((...args) => $options.cancelLongPress && $options.cancelLongPress(...args)), K: common_vendor.o($options.close), L: common_vendor.o($options.open), M: common_vendor.p({ show: $data.showadd, round: "20rpx", bgColor: "#fffee1" }) }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-81fcd0c9"]]); wx.createPage(MiniProgramPage);