123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- "use strict";
- var common_vendor = require("../../common/vendor.js");
- var api_home = require("../../api/home.js");
- require("../../common/request.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: "\u516C\u544A:",
- icon2: "\u5E7F\u64AD:",
- text1: "\u7EC4\u4EF6\u529F\u80FD\u4E30\u5BCC\u591A\u7AEF\u517C\u5BB9\u8BA9\u60A8\u5FEB\u901F\u96C6\u6210\u5F00\u7BB1\u5373\u7528",
- text2: "\u4E30\u5BCC\u591A\u7AEF\u517C\u5BB9\u8BA9\u60A8\u5FEB\u901F\u96C6\u6210\u5F00\u7BB1\u5373\u7528",
- srcAvatar: "",
- acttab: 0,
- value: "",
- talkdisabled: false,
- placeholderText: "\u8BF7\u8F93\u5165\u5185\u5BB9",
- 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(new Date(), "yyyy-mm-dd hh:MM:ss"),
- codeimg: "",
- userid: "4",
- liveId: "5",
- upDown: true,
- isLongPress: false,
- timeout: null,
- list1: [
- {
- name: "\u8BA8\u8BBA"
- },
- {
- name: "\u8D44\u6599"
- }
- ],
- 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: "\u4FDD\u5B58\u6210\u529F"
- });
- },
- fail: () => {
- common_vendor.index.showToast({
- title: "\u4FDD\u5B58\u5931\u8D25",
- 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 = "\u76F4\u64AD\u5F00\u59CB\u624D\u80FD\u53D1\u8A00\u8BA8\u8BBA";
- 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=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\u8FDE\u63A5\u5DF2\u6253\u5F00\uFF01!");
- common_vendor.index.showToast({
- title: "\u63D2\u4EF6\u5DF2\u6253\u5F00",
- icon: "none"
- });
- });
- common_vendor.index.onSocketClose(() => {
- isSocketOpen = false;
- clearInterval(pingpangTimes);
- console.log("WebSocket\u8FDE\u63A5\u5DF2\u5173\u95ED\uFF01");
- common_vendor.index.showToast({
- title: "\u63D2\u4EF6\u79BB\u7EBF",
- icon: "none"
- });
- that.reConnect();
- });
- common_vendor.index.onSocketError(() => {
- isSocketOpen = false;
- clearInterval(pingpangTimes);
- console.log("WebSocket\u8FDE\u63A5\u6253\u5F00\u5931\u8D25");
- common_vendor.index.showToast({
- title: "\u63D2\u4EF6\u79BB\u7EBF",
- icon: "none"
- });
- common_vendor.index.showModal({
- content: "\u804A\u5929\u8FDE\u63A5\u5931\u8D25\u662F\u5426\u91CD\u65B0\u5C1D\u8BD5\u8FDE\u63A5",
- 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: "\u4E0D\u80FD\u53D1\u9001\u7A7A\u6D88\u606F",
- icon: "none"
- });
- } else {
- socket.send({
- data: JSON.stringify(data),
- success: () => {
- console.log("\u53D1\u9001\u6210\u529F");
- this.value = "";
- },
- fail: () => {
- console.log("\u53D1\u9001\u5931\u8D25");
- }
- });
- }
- }
- }
- }
- };
- 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: $data.upDown,
- m: common_vendor.o(($event) => $data.upDown = !$data.upDown),
- n: !$data.upDown,
- o: common_vendor.o(($event) => $data.upDown = !$data.upDown),
- p: $data.acttab == 0
- }, $data.acttab == 0 ? common_vendor.e({
- q: common_vendor.f($data.talklist, (item, index, i0) => {
- return common_vendor.e({
- a: "281d25f3-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"
- });
- }),
- r: $data.showWelcomeMessage
- }, $data.showWelcomeMessage ? {
- s: 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"
- });
- })
- } : {}, {
- t: $data.scrollIntoView,
- v: common_vendor.o(($event) => $data.value = $event),
- w: common_vendor.p({
- placeholder: $data.placeholderText,
- border: "none",
- customStyle: "background:#f1f7f7;padding:12rpx;padding-left:40rpx",
- shape: "circle",
- modelValue: $data.value
- }),
- x: common_vendor.o((...args) => $options.sendMsg && $options.sendMsg(...args))
- }) : {}, {
- y: $data.acttab == 1
- }, $data.acttab == 1 ? {
- z: $data.livedata.liveDesc,
- A: !$data.livedata.liveDesc
- } : {}, {
- B: common_vendor.o((...args) => $options.addwechat && $options.addwechat(...args)),
- C: common_vendor.o(($event) => $data.showadd = !$data.showadd),
- D: common_vendor.p({
- name: "close",
- size: "18"
- }),
- E: $data.codeimg,
- F: common_vendor.o((...args) => $options.longPress && $options.longPress(...args)),
- G: common_vendor.o((...args) => $options.cancelLongPress && $options.cancelLongPress(...args)),
- H: common_vendor.o($options.close),
- I: common_vendor.o($options.open),
- J: common_vendor.p({
- show: $data.showadd,
- round: "20rpx",
- bgColor: "#fffee1"
- })
- });
- }
- var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-281d25f3"], ["__file", "C:/Users/Administrator/Desktop/\u9879\u76EE/\u76F4\u64AD/liveH5-v3/pages/home/live.vue"]]);
- wx.createPage(MiniProgramPage);
|