MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / PinHandler

Class PinHandler

webiojs/src/handlers/pin.ts:9–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9export class PinHandler implements CommandHandler {
10 session: Session;
11
12 accept_command = ['pin_values', 'pin_update', 'pin_wait', 'pin_onchange'];
13
14 constructor(session: Session) {
15 this.session = session;
16 }
17
18 handle_message(msg: Command) {
19 if (msg.command === 'pin_values') {
20 let values = GetPinValues(msg.spec.names);
21 let send_msg = {
22 event: "js_yield",
23 task_id: msg.task_id,
24 data: values
25 };
26 this.submit(
27 send_msg,
28 msg.spec.names.filter(IsFileInput)
29 );
30 } else if (msg.command === 'pin_update') {
31 PinUpdate(msg.spec.name, msg.spec.attributes);
32 } else if (msg.command === 'pin_wait') {
33 let p = WaitChange(msg.spec.names, msg.spec.timeout);
34 Promise.resolve(p).then((change_info: (null | { name: string, value: any })) => {
35 // change_info: null or {'name': name, 'value': value}
36 let send_msg = {event: "js_yield", task_id: msg.task_id, data: change_info};
37 this.submit(
38 send_msg,
39 (change_info && IsFileInput(change_info.name)) ? ['value'] : []
40 );
41 }).catch((error) => {
42 console.error('error in `pin_wait`: %s', error);
43 this.submit({event: "js_yield", task_id: msg.task_id, data: null}, []);
44 });
45 } else if (msg.command === 'pin_onchange') {
46 let onchange = (val: any) => {
47 let send_msg = {
48 event: "callback",
49 task_id: msg.spec.callback_id,
50 data: {value: val}
51 }
52 this.submit(
53 send_msg,
54 IsFileInput(msg.spec.name)? ['value'] : []
55 );
56 }
57 PinChangeCallback(msg.spec.name, msg.spec.callback_id ? onchange : null, msg.spec.clear);
58 }
59 }
60
61 /*
62 * Send pin values to server.
63 * `msg.data`: {input_name: input_value, ...} or null
64 * for file input, the `input_value` is in {multiple: bool, files: File[] }
65 * */
66 submit(msg: ClientEvent, file_input_names: string[]) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…