-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.html
233 lines (211 loc) · 6.59 KB
/
go.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>360Go Skyway</title>
<meta name="description" content="360 Video — A-Frame">
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script type="text/javascript" src="https://cdn.webrtc.ecl.ntt.com/skyway-latest.js"></script>
<script>
//function _assert(desc, v) {
// if (v) {
// return;
// }
// else {
// let caller = _assert.caller || 'Top level';
// console.error('ASSERT in %s, %s is :', caller, desc, v);
// }
//}
//function _logStream(stream) {
// console.log(msg + ': id=' + stream.id);
// const videoTracks = stream.getVideoTracks();
// if (videoTracks) {
// console.log('videoTracks.length=' + videoTracks.length);
// for (let i = 0; i < videoTracks.length; i++) {
// const track = videoTracks[i];
// console.log('track.id=' + track.id);
// }
// }
// const audioTracks = stream.getAudioTracks();
// if (audioTracks) {
// console.log('audioTracks.length=' + audioTracks.length);
// for (let i = 0; i < audioTracks.length; i++) {
// const track = audioTracks[i];
// console.log('track.id=' + track.id);
// }
// }
//}
</script>
<script type="text/javascript">
// ----- use skyway room ----
let myApiKey = '2885722c-b2d0-4dd7-9d7b-d9738873effa'; //null; // set your API key
let peer = null;
let meshRoom = null;
const defaultRoomName = '0000';
function getApiKey() {
let key = document.getElementById('api_key_text').value;
return key;
}
function getApiKeyFromURL() {
const search = window.location.search;
const re = new RegExp('apikey=([^&=]+)');
const results = re.exec(search);
if (results) {
//document.getElementById('api_key_text').value = results[1];
return results[1];
}
return null;
}
function getRoomFromURL() {
const search = window.location.search;
const re = new RegExp('room=([^&=]+)');
const results = re.exec(search);
if (results) {
//document.getElementById('roomname_text').value = results[1];
return results[1];
}
}
//let localStream = null;
//function startMediaAndJoinRoom() {
// const mediaConstraints = {video: false, audio: true};
// console.log('--startMediaAndJoinRoom is called--');
// navigator.mediaDevices.getUserMedia(mediaConstraints)
//.then( stream => {
// _logStream(stream);
// localStream = stream;
// joinRoom(stream);
// })
// .catch ( err => {
// console.error('getUserMedia ERROR:', err );
// })
//}
function joinRoom(stream) {
let apiKey = getApiKeyFromURL() || myApiKey;
if ((! apiKey) || (apiKey === '')) {
alert('Please set your API Key');
return;
}
const roomName = getRoomFromURL() || defaultRoomName;
peer = new Peer({key: apiKey, debug: 1});
peer.on('open',function() {
console.log('--open--');
//meshRoom = peer.joinRoom(roomName, {mode: 'mesh', stream: localStream});
if (stream) {
meshRoom = peer.joinRoom(roomName, {mode: 'sfu', stream: stream});
}
else {
meshRoom = peer.joinRoom(roomName, {mode: 'sfu'});
}
meshRoom.on('open', function() {
console.log('joined the room:' + roomName);
console.log('check stream:' + stream);
});
meshRoom.on('stream', function(stream) {
console.log('on stream:' + stream);
let remoteId = stream.peerId;
attachVideo(remoteId, stream);
});
meshRoom.on('peerLeave', function(peerId) {
console.log('Left room' + peerId);
detachVideo(peerId);
});
});
// -- kick to play in iOS 11 Safari --
//setTimeout(playAllRemoteVideo, 1000);
}
function leaveRoom() {
if (meshRoom) {
meshRoom.close();
}
detachVideo('_any_');
}
function attachVideo(id, stream) {
console.log('attach stream =' + stream);
const videoElement = document.getElementById("video1");
videoElement.srcObject = stream;
videoElement.play();
console.info("remote media start");
}
function detachVideo(id) {
const videoElement = document.getElementById("video1");
videoElement.pause();
videoElement.srcObject = null;
console.info("remote media stop");
}
function hideWaitMessage() {
const element = document.getElementById("wait_massage");
element.style.display = 'none';
}
</script>
<script>
AFRAME.registerComponent('play-on-window-click', {
init: function () {
this.onClick = this.onClick.bind(this);
},
play: function () {
window.addEventListener('click', this.onClick);
},
pause: function () {
window.removeEventListener('click', this.onClick);
},
onClick: function (evt) {
hideWaitMessage();
joinRoom(null);
//startMediaAndJoinRoom();
}
});
AFRAME.registerComponent('hide-once-playing', {
schema: {type: 'selector'},
init: function () {
this.onPlaying = this.onPlaying.bind(this);
this.onPause = this.onPause.bind(this);
},
play: function () {
if (this.data) {
this.data.addEventListener('playing', this.onPlaying);
this.data.addEventListener('pause', this.onPause);
}
},
pause: function () {
if (this.data) {
this.data.removeEventListener('playing', this.onPlaying);
this.data.removeEventListener('pause', this.onPause);
}
},
onPlaying: function (evt) {
this.el.setAttribute('visible', false);
},
onPause: function (evt) {
this.el.setAttribute('visible', true);
}
});
</script>
</head>
<body>
<div id="wait_massage">Please wait for loading ...</div>
<a-scene>
<a-assets>
<video id="video1" autoplay loop crossorigin="anonymous" playsinline webkit-playsinline>
<source src="" type="video/mp4">
</video>
</a-assets>
<a-videosphere src="#video1" rotation="0 90 0"
play-on-window-click
>
</a-videosphere>
<a-camera user-height="0" wasd-controls-enabled="false" arrow-key-rotation>
<!-- Text element for display messaging. Hide once video is playing. -->
<a-entity id="msg" position="0 -0.3 -1.5" text="align:center;
width:3;
wrapCount:100;
color: #FF8080;
value:Please click window to start 360 video streaming."
hide-once-playing="#video1">
</a-entity>
</a-camera>
</a-scene>
</body>
<script type="text/javascript">
//joinRoom();
</script>
</html>