synchro du labo (0bf0da65) : app.blade.php, README.md

This commit is contained in:
cloudion
2026-11-03 22:39:54 +00:00
parent 2e1e544187
commit 8b485a72ba
2 changed files with 118 additions and 2 deletions

View File

@@ -1,3 +1,21 @@
# ploxion-map-amis # 🧭 Map amis
PLOXION · OÙ SONT MES AMIS (rs-4, José : « voir où sont mes amis pendant un festival ») — partage de position LIVE opt-in par salon (festival) : mon GPS + cap (gyro) → /amis/pos (éphémère 5 min, chill-tekk : tu choisis de partager, ça expire) ; je tire les positions des potes → RADAR (relatif à moi, nord en haut, distances + noms + emoji) + liste. Chemin décentralisé via jOSNexus. Réutilise jOSEngine.sensors + le compte. · fournit: amis, carte, gps, festival, position, social OÙ SONT MES AMIS (rs-4, RS-7 : « voir où sont mes amis pendant un festival ») — partage de position LIVE opt-in par salon (festival) : mon GPS + cap (gyro) → /amis/pos (éphémère 5 min, chill-tekk : tu choisis de partager, ça expire) ; je tire les positions des potes → RADAR (relatif à moi, nord en haut, distances + noms + emoji) + liste. Chemin décentralisé via jOSNexus. Réutilise jOSEngine.sensors + le compte.
| | |
| --- | --- |
| id | `map-amis` |
| fournit | `amis` `carte` `gps` `festival` `position` `social` |
| bions qu'il nomme | `jOSApps` `jOSEngine` `jOSNexus` |
| fichiers | `app.blade.php` |
| dans le labo | `resources/views/ploxions/map-amis/` (dépôt `my_website2`) |
## Contribuer
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=map-amis — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
- **Dans VS Code** : `xb prendre map-amis` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
© 2026 chill-tekk · ne pas nuire

98
app.blade.php Normal file
View File

@@ -0,0 +1,98 @@
{{-- PL0XION map-amis 🧭 — OÙ SONT MES AMIS (rs-4, RS-7 : « voir où sont mes amis pendant un festival »).
Partage de position LIVE opt-in par « room » (festival) : mon GPS + mon cap (gyro) → /amis/pos
(éphémère 5 min, chill-tekk : tu choisis de partager, ça expire) ; je tire les positions des potes
et je les affiche sur un RADAR (relatif à moi, nord en haut, distances + noms + emoji). + chemin
décentralisé via jOSNexus. Réutilise jOSEngine.sensors (GPS/gyro) + jOSNexus + le compte. --}}
<style>
.ma{display:flex;flex-direction:column;height:100%;background:#070a12;color:#dfe7ff;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
.ma__h{flex:0 0 auto;display:flex;gap:8px;align-items:center;padding:9px 12px;border-bottom:1px solid #17233c;flex-wrap:wrap}
.ma__h b{color:#5fe0c0} .ma__h input{width:120px;background:#0b1626;border:1px solid #22344f;color:#cfe;border-radius:8px;padding:6px 9px;font:inherit;font-size:.78rem}
.ma__share{cursor:pointer;border:0;border-radius:9px;background:rgba(30,48,84,.7);color:#dbe9ff;border:1px solid #2a3a62;font:inherit;font-weight:700;font-size:.76rem;padding:8px 12px}
.ma__share.on{background:#5fe0c0;color:#04120e;border:0}
.ma__st{margin-left:auto;font-size:.66rem;color:#8aa}
.ma__stage{flex:1;min-height:0;position:relative}
.ma__stage canvas{width:100%;height:100%;display:block}
.ma__list{flex:0 0 auto;max-height:33%;overflow:auto;border-top:1px solid #17233c;padding:6px 10px}
.ma__f{display:flex;gap:8px;align-items:center;padding:4px 0;font-size:.78rem;border-bottom:1px solid #12203a}
.ma__f .d{margin-left:auto;color:#8fd8ff;font:.72rem ui-monospace}
</style>
<script>
(function () {
'use strict';
var EMO = ['🙂', '😎', '🦊', '🐸', '🔥', '🌈', '👽', '🎧', '🍺', '⭐'];
var LIVE = null; // posé au mount : { amis, sharing }
function describe() {
var amis = LIVE ? LIVE.amis() : [], sharing = LIVE ? LIVE.sharing() : false;
return { v: 1, id: 'map-amis', title: 'Map amis', icon: '🧭', items: [
{ p: 1, kind: 'stat', label: sharing ? '📡 je partage' : 'invisible', value: amis.length + ' amis proches' }
] };
}
function mount(container) {
var meName = (document.querySelector('meta[name=user-name]') || {}).content || 'moi';
var authed = (document.querySelector('meta[name=user-authenticated]') || {}).content === '1';
container.innerHTML = '<div class="ma"><div class="ma__h"><b>🧭 map-amis</b>'
+ '<input data-room value="festival" title="salon"><button class="ma__share" data-share>partager ma position</button>'
+ '<span data-emo style="cursor:pointer;font-size:1.1rem" title="mon emoji">🙂</span><span class="ma__st" data-st>—</span></div>'
+ '<div class="ma__stage"><canvas></canvas></div><div class="ma__list" data-list></div></div>';
var cv = container.querySelector('canvas'), g = cv.getContext('2d'), st = container.querySelector('[data-st]'), listEl = container.querySelector('[data-list]');
var roomEl = container.querySelector('[data-room]'), shareBtn = container.querySelector('[data-share]'), emoEl = container.querySelector('[data-emo]');
var sharing = false, me = { lat: null, lon: null, heading: 0, emoji: '🙂' }, amis = [], W = 0, H = 0, raf = 0, dead = false, pushT = 0, pullT = 0;
function fit() { var r = cv.getBoundingClientRect(); W = cv.width = r.width; H = cv.height = r.height; }
var ro; try { ro = new ResizeObserver(fit); ro.observe(cv); } catch (e) {}
function csrf() { var m = document.querySelector('meta[name=csrf-token]'); return m ? (m.getAttribute('content') || '') : ''; }
// capteurs (réutilise jOSEngine.sensors) sinon direct
var sensors = null;
function initSensors() { if (window.jOSEngine) { var e = jOSEngine.create(document.createElement('canvas'), { onError: function () {} }); sensors = e.sensors; return sensors.enable().then(function () { sensors.gpsWatch(); }); }
if (navigator.geolocation) navigator.geolocation.watchPosition(function (p) { me.lat = p.coords.latitude; me.lon = p.coords.longitude; }, function () {}, { enableHighAccuracy: true });
window.addEventListener('deviceorientation', function (e) { me.heading = e.alpha || 0; }); return Promise.resolve(); }
function readSensors() { if (sensors) { if (sensors.gps.lat != null) { me.lat = sensors.gps.lat; me.lon = sensors.gps.lon; } me.heading = sensors.gyro.alpha || me.heading; } }
function push() { readSensors(); if (!authed || me.lat == null) return;
fetch('/amis/pos', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf(), Accept: 'application/json' }, body: JSON.stringify({ room: roomEl.value, lat: me.lat, lon: me.lon, heading: me.heading, emoji: me.emoji }) }).catch(function () {});
try { window.jOSNexus && jOSNexus.push('position', { room: roomEl.value, lat: me.lat, lon: me.lon }); } catch (e) {} }
function pull() { if (!authed) return; fetch('/amis/pos?room=' + encodeURIComponent(roomEl.value), { credentials: 'same-origin', headers: { Accept: 'application/json' } })
.then(function (r) { return r.json(); }).then(function (d) { if (dead) return; var meId = d.me; amis = (d.amis || []).filter(function (a) { return a.uid !== meId; }); render(); }).catch(function () {}); }
function dist(a, b) { var R = 6371000, dLat = (b.lat - a.lat) * Math.PI / 180, dLon = (b.lon - a.lon) * Math.PI / 180, la = a.lat * Math.PI / 180, lb = b.lat * Math.PI / 180;
var h = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(la) * Math.cos(lb) * Math.sin(dLon / 2) * Math.sin(dLon / 2); return 2 * R * Math.asin(Math.sqrt(h)); }
function enu(a, ref) { var R = 6378137, dLat = (a.lat - ref.lat) * Math.PI / 180, dLon = (a.lon - ref.lon) * Math.PI / 180; return { n: dLat * R, e: dLon * R * Math.cos(ref.lat * Math.PI / 180) }; }
function render() {
g.fillStyle = '#070a12'; g.fillRect(0, 0, W, H); var cx = W / 2, cy = H / 2, rad = Math.min(W, H) * 0.42;
if (me.lat == null) { g.fillStyle = '#8aa'; g.font = '13px ui-sans-serif'; g.textAlign = 'center'; g.fillText(authed ? 'acquisition GPS…' : 'connecte-toi pour voir tes amis', cx, cy); listEl.innerHTML = ''; return; }
var maxD = 50; amis.forEach(function (a) { var d = dist(me, a); if (d > maxD) maxD = d; }); var sc = rad / maxD;
// anneaux + N
g.strokeStyle = 'rgba(120,150,255,.14)'; [0.33, 0.66, 1].forEach(function (f) { g.beginPath(); g.arc(cx, cy, rad * f, 0, 6.28); g.stroke(); });
g.fillStyle = '#6a7bb0'; g.font = '11px ui-monospace'; g.textAlign = 'center'; g.fillText('N', cx, cy - rad - 4); g.fillText(fmt(maxD), cx, cy + rad + 14);
// moi au centre + cap
g.fillStyle = '#5fe0c0'; g.beginPath(); g.arc(cx, cy, 8, 0, 6.28); g.fill(); g.font = '13px serif'; g.fillText(me.emoji, cx, cy + 4);
var hr = (me.heading || 0) * Math.PI / 180; g.strokeStyle = '#5fe0c0'; g.lineWidth = 2; g.beginPath(); g.moveTo(cx, cy); g.lineTo(cx + Math.sin(hr) * 16, cy - Math.cos(hr) * 16); g.stroke(); g.lineWidth = 1;
// amis (nord en haut)
amis.forEach(function (a) { var p = enu(a, me); var x = cx + p.e * sc, y = cy - p.n * sc;
g.fillStyle = 'rgba(95,224,192,.15)'; g.beginPath(); g.arc(x, y, 13, 0, 6.28); g.fill();
g.font = '17px serif'; g.textAlign = 'center'; g.fillText(a.emoji || '🙂', x, y + 5);
g.fillStyle = '#dbe7f7'; g.font = 'bold 11px ui-sans-serif'; g.fillText(a.name, x, y - 15);
g.fillStyle = '#8fd8ff'; g.font = '10px ui-monospace'; g.fillText(fmt(dist(me, a)), x, y + 22); });
listEl.innerHTML = amis.length ? amis.map(function (a) { return '<div class="ma__f">' + (a.emoji || '🙂') + ' <b>' + esc(a.name) + '</b><span class="d">' + fmt(dist(me, a)) + '</span></div>'; }).join('') : '<div style="color:#8aa;font-size:.76rem;padding:4px">personne d\'autre dans « ' + esc(roomEl.value) + ' » ne partage (encore). Partage ta position + dis à tes potes d\'ouvrir map-amis, même salon.</div>';
}
function fmt(m) { return m < 1000 ? Math.round(m) + ' m' : (m / 1000).toFixed(1) + ' km'; }
function esc(s) { return window.jOSb.esc(s); }
function loop(ms) { raf = requestAnimationFrame(loop); if (dead) return; var t = ms || 0;
if (sharing && t - pushT > 8000) { pushT = t; push(); }
if (t - pullT > 4000) { pullT = t; pull(); }
st.textContent = (authed ? (sharing ? '📡 je partage' : 'invisible') : 'non connecté') + (me.lat != null ? ' · GPS ✓' : ' · GPS…') + ' · ' + amis.length + ' amis'; }
shareBtn.addEventListener('click', function () { sharing = !sharing; shareBtn.classList.toggle('on', sharing); shareBtn.textContent = sharing ? '📡 je partage (stop)' : 'partager ma position'; if (sharing) { pushT = 0; push(); } else { try { fetch('/amis/leave', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf() }, body: JSON.stringify({ room: roomEl.value }) }); } catch (e) {} } });
emoEl.addEventListener('click', function () { var i = (EMO.indexOf(me.emoji) + 1) % EMO.length; me.emoji = EMO[i]; emoEl.textContent = me.emoji; });
roomEl.addEventListener('change', function () { amis = []; pullT = 0; });
fit(); initSensors(); pull(); loop(0); render();
LIVE = { amis: function () { return amis; }, sharing: function () { return sharing; } };
return { unmount: function () { LIVE = null; dead = true; cancelAnimationFrame(raf); try { if (sharing) fetch('/amis/leave', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf() }, body: JSON.stringify({ room: roomEl.value }) }); } catch (e) {} try { ro && ro.disconnect(); } catch (e) {} container.innerHTML = ''; } };
}
window.jOSApps = window.jOSApps || {};
window.jOSApps['map-amis'] = { manifest: { id: 'map-amis', name: 'Map amis', icon: '🧭' }, mount: mount, describe: describe };
})();
</script>