Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 0d73a82

Browse files
accessibility command plugins
1 parent 4917791 commit 0d73a82

File tree

13 files changed

+274
-40
lines changed

13 files changed

+274
-40
lines changed

example/aframe/sandbox/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
77

8-
<script src="./../../../dist/aframe.min.js"></script> <!-- v1.5.0 -->
8+
<!-- AFRAME v1.5.0 + extra THREE.js extra loaders -->
9+
<script src="./../../../dist/aframe.min.js"></script>
910
<script src="./../../../dist/xrfragment.aframe.js"></script>
1011

1112
<!-- important: allow touchevents in AR -->

example/assets/index.glb

420 Bytes
Binary file not shown.

make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ build(){
105105
cp src/3rd/js/plugin/frontend/\$editor.js dist/xrfragment.plugin.editor.js
106106

107107
cp src/3rd/js/plugin/frontend/css.js dist/xrfragment.plugin.frontend.css.js
108-
jscat src/3rd/js/plugin/frontend/{snackbar,accessibility,\$menu,frontend}.js > dist/xrfragment.plugin.frontend.js
108+
jscat src/3rd/js/plugin/frontend/{snackbar,accessibility,\$menu,frontend,chatcommand/*}.js > dist/xrfragment.plugin.frontend.js
109109

110110
jscat src/3rd/js/plugin/matrix/{matrix-crdt,matrix}.js > dist/xrfragment.plugin.matrix.js
111111
jscat src/3rd/js/plugin/p2p/{trystero-torrent.min,trystero}.js > dist/xrfragment.plugin.p2p.js

src/3rd/js/aframe/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ window.AFRAME.registerComponent('xrf', {
5353
VRbutton = document.querySelector('.a-enter-vr-button')
5454
if( ARbutton ) ARbutton.addEventListener('click', () => AFRAME.XRF.hashbus.pub( '#-VR' ) )
5555
if( VRbutton ) VRbutton.addEventListener('click', () => AFRAME.XRF.hashbus.pub( '#VR' ) )
56-
//if( AFRAME.utils.device.checkARSupport() && VRbutton ){
57-
// VRbutton.style.display = 'none'
58-
// ARbutton.parentNode.style.right = '20px'
59-
//}
56+
})
57+
58+
// (de)active look-controls because of 'rot=' XR Fragment
59+
aScene.addEventListener('loaded', () => {
60+
// this is just for convenience (not part of spec): enforce AR + hide/show stuff based on VR tags in 3D model
61+
aScene.canvas.addEventListener('mousedown', () => xrf.camera.el.setAttribute("look-controls","") )
62+
})
63+
XRF.addEventListener('rot',(e) => {
64+
let lookcontrols = document.querySelector('[look-controls]')
65+
if( lookcontrols ) lookcontrols.removeAttribute("look-controls")
6066
})
6167

6268
let repositionUser = (scale) => () => {

src/3rd/js/plugin/frontend/$chat.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ chatComponent = {
2828
$messages: el.querySelector("#messages"),
2929
$chatline: el.querySelector("#chatline"),
3030
$chatbar: el.querySelector("#chatbar"),
31+
$chatsend: el.querySelector("#chatsend"),
3132

3233
install(opts){
3334
this.opts = opts
@@ -40,19 +41,30 @@ chatComponent = {
4041
this.send({message:`Welcome to <b>${document.location.search.substr(1)}</b>, a 3D scene(file) which simply links to other ones.<br>You can start a solo offline exploration in XR right away.<br>Type /help below, or use the arrow- or WASD-keys on your keyboard, and mouse-drag to rotate.<br>`, class: ["info","guide","multiline"] })
4142
},
4243

44+
sendInput(value){
45+
if( value[0] == '#' ) return xrf.navigator.to(value)
46+
let event = value.match(/^[!\/]/) ? "chat.command" : "network.send"
47+
let message = value.replace(/^[!\/]/,'')
48+
let raw = {detail:{message:value, halt:false}}
49+
document.dispatchEvent( new CustomEvent( event, {detail: {message}} ) )
50+
document.dispatchEvent( new CustomEvent( "chat.input", raw ) )
51+
if( event == "network.send" && !raw.detail.halt ) this.send({message: value })
52+
this.$chatline.lastValue = value
53+
this.$chatline.value = ''
54+
if( window.innerHeight < 600 ) this.$chatline.blur()
55+
},
56+
4357
initListeners(){
4458
let {$chatline} = this
4559

4660
$chatline.addEventListener('click', (e) => this.inform() )
4761

4862
$chatline.addEventListener('keydown', (e) => {
4963
if (e.key == 'Enter' ){
50-
let event = $chatline.value.match(/^[!\/]/) ? "chat.command" : "network.send"
51-
let message = $chatline.value.replace(/^[!\/]/,'')
52-
document.dispatchEvent( new CustomEvent( event, {detail: {message}} ) )
53-
if( event == "network.send" ) this.send({message: $chatline.value })
54-
$chatline.value = ''
55-
if( window.innerHeight < 600 ) $chatline.blur()
64+
this.sendInput($chatline.value)
65+
}
66+
if (e.key == 'ArrowUp' ){
67+
$chatline.value = $chatline.lastValue || ''
5668
}
5769
})
5870

@@ -76,11 +88,15 @@ chatComponent = {
7688
}
7789
})
7890

91+
this.$chatsend.addEventListener('click', (e) => {
92+
this.sendInput($chatline.value)
93+
})
94+
7995
},
8096

8197
inform(){
8298
if( !this.inform.informed && (this.inform.informed = true) ){
83-
window.notify("Connected via P2P. You can now type message which will be visible to others.")
99+
window.notify("You can now type messages in the textfield below.")
84100
}
85101
},
86102

@@ -263,6 +279,7 @@ chatComponent.css = `
263279
max-width: 500px;
264280
*/
265281
width:100%;
282+
box-sizing:border-box;
266283
align-items: flex-start;
267284
position: absolute;
268285
transition:1s;
@@ -271,7 +288,7 @@ chatComponent.css = `
271288
bottom: 49px;
272289
padding: 20px;
273290
overflow:hidden;
274-
overflow-y: scroll;
291+
overflow-y: auto;
275292
pointer-events:none;
276293
transition:1s;
277294
z-index: 100;
@@ -283,11 +300,14 @@ chatComponent.css = `
283300
pointer-events:all;
284301
}
285302
#messages *{
303+
box-sizing:border-box;
304+
/*
286305
pointer-events:none;
287306
-webkit-user-select:none;
288307
-moz-user-select:-moz-none;
289308
-ms-user-select:none;
290309
user-select:none;
310+
*/
291311
}
292312
#messages .msg{
293313
transition:all 1s ease;
@@ -320,9 +340,9 @@ chatComponent.css = `
320340
color:#FFF;
321341
}
322342
#messages .msg.info{
323-
background: #473f7f;
343+
background: var(--xrf-white);
324344
border-radius: 20px;
325-
color: #FFF;
345+
color: var(--xrf-dark-gray);
326346
text-align: left;
327347
line-height: 19px;
328348
}
@@ -411,7 +431,8 @@ chatComponent.css = `
411431
412432
.envelope{
413433
margin-right:15px;
414-
max-width:80%;
434+
width:50%;
435+
max-width:700px;
415436
}
416437
417438
.envelope,

src/3rd/js/plugin/frontend/accessibility.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ window.accessibility = (opts) => new Proxy({
44
enabled: false,
55

66
// features
7-
speak_movements: true,
8-
speak_keyboard: true,
7+
speak_teleports: true,
8+
speak_keyboard: false,
99

1010
// audio settings
1111
speak_rate: 1,
1212
speak_pitch: 1,
1313
speak_volume: 1,
1414
speak_voice: -1,
15+
speak_voices: 0,
1516

1617
toggle(){ this.enabled = !this.enabled },
1718

@@ -33,8 +34,10 @@ window.accessibility = (opts) => new Proxy({
3334
}
3435
let speech = window.speechSynthesis
3536
let utterance = new SpeechSynthesisUtterance( str )
36-
if( this.speak_voice != -1) utterance.voice = speech.getVoices()[ this.speak_voice ];
37-
else{
37+
this.speak_voices = speech.getVoices().length
38+
if( this.speak_voice != -1 && this.speak_voice < this.speak_voices ){
39+
utterance.voice = speech.getVoices()[ this.speak_voice ];
40+
}else{
3841
let voices = speech.getVoices()
3942
for(let i = 0; i < voices.length; i++ ){
4043
if( voices[i].lang == navigator.lang ) this.speak_voice = i;
@@ -78,6 +81,9 @@ window.accessibility = (opts) => new Proxy({
7881
this.speak( lines.join("."), {override:true,speaksigns:false} )
7982
}
8083
})
84+
document.addEventListener('$chat.send', (opts) => {
85+
if( opts.detail.message ) this.speak( opts.detail.message)
86+
})
8187
})
8288

8389
document.addEventListener('network.send', (e) => {
@@ -87,8 +93,7 @@ window.accessibility = (opts) => new Proxy({
8793
})
8894

8995
opts.xrf.addEventListener('pos', (opts) => {
90-
if( this.enabled ){
91-
$chat.send({message: this.posToMessage(opts) })
96+
if( this.enabled && this.speak_teleports ){
9297
network.send({message: this.posToMessage(opts), class:["info","guide"]})
9398
}
9499
if( opts.frag.pos.string.match(/,/) ){
@@ -100,7 +105,7 @@ window.accessibility = (opts) => new Proxy({
100105

101106
setTimeout( () => this.initCommands(), 200 )
102107
// auto-enable if previously enabled
103-
if( window.localStorage.getItem("accessibility") ){
108+
if( window.localStorage.getItem("accessibility") === 'true' ){
104109
setTimeout( () => {
105110
this.enabled = true
106111
this.setFontSize()
@@ -111,7 +116,7 @@ window.accessibility = (opts) => new Proxy({
111116
initCommands(){
112117

113118
document.addEventListener('chat.command.help', (e) => {
114-
e.detail.message += `<br><b class="badge">/fontsize <number></b> set fontsize (default=14) `
119+
e.detail.message += `<br><b class="badge">/fontsize &lt;number&gt;</b> set fontsize (default=14) `
115120
})
116121

117122
document.addEventListener('chat.command', (e) => {
@@ -179,10 +184,11 @@ window.accessibility = (opts) => new Proxy({
179184
data[k] = v
180185
switch( k ){
181186
case "enabled": {
182-
let message = "accessibility has been"+(v?"boosted":"lowered")
187+
let message = "accessibility mode has been "+(v?"activated":"disabled")+".<br>Type /help for help."
188+
if( v ) message = "<img src='https://i.imgur.com/wedtUSs.png' style='width:100%;border-radius:6px'/><br>" + message
183189
$('#accessibility.btn').style.filter= v ? 'brightness(1.0)' : 'brightness(0.5)'
184190
if( v ) $chat.visible = true
185-
$chat.send({message,class:['info','guide']})
191+
$chat.send({message,class:['info']})
186192
data.enabled = true
187193
data.speak(message)
188194
data.enabled = v
@@ -212,6 +218,10 @@ document.querySelector('head').innerHTML += `
212218
font-size:24px !important;
213219
line-height:40px;
214220
}
221+
.accessibility #messages .msg.self {
222+
background:var(--xrf-gray);
223+
color:#FFF;
224+
}
215225
.accessibility #messages .msg.info,
216226
.accessibility #messages .msg.self {
217227
line-height:unset;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// this allows surfing to a href by typing its node-name
2+
3+
// help screen
4+
document.addEventListener('chat.command.help', (e) => {
5+
e.detail.message += `
6+
<br><b class="badge">&lt;destinationname&gt;</b> surf to a destination
7+
`
8+
})
9+
10+
document.addEventListener('chat.input', (e) => {
11+
12+
let name = e.detail.message.trim()
13+
xrf.scene.traverse( (n) => {
14+
if( n.userData && n.userData.href && n.userData.href.match(/pos=/) && n.name == name ){
15+
$chat.send({message:'<b class="badge">activating</b> '+n.name, class:['self','info']})
16+
xrf.navigator.to( n.userData.href )
17+
}
18+
})
19+
20+
})

0 commit comments

Comments
 (0)