Browse Source

Image broadcast

infinite
A.Olokhtonov 2 years ago
parent
commit
3b8232e196
  1. 38
      client/client_recv.js
  2. 9
      client/client_send.js
  3. 1
      client/default.css
  4. 24
      client/index.html
  5. 9
      client/webgl_listeners.js
  6. 4
      client/websocket.js

38
client/client_recv.js

@ -214,27 +214,23 @@ function handle_event(state, context, event, relax = false) {
} }
case EVENT.IMAGE: { case EVENT.IMAGE: {
need_draw = true; try {
console.error('todo'); (async () => {
// const url = config.image_url + event.image_id; const url = config.image_url + event.image_id;
// const item = document.createElement('img'); const r = await fetch(config.image_url + event.image_id);
const blob = await r.blob();
// item.classList.add('floating-image'); const bitmap = await createImageBitmap(blob);
// item.style['z-index'] = state.events.length; const p = {'x': event.x, 'y': event.y};
// item.setAttribute('data-image-id', event.image_id);
// item.setAttribute('src', url); add_image(context, bitmap, p);
// item.style.transform = `translate(${event.x}px, ${event.y}px)`;
// God knows when this will actually complete (it loads the image from the server)
// elements.images.appendChild(item); // so do not set need_draw. Instead just schedule the draw ourselves when done
// state.images[event.image_id] = { schedule_draw(state, context);
// 'x': event.x, 'y': event.y })();
// }; } catch (e) {
// const r = await fetch(config.image_url + event.image_id); console.log('Could not load image bitmap:', e);
// const blob = await r.blob(); }
// const bitmap = await createImageBitmap(blob);
// event.bitmap = bitmap;
// const bbox = bitmap_bbox(event);
// state.ctx0.drawImage(bitmap, bbox.xmin, bbox.ymin);
break; break;
} }

9
client/client_send.js

@ -245,6 +245,15 @@ function width_event(width) {
}; };
} }
function image_event(image_id, x, y) {
return {
'type': EVENT.IMAGE,
'image_id': image_id,
'x': x,
'y': y,
};
}
function stroke_event(state) { function stroke_event(state) {
return { return {
'type': EVENT.STROKE, 'type': EVENT.STROKE,

1
client/default.css

@ -283,6 +283,7 @@ input[type=range]::-moz-range-track {
font-weight: bold; font-weight: bold;
user-select: none; user-select: none;
transition: transform .1s ease-in-out, opacity .1s; transition: transform .1s ease-in-out, opacity .1s;
pointer-events: none;
} }
.offline-toast.hidden { .offline-toast.hidden {

24
client/index.html

@ -7,20 +7,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="shortcut icon" href="icons/favicon.svg" id="favicon"> <link rel="shortcut icon" href="icons/favicon.svg" id="favicon">
<link rel="stylesheet" type="text/css" href="default.css?v=22"> <link rel="stylesheet" type="text/css" href="default.css?v=24">
<script type="text/javascript" src="aux.js?v=22"></script> <script type="text/javascript" src="aux.js?v=24"></script>
<script type="text/javascript" src="math.js?v=22"></script> <script type="text/javascript" src="math.js?v=24"></script>
<script type="text/javascript" src="tools.js?v=22"></script> <script type="text/javascript" src="tools.js?v=24"></script>
<script type="text/javascript" src="webgl_geometry.js?v=22"></script> <script type="text/javascript" src="webgl_geometry.js?v=24"></script>
<script type="text/javascript" src="webgl_shaders.js?v=22"></script> <script type="text/javascript" src="webgl_shaders.js?v=24"></script>
<script type="text/javascript" src="webgl_listeners.js?v=22"></script> <script type="text/javascript" src="webgl_listeners.js?v=24"></script>
<script type="text/javascript" src="webgl_draw.js?v=22"></script> <script type="text/javascript" src="webgl_draw.js?v=24"></script>
<script type="text/javascript" src="index.js?v=22"></script> <script type="text/javascript" src="index.js?v=24"></script>
<script type="text/javascript" src="client_send.js?v=22"></script> <script type="text/javascript" src="client_send.js?v=24"></script>
<script type="text/javascript" src="client_recv.js?v=22"></script> <script type="text/javascript" src="client_recv.js?v=24"></script>
<script type="text/javascript" src="websocket.js?v=22"></script> <script type="text/javascript" src="websocket.js?v=24"></script>
</head> </head>
<body> <body>
<div class="main"> <div class="main">

9
client/webgl_listeners.js

@ -363,20 +363,19 @@ async function on_drop(e, state, context) {
canvasp.y -= bitmap.height / 2; canvasp.y -= bitmap.height / 2;
add_image(context, bitmap, canvasp); add_image(context, bitmap, canvasp);
// storage.ctx0.drawImage(bitmap, x, y);
const form_data = new FormData(); const form_data = new FormData();
form_data.append('file', file); form_data.append('file', file);
const resp = await fetch(`/api/image?deskId=333`, { const resp = await fetch(`/api/image?deskId=${state.desk_id}`, {
method: 'post', method: 'post',
body: form_data, body: form_data,
}) })
if (resp.ok) { if (resp.ok) {
// const image_id = await resp.text(); const image_id = await resp.text();
// const event = image_event(image_id, x, y); const event = image_event(image_id, canvasp.x, canvasp.y);
// await queue_event(event); await queue_event(state, event);
} }
schedule_draw(state, context); schedule_draw(state, context);

4
client/websocket.js

@ -27,7 +27,9 @@ async function ws_connect(state, context, first_connect = false) {
return; return;
} }
} }
} catch (e) {} } catch (e) {
console.log('Could not ping the server:', e);
}
state.timers.offline_toast = setTimeout(() => ws_connect(state, context, first_connect), config.ws_reconnect_timeout); state.timers.offline_toast = setTimeout(() => ws_connect(state, context, first_connect), config.ws_reconnect_timeout);
} }

Loading…
Cancel
Save