MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / connect

Function connect

server-bridge.js:148–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146 ws.removeEventListener('open', onOpen);
147 }
148 fn();
149 }
150 function onOpen() {
151 finish(resolve);
152 }
153 function attachToCurrentSocket() {
154 if (settled) return;
155 if (ws && ws.readyState === WebSocket.OPEN) {
156 finish(resolve);
157 return;
158 }
159 if (ws) {
160 ws.removeEventListener('open', onOpen);
161 ws.addEventListener('open', onOpen);
162 }
163 }
164 function poll() {
165 if (settled) return;
166 if (ws && ws.readyState === WebSocket.OPEN) {
167 finish(resolve);
168 return;
169 }
170 if (Date.now() >= deadline) {
171 finish(function() {
172 reject(new Error('WebSocket connection failed'));
173 });
174 return;
175 }
176 if (reconnectAttempts >= maxReconnectAttempts && (!ws || ws.readyState === WebSocket.CLOSED)) {
177 finish(function() {
178 reject(new Error('WebSocket connection unavailable'));
179 });
180 return;
181 }
182 // Keep trying connect while waiting (no-ops if already connecting/open)
183 connect();
184 attachToCurrentSocket();
185 pollTimer = setTimeout(poll, 250);
186 }
187
188 attachToCurrentSocket();
189 pollTimer = setTimeout(poll, 250);
190 });
191 }
192
193 // Define send() method - will be enhanced when WebSocket connects
194 let sendFunction = function(channel, ...args) {
195 // Will be enhanced when WebSocket connects
196 console.warn('window.electron.send called before WebSocket connected:', channel);
197 };
198 window.electron.send = sendFunction;
199
200 function showBrowserMessage(title, message, buttons = ['OK']) {
201 return new Promise((resolve) => {
202 const dialog = document.createElement('dialog');
203 const dialogId = `browser-message-${Date.now()}-${Math.floor(Math.random() * 1000)}`;
204 dialog.id = dialogId;
205 dialog.style.cssText = `

Callers 2

makeIpcCallFunction · 0.85
server-bridge.jsFile · 0.85

Calls 2

listenerFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected