Tool to send cross-session opencode messages, including as request-response pattern
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

implement mdns sensor

rektide 2bdd3800 915297ea

+93
+3
package.json
··· 27 27 "gunshi": "^0.27.6", 28 28 "oxfmt": "^0.28.0", 29 29 "oxlint": "^1.43.0" 30 + }, 31 + "dependencies": { 32 + "bonjour-service": "^1.3.0" 30 33 } 31 34 }
+44
pnpm-lock.yaml
··· 7 7 importers: 8 8 9 9 .: 10 + dependencies: 11 + bonjour-service: 12 + specifier: ^1.3.0 13 + version: 1.3.0 10 14 devDependencies: 11 15 gunshi: 12 16 specifier: ^0.27.6 ··· 19 23 version: 1.43.0 20 24 21 25 packages: 26 + 27 + '@leichtgewicht/ip-codec@2.0.5': 28 + resolution: {integrity: sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==} 22 29 23 30 '@oxfmt/darwin-arm64@0.28.0': 24 31 resolution: {integrity: sha512-jmUfF7cNJPw57bEK7sMIqrYRgn4LH428tSgtgLTCtjuGuu1ShREyrkeB7y8HtkXRfhBs4lVY+HMLhqElJvZ6ww==} ··· 108 115 cpu: [x64] 109 116 os: [win32] 110 117 118 + bonjour-service@1.3.0: 119 + resolution: {integrity: sha512-3YuAUiSkWykd+2Azjgyxei8OWf8thdn8AITIog2M4UICzoqfjlqr64WIjEXZllf/W6vK1goqleSR6brGomxQqA==} 120 + 121 + dns-packet@5.6.1: 122 + resolution: {integrity: sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw==} 123 + engines: {node: '>=6'} 124 + 125 + fast-deep-equal@3.1.3: 126 + resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} 127 + 111 128 gunshi@0.27.6: 112 129 resolution: {integrity: sha512-8+TfJPzDE9XjUkdxpQQNbdxHWZ1VuIjWIRMTht4id4qdo/mIRWLdxQd61m9gvPkPf5kg0LuIxEobCsWJVYjoPA==} 113 130 engines: {node: '>= 20'} 131 + 132 + multicast-dns@7.2.5: 133 + resolution: {integrity: sha512-2eznPJP8z2BFLX50tf0LuODrpINqP1RVIm/CObbTcBRITQgmC/TjcREF1NeTBzIcR5XO/ukWo+YHOjBbFwIupg==} 134 + hasBin: true 114 135 115 136 oxfmt@0.28.0: 116 137 resolution: {integrity: sha512-3+hhBqPE6Kp22KfJmnstrZbl+KdOVSEu1V0ABaFIg1rYLtrMgrupx9znnHgHLqKxAVHebjTdiCJDk30CXOt6cw==} ··· 127 148 oxlint-tsgolint: 128 149 optional: true 129 150 151 + thunky@1.1.0: 152 + resolution: {integrity: sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==} 153 + 130 154 tinypool@2.1.0: 131 155 resolution: {integrity: sha512-Pugqs6M0m7Lv1I7FtxN4aoyToKg1C4tu+/381vH35y8oENM/Ai7f7C4StcoK4/+BSw9ebcS8jRiVrORFKCALLw==} 132 156 engines: {node: ^20.0.0 || >=22.0.0} 133 157 134 158 snapshots: 159 + 160 + '@leichtgewicht/ip-codec@2.0.5': {} 135 161 136 162 '@oxfmt/darwin-arm64@0.28.0': 137 163 optional: true ··· 181 207 '@oxlint/win32-x64@1.43.0': 182 208 optional: true 183 209 210 + bonjour-service@1.3.0: 211 + dependencies: 212 + fast-deep-equal: 3.1.3 213 + multicast-dns: 7.2.5 214 + 215 + dns-packet@5.6.1: 216 + dependencies: 217 + '@leichtgewicht/ip-codec': 2.0.5 218 + 219 + fast-deep-equal@3.1.3: {} 220 + 184 221 gunshi@0.27.6: {} 222 + 223 + multicast-dns@7.2.5: 224 + dependencies: 225 + dns-packet: 5.6.1 226 + thunky: 1.1.0 185 227 186 228 oxfmt@0.28.0: 187 229 dependencies: ··· 206 248 '@oxlint/linux-x64-musl': 1.43.0 207 249 '@oxlint/win32-arm64': 1.43.0 208 250 '@oxlint/win32-x64': 1.43.0 251 + 252 + thunky@1.1.0: {} 209 253 210 254 tinypool@2.1.0: {}
+46
src/sensor/mdns.ts
··· 1 + import { Browser, Service } from "bonjour-service"; 2 + 3 + export interface Instance { 4 + port: number; 5 + hostname?: string; 6 + type: "mdns"; 7 + } 8 + 9 + export class MdnsSensor { 10 + private browser?: Browser; 11 + 12 + async discover(timeout = 5000): Promise<Instance[]> { 13 + const instances: Instance[] = []; 14 + const bonjour = new Browser(); 15 + 16 + this.browser = bonjour; 17 + 18 + return new Promise((resolve) => { 19 + const timer = setTimeout(() => { 20 + this.stop(); 21 + resolve(instances); 22 + }, timeout); 23 + 24 + bonjour.find({ type: "http", protocol: "tcp" }, (service) => { 25 + if (!service.name.includes("opencode")) { 26 + return; 27 + } 28 + 29 + if (service.port) { 30 + instances.push({ 31 + port: service.port, 32 + hostname: service.host, 33 + type: "mdns", 34 + }); 35 + } 36 + }); 37 + }); 38 + } 39 + 40 + stop(): void { 41 + if (this.browser) { 42 + this.browser.stop(); 43 + this.browser = undefined; 44 + } 45 + } 46 + }