|
@@ -6,10 +6,18 @@ import { isPhoneX } from "./../../utils/tools";
|
|
|
|
|
|
import { CDN_URL, API_BASE_URL, VIDEO_BASE_URL, app } from "../../config/index";
|
|
|
|
|
|
+let socket_io = require("../../utils/socket.io-mp.js")
|
|
|
+
|
|
|
let timer = null;
|
|
|
|
|
|
var g_app = getApp();
|
|
|
|
|
|
+let TYPESTR = {
|
|
|
+ 0:'media',
|
|
|
+ 1:'pic'
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
import Router from "../../utils/routes";
|
|
|
|
|
|
VueLikePage([], {
|
|
@@ -18,40 +26,22 @@ VueLikePage([], {
|
|
|
isIphoneX: false,
|
|
|
canTap: true,
|
|
|
rndWord: randomWord(false, 8),
|
|
|
- background: [
|
|
|
- {
|
|
|
- img: "lunbo1.png",
|
|
|
- id: "1",
|
|
|
- },
|
|
|
- {
|
|
|
- img: "lunbo2.png",
|
|
|
- id: "2",
|
|
|
- },
|
|
|
- {
|
|
|
- img: "lunbo3.png",
|
|
|
- id: "3",
|
|
|
- },
|
|
|
- ],
|
|
|
-
|
|
|
scenes: [
|
|
|
{
|
|
|
- img: "1.png",
|
|
|
- id: "1",
|
|
|
+ id: "4",
|
|
|
},
|
|
|
{
|
|
|
- img: "2.png",
|
|
|
- id: "2",
|
|
|
+ id: "5",
|
|
|
},
|
|
|
{
|
|
|
- img: "3.png",
|
|
|
- id: "3",
|
|
|
+ id: "6",
|
|
|
},
|
|
|
],
|
|
|
autoplay: true,
|
|
|
interval: 3000,
|
|
|
duration: 500,
|
|
|
current: 0,
|
|
|
- currentScene: 1,
|
|
|
+ currentScene: 4,
|
|
|
daojishi: 0,
|
|
|
isShot: false,
|
|
|
isRecord: false,
|
|
@@ -127,166 +117,57 @@ VueLikePage([], {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- app.websocket = wx.connectSocket({
|
|
|
- url: API_BASE_URL,
|
|
|
- timeout: 180 * 1000,
|
|
|
- success: () => {},
|
|
|
+ app.websocket = socket_io(API_BASE_URL,{
|
|
|
+ transports: ['websocket']
|
|
|
});
|
|
|
|
|
|
- app.websocket.onOpen(() => {
|
|
|
- app.is_connect = true;
|
|
|
- app.is_connect_ok = null;
|
|
|
- app.send("request");
|
|
|
- });
|
|
|
+ app.websocket.on('connect', () => {
|
|
|
+ console.log('SOCKET连接成功');
|
|
|
+ app.emitEvent.request(data=>{
|
|
|
+ console.log(data,1111111);
|
|
|
+ });
|
|
|
+ })
|
|
|
|
|
|
- app.websocket.onMessage((msg) => {
|
|
|
- console.log(msg);
|
|
|
- app.hideLoading();
|
|
|
- if (typeof msg.data == "string") {
|
|
|
- switch (msg.data) {
|
|
|
- case "error 101":
|
|
|
- console.log("发送的消息有误");
|
|
|
- break;
|
|
|
- case "error 302":
|
|
|
- app.hideLoading();
|
|
|
- app.showAlert("网络异常,生成失败");
|
|
|
- break;
|
|
|
- case "error 404":
|
|
|
- app.showAlert("网络异常,请稍后再试");
|
|
|
- break;
|
|
|
- case "error 500":
|
|
|
- app.is_connect_ok = false;
|
|
|
- app.is_other_used = true;
|
|
|
-
|
|
|
- if (app.is_send_msg) {
|
|
|
- app.showAlert("服务器连接失败,请重新连接", () => {
|
|
|
- wx.reLaunch({
|
|
|
- url: "index",
|
|
|
- });
|
|
|
- },'重新连接');
|
|
|
- }
|
|
|
- break;
|
|
|
+ app.websocket.on('ForceOffline', () => {
|
|
|
+ app.showAlert("服务器连接失败,请稍后再试", () => {
|
|
|
+ wx.reLaunch({
|
|
|
+ url: "/pages/start/index",
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log('ForceOffline成功');
|
|
|
+ })
|
|
|
|
|
|
- case "error 808":
|
|
|
- app.is_connect_ok = true;
|
|
|
- app.is_other_used = true;
|
|
|
- if (app.is_send_msg) {
|
|
|
- app.showAlert("当前画屏正在被使用,请稍后");
|
|
|
- }
|
|
|
- break;
|
|
|
+ },
|
|
|
|
|
|
- case "error 909":
|
|
|
- if (app.is_send_msg) {
|
|
|
- app.showAlert("录像失败");
|
|
|
- }
|
|
|
- break;
|
|
|
- case "ok 200":
|
|
|
- console.log("切换画风成功");
|
|
|
- break;
|
|
|
- case "ok 201":
|
|
|
- app.is_connect_ok = false;
|
|
|
- app.is_other_used = true;
|
|
|
- app.checkOperationTimeout(true);
|
|
|
- break;
|
|
|
- case "ok 300":
|
|
|
- app.is_other_used = null;
|
|
|
- app.is_connect_ok = true;
|
|
|
- app.checkOperationTimeout();
|
|
|
- this.reset();
|
|
|
- break;
|
|
|
- case "ok 301":
|
|
|
- console.log("拍照成功,开始等待照片");
|
|
|
-
|
|
|
- // 轮询拿视频/图片
|
|
|
- this.clearLongTime();
|
|
|
- app.longtime = setInterval(() => {
|
|
|
- let link = "",
|
|
|
- m_type = "";
|
|
|
- if (this.data.type == "0") {
|
|
|
- link = `${VIDEO_BASE_URL}4dvedio/vedio${this.data.rndWord}.mp4`;
|
|
|
- m_type = "video";
|
|
|
- } else {
|
|
|
- link = `${VIDEO_BASE_URL}4dpic/pic${this.data.rndWord}.jpg`;
|
|
|
- m_type = "jpeg";
|
|
|
- }
|
|
|
-
|
|
|
- console.log(link, 1111);
|
|
|
- console.log(m_type, 1111);
|
|
|
-
|
|
|
- wx.downloadFile({
|
|
|
- url: link,
|
|
|
- success: (res) => {
|
|
|
- //判断是否为数组
|
|
|
- let typeType =
|
|
|
- (Object.prototype.toString.call(res.header["Content-Type"]) == "[object String]")?
|
|
|
- res.header["Content-Type"] : res.header["Content-Type"][0]
|
|
|
-
|
|
|
- console.log(typeType,8888);
|
|
|
-
|
|
|
- //判断不是xml文件
|
|
|
- if (typeType.indexOf(m_type) > -1) {
|
|
|
- this.clearLongTime();
|
|
|
- g_app.globalData.m_file = res.tempFilePath;
|
|
|
- this.gotoWork();
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (e) => {
|
|
|
- console.log(e, 1111);
|
|
|
+ checkTextDetail:function () {
|
|
|
+ wx.showModal({
|
|
|
+ title: '作品标识码(在首页获取作品)',
|
|
|
+ content: TYPESTR[this.data.type]+this.data.rndWord + app.id,
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: '复制文本',
|
|
|
+ success: (result) => {
|
|
|
+ if (result.confirm) {
|
|
|
+ wx.setClipboardData({
|
|
|
+ data: TYPESTR[this.data.type]+this.data.rndWord + app.id,
|
|
|
+ success: () => {
|
|
|
+ wx.getClipboardData({
|
|
|
+ success: () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 3
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
},
|
|
|
});
|
|
|
- }, 5 * 1000);
|
|
|
-
|
|
|
- // 3分钟后不可以就弹出生成失败
|
|
|
- timer = setTimeout(() => {
|
|
|
- this.clearLongTime();
|
|
|
- app.hideLoading();
|
|
|
- app.showAlert("生成失败,请重新连接", () => {
|
|
|
- wx.reLaunch({
|
|
|
- url: "index",
|
|
|
- });
|
|
|
- });
|
|
|
- }, 180 * 1000);
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- try {
|
|
|
- // var json = JSON.parse(msg.data);
|
|
|
- // if (json.url) {
|
|
|
- // if (json.url.indexOf(this.data.rndWord) > -1) {
|
|
|
- // timer && clearTimeout(timer);
|
|
|
- // timer = null
|
|
|
- // this.clearLongTime()
|
|
|
- // this.gotoWork();
|
|
|
- // }
|
|
|
- // }
|
|
|
- } catch (error) {
|
|
|
- console.error(error);
|
|
|
}
|
|
|
-
|
|
|
- break;
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
- app.is_send_msg = false;
|
|
|
- } else {
|
|
|
- console.log("error 600");
|
|
|
- }
|
|
|
+ },
|
|
|
});
|
|
|
-
|
|
|
- app.websocket.onClose((res) => {
|
|
|
- app.is_connect = false;
|
|
|
- app.checkOperationTimeout(true);
|
|
|
- app.hideLoading();
|
|
|
- app.websocket = null;
|
|
|
|
|
|
- if (!app.longtime&&!app.closeByVideoHandle) {
|
|
|
- app.showAlert("服务器连接已关闭,请重新连接", () => {
|
|
|
- wx.reLaunch({
|
|
|
- url: "index",
|
|
|
- });
|
|
|
- },'重新连接');
|
|
|
- app.closeByVideoHandle = false
|
|
|
- }
|
|
|
- });
|
|
|
+
|
|
|
},
|
|
|
onLoad: function () {
|
|
|
isPhoneX().then((res) => {
|
|
@@ -294,7 +175,14 @@ VueLikePage([], {
|
|
|
isIphoneX: res,
|
|
|
});
|
|
|
});
|
|
|
- this.handleWebSocket();
|
|
|
+ let tmp = g_app.globalData.scenes.map(item=>{
|
|
|
+ return {id:item}
|
|
|
+ })
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ scenes: tmp,
|
|
|
+ currentScene:tmp[0].id
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
daojishiFn(key, time, fn = () => {}) {
|
|
@@ -319,7 +207,7 @@ VueLikePage([], {
|
|
|
},
|
|
|
|
|
|
shot: function (e) {
|
|
|
- app.checkOperationTimeout(true);
|
|
|
+ // app.checkOperationTimeout(true);
|
|
|
|
|
|
let { id } = e.currentTarget.dataset;
|
|
|
|
|
@@ -328,11 +216,9 @@ VueLikePage([], {
|
|
|
rndWord: randomWord(false, 8),
|
|
|
});
|
|
|
|
|
|
- if (!app.sendCheck()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ // if (!app.sendCheck()) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
|
|
|
//录像
|
|
|
if (id == "0") {
|
|
@@ -347,10 +233,11 @@ VueLikePage([], {
|
|
|
daojishi: 3,
|
|
|
});
|
|
|
|
|
|
- app.send("switch " + this.data.currentScene);
|
|
|
+ app.emitEvent.switchMachine(this.data.currentScene)
|
|
|
+
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- app.send("photo " + "0#" + this.data.rndWord);
|
|
|
+ app.emitEvent.Video(TYPESTR[this.data.type]+this.data.rndWord)
|
|
|
|
|
|
// 为了同步机器的倒计时
|
|
|
setTimeout(() => {
|
|
@@ -364,19 +251,13 @@ VueLikePage([], {
|
|
|
title: "生成视频中...",
|
|
|
});
|
|
|
setTimeout(() => {
|
|
|
- this.closeServer(()=>{
|
|
|
- wx.showLoading({
|
|
|
- title: "生成视频中...",
|
|
|
- });
|
|
|
- });
|
|
|
- }, 20 * 1000);
|
|
|
+ wx.hideLoading()
|
|
|
+ this.checkTextDetail()
|
|
|
+ }, 1000);
|
|
|
});
|
|
|
});
|
|
|
}, 500);
|
|
|
-
|
|
|
}, 1000);
|
|
|
-
|
|
|
-
|
|
|
}, 500);
|
|
|
}
|
|
|
|
|
@@ -394,20 +275,22 @@ VueLikePage([], {
|
|
|
});
|
|
|
|
|
|
|
|
|
- app.send("switch " + this.data.currentScene);
|
|
|
+ app.emitEvent.switchMachine(this.data.currentScene)
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- app.send("photo " + "1#" + this.data.rndWord);
|
|
|
+ app.emitEvent.Photo(TYPESTR[this.data.type]+this.data.rndWord)
|
|
|
|
|
|
// 为了同步机器的倒计时
|
|
|
setTimeout(() => {
|
|
|
this.daojishiFn("daojishi", this.data.daojishi, () => {
|
|
|
- this.closeServer(()=>{
|
|
|
- wx.showLoading({
|
|
|
- title: "生成图片中...",
|
|
|
- // mask: true,
|
|
|
- });
|
|
|
+ wx.showLoading({
|
|
|
+ title: "生成图片中...",
|
|
|
+ // mask: true,
|
|
|
});
|
|
|
+ setTimeout(() => {
|
|
|
+ this.checkTextDetail()
|
|
|
+ wx.hideLoading()
|
|
|
+ }, 1000);
|
|
|
});
|
|
|
}, 500);
|
|
|
|
|
@@ -448,21 +331,15 @@ VueLikePage([], {
|
|
|
app.hideLoading();
|
|
|
}, 3 * 1000);
|
|
|
|
|
|
- if (!app.sendCheck()) {
|
|
|
- this.setData({
|
|
|
- canTap: true,
|
|
|
- });
|
|
|
- app.hideLoading();
|
|
|
- } else {
|
|
|
- wx.showLoading({
|
|
|
- title: "切换中...",
|
|
|
- mask: true,
|
|
|
- });
|
|
|
- this.setData({
|
|
|
- currentScene: id
|
|
|
- });
|
|
|
- app.send("switch " + id);
|
|
|
- }
|
|
|
+
|
|
|
+ wx.showLoading({
|
|
|
+ title: "切换中...",
|
|
|
+ mask: true,
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ currentScene: id
|
|
|
+ });
|
|
|
+ app.emitEvent.switchMachine(id)
|
|
|
},
|
|
|
},
|
|
|
});
|