123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- "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);
|