-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
113 lines (98 loc) · 4.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>マルバツゲーム VR</title>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script src="https://aframe.io/releases/0.4.0/aframe.min.js"></script>
<script src="https://rawgit.com/bryik/aframe-bmfont-text-component/master/dist/aframe-bmfont-text-component.min.js"></script>
<script src="https://skyway.io/dist/0.3/peer.js"></script>
<script type="text/javascript">
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
var localStream;
navigator.getUserMedia({audio: true, video: false}, function(stream){
localStream = stream;
}, function(error) {
alert('Error!: ' + error);
});
var peer = new Peer({key: 'f42387e2-4c9f-4951-bce2-cc7802643eba'});
peer.on('open', function(id) {
login(id);
});
peer.on('call', function(call) {
call.answer(localStream);
call.on('stream', function(stream) {
let audio = document.getElementById("audio");
audio.srcObject = stream;
});
});
window.onbeforeunload = function(){
peer.disconnect();
}
var socket = io.connect();
var player_id;
socket.on("set_player", function(player) {
player_id = player;
var playersCamera = document.querySelector("#" + player_id);
playersCamera.setAttribute("camera", "active", true);
});
socket.on("click-square", function(square_id, player_id) {
click_square(square_id, player_id);
});
socket.on("call", function(peer_id) {
let call = window.peer.call(peer_id, localStream);
call.on('stream', function(stream){
let audio = document.getElementById("audio");
audio.srcObject = stream;
});
});
function login(peer_id) {
socket.emit("connected", peer_id);
}
function click_square(square_id, player_id) {
var image = player_id === "player1" ? "#cross" : "#circle";
document.querySelector("#" + square_id).setAttribute("src", image);
}
AFRAME.registerComponent('cursor-listener', {
init: function () {
this.el.addEventListener("click", function (evt) {
click_square(this.id, player_id);
socket.emit("click-square", this.id, player_id);
});
}
});
</script>
</head>
<body>
<audio id="audio" autoplay=true></audio>
<a-scene>
<a-assets>
<img src="https://i.imgur.com/7YnjGfI.png" id="square" crossorigin="anonymous">
<img src="https://i.imgur.com/vxesSQm.png" id="circle" crossorigin="anonymous">
<img src="https://i.imgur.com/EdymqIg.png" id="cross" crossorigin="anonymous">
</a-assets>
<a-camera position="0 1.6 -4" rotation="0 180 0" id="player1">
<a-cursor fuse=true fuse-timeout=1000></a-cursor>
<a-box color="#998877"></a-box>
<a-entity position="0 1 0" scale="3 3 0" rotation="0 180 0" bmfont-text="text: Player1; color: black;">
</a-camera>
<a-camera position="0 1.6 4" id="player2">
<a-cursor fuse=true fuse-timeout=1000></a-cursor>
<a-cylinder color="#114499" ></a-cylinder>
<a-entity position="0 1 0" scale="3 3 0" rotation="0 180 0" bmfont-text="text: Player2; color: black;">
</a-camera>
<a-sky color="#ECECEC"></a-sky>
<a-entity id="square">
<a-plane id="square0" cursor-listener src="#square" position="-1 0 -1" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square1" cursor-listener src="#square" position="-1 0 0" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square2" cursor-listener src="#square" position="-1 0 1" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square3" cursor-listener src="#square" position="0 0 -1" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square4" cursor-listener src="#square" position="0 0 0" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square5" cursor-listener src="#square" position="0 0 1" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square6" cursor-listener src="#square" position="1 0 -1" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square7" cursor-listener src="#square" position="1 0 0" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
<a-plane id="square8" cursor-listener src="#square" position="1 0 1" rotation="-90 0 0" width="1" height="1" color="#EEEEEE"></a-plane>
</a-entity>
</a-scene>
</body>
</html>