|
@@ -13,6 +13,7 @@
|
|
|
const { io } = require("socket.io-client");
|
|
const { io } = require("socket.io-client");
|
|
|
import Login from "@/components/login";
|
|
import Login from "@/components/login";
|
|
|
import Loading from "@/components/loading";
|
|
import Loading from "@/components/loading";
|
|
|
|
|
+import { Message } from "view-design";
|
|
|
export default {
|
|
export default {
|
|
|
components: { Login, Loading },
|
|
components: { Login, Loading },
|
|
|
data() {
|
|
data() {
|
|
@@ -60,10 +61,17 @@ export default {
|
|
|
this.remoteVideo.srcObject = evt.streams[0];
|
|
this.remoteVideo.srcObject = evt.streams[0];
|
|
|
this.showLoading = false;
|
|
this.showLoading = false;
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ // init Control
|
|
|
|
|
+ window.addEventListener("gamepadconnected", this.conControl);
|
|
|
|
|
+ window.addEventListener("gamepaddisconnected", this.disControl);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
this.socket.disconnect();
|
|
this.socket.disconnect();
|
|
|
this.isLogin = false;
|
|
this.isLogin = false;
|
|
|
- alert("不支持Webrtc");
|
|
|
|
|
|
|
+ Message.error({
|
|
|
|
|
+ content: "webrtc初始化错误" + error,
|
|
|
|
|
+ duration: 3,
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -89,8 +97,21 @@ export default {
|
|
|
this.socket.on("connect_error", (err) => this.close(err));
|
|
this.socket.on("connect_error", (err) => this.close(err));
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ ControlData() {
|
|
|
|
|
+ const data = navigator.getGamepads();
|
|
|
|
|
+ const db = data[0];
|
|
|
|
|
+ if (!db) return;
|
|
|
|
|
+ const params = {
|
|
|
|
|
+ v0: Math.floor(db.axes[0] * 128 + 128),
|
|
|
|
|
+ v1: Math.floor(db.axes[1] * 128 + 128),
|
|
|
|
|
+ v2: Math.floor(db.axes[2] * 128 + 128),
|
|
|
|
|
+ v3: Math.floor(db.axes[3] * 128 + 128),
|
|
|
|
|
+ };
|
|
|
|
|
+ console.log(params);
|
|
|
|
|
+ requestAnimationFrame(this.ControlData);
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
login(data) {
|
|
login(data) {
|
|
|
- // 设置登录头
|
|
|
|
|
if (this.socket) {
|
|
if (this.socket) {
|
|
|
this.socket.auth = {
|
|
this.socket.auth = {
|
|
|
roomID: data.roomID,
|
|
roomID: data.roomID,
|
|
@@ -109,6 +130,25 @@ export default {
|
|
|
this.isLogin = false;
|
|
this.isLogin = false;
|
|
|
this.showLoading = false;
|
|
this.showLoading = false;
|
|
|
this.error = err || "";
|
|
this.error = err || "";
|
|
|
|
|
+ window.removeEventListener("gamepadconnected", this.conControl);
|
|
|
|
|
+ window.removeEventListener("gamepaddisconnected", this.disControl);
|
|
|
|
|
+ cancelAnimationFrame(this.ControlData);
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ conControl(event) {
|
|
|
|
|
+ Message.success({
|
|
|
|
|
+ content: event.gamepad.id + "手柄已连接",
|
|
|
|
|
+ duration: 3,
|
|
|
|
|
+ });
|
|
|
|
|
+ this.ControlData();
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ disControl(event) {
|
|
|
|
|
+ Message.error({
|
|
|
|
|
+ content: event.gamepad.id + "手柄已断开",
|
|
|
|
|
+ duration: 3,
|
|
|
|
|
+ });
|
|
|
|
|
+ cancelAnimationFrame(this.ControlData);
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|