Skip to content

Commit 1465934

Browse files
committed
fix connection issue for ID on windows
Thanks https://github.com/goncalovf for identifying and showing fix.
1 parent c3eef3c commit 1465934

File tree

3 files changed

+122
-104
lines changed

3 files changed

+122
-104
lines changed

adb-proxy-socket/proxy.js

Lines changed: 98 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -23,115 +23,120 @@
2323
* SOFTWARE.
2424
*/
2525

26-
const express = require('express');
27-
const http = require('http');
28-
const { Server } = require('socket.io');
26+
const express = require("express");
27+
const http = require("http");
28+
const { Server } = require("socket.io");
2929
const app = express();
3030
const server = http.createServer(app);
31-
const io = new Server(server,
32-
{
33-
transports: ["websocket"],
34-
maxHttpBufferSize: 50 * 1024 * 1024
35-
}
36-
);
37-
38-
const PORT = 3001
31+
const io = new Server(server, {
32+
transports: ["websocket", "polling"],
33+
maxHttpBufferSize: 50 * 1024 * 1024,
34+
});
35+
36+
const PORT = 3001;
3937
// Track clients by application
4038
const applicationClients = {};
4139

42-
io.on('connection', (socket) => {
43-
console.log(`User connected: ${socket.id}`);
44-
45-
socket.on('register', ({ application }) => {
46-
console.log(`Client ${socket.id} registered for application: ${application}`);
47-
48-
// Store the application preference with this socket
49-
socket.data.application = application;
50-
51-
// Register this client for this application
52-
if (!applicationClients[application]) {
53-
applicationClients[application] = new Set();
54-
}
55-
applicationClients[application].add(socket.id);
56-
57-
// Optionally confirm registration
58-
socket.emit('registration_response', {
59-
type: 'registration',
60-
status: 'success',
61-
message: `Registered for ${application}`
40+
io.on("connection", (socket) => {
41+
console.log(`User connected: ${socket.id}`);
42+
43+
socket.on("register", ({ application }) => {
44+
console.log(
45+
`Client ${socket.id} registered for application: ${application}`
46+
);
47+
48+
// Store the application preference with this socket
49+
socket.data.application = application;
50+
51+
// Register this client for this application
52+
if (!applicationClients[application]) {
53+
applicationClients[application] = new Set();
54+
}
55+
applicationClients[application].add(socket.id);
56+
57+
// Optionally confirm registration
58+
socket.emit("registration_response", {
59+
type: "registration",
60+
status: "success",
61+
message: `Registered for ${application}`,
62+
});
6263
});
63-
});
64-
65-
socket.on('command_packet_response', ({ packet }) => {
66-
const senderId = packet.senderId;
67-
68-
if (senderId) {
69-
70-
io.to(senderId).emit('packet_response', packet);
71-
console.log(`Sent confirmation to client ${senderId}`);
72-
} else {
73-
console.log(`No sender ID provided in packet`);
74-
}
75-
});
76-
77-
socket.on('command_packet', ({ application, command }) => {
78-
console.log(`Command from ${socket.id} for application ${application}:`, command);
79-
80-
// Register this client for this application if not already registered
81-
//if (!applicationClients[application]) {
82-
// applicationClients[application] = new Set();
83-
//}
84-
//applicationClients[application].add(socket.id);
85-
86-
// Process the command
87-
88-
let packet = {
89-
senderId:socket.id,
90-
application:application,
91-
command:command
92-
}
9364

94-
sendToApplication(packet)
95-
96-
// Send response back to this client
97-
//socket.emit('json_response', { from: 'server', command });
98-
});
99-
100-
socket.on('disconnect', () => {
101-
console.log(`User disconnected: ${socket.id}`);
102-
103-
// Remove this client from all application registrations
104-
for (const app in applicationClients) {
105-
applicationClients[app].delete(socket.id);
106-
// Clean up empty sets
107-
if (applicationClients[app].size === 0) {
108-
delete applicationClients[app];
109-
}
110-
}
111-
});
65+
socket.on("command_packet_response", ({ packet }) => {
66+
const senderId = packet.senderId;
67+
68+
if (senderId) {
69+
io.to(senderId).emit("packet_response", packet);
70+
console.log(`Sent confirmation to client ${senderId}`);
71+
} else {
72+
console.log(`No sender ID provided in packet`);
73+
}
74+
});
75+
76+
socket.on("command_packet", ({ application, command }) => {
77+
console.log(
78+
`Command from ${socket.id} for application ${application}:`,
79+
command
80+
);
81+
82+
// Register this client for this application if not already registered
83+
//if (!applicationClients[application]) {
84+
// applicationClients[application] = new Set();
85+
//}
86+
//applicationClients[application].add(socket.id);
87+
88+
// Process the command
89+
90+
let packet = {
91+
senderId: socket.id,
92+
application: application,
93+
command: command,
94+
};
95+
96+
sendToApplication(packet);
97+
98+
// Send response back to this client
99+
//socket.emit('json_response', { from: 'server', command });
100+
});
101+
102+
socket.on("disconnect", () => {
103+
console.log(`User disconnected: ${socket.id}`);
104+
105+
// Remove this client from all application registrations
106+
for (const app in applicationClients) {
107+
applicationClients[app].delete(socket.id);
108+
// Clean up empty sets
109+
if (applicationClients[app].size === 0) {
110+
delete applicationClients[app];
111+
}
112+
}
113+
});
112114
});
113115

114116
// Add a function to send messages to clients by application
115117
function sendToApplication(packet) {
116-
117-
let application = packet.application
118+
let application = packet.application;
118119
if (applicationClients[application]) {
119-
console.log(`Sending to ${applicationClients[application].size} clients for ${application}`);
120-
121-
let senderId = packet.senderId
120+
console.log(
121+
`Sending to ${applicationClients[application].size} clients for ${application}`
122+
);
123+
124+
let senderId = packet.senderId;
122125
// Loop through all client IDs for this application
123-
applicationClients[application].forEach(clientId => {
124-
io.to(clientId).emit('command_packet', packet);
125-
});
126-
return true;
127-
}
128-
console.log(`No clients registered for application: ${application}`);
129-
return false;
126+
applicationClients[application].forEach((clientId) => {
127+
io.to(clientId).emit("command_packet", packet);
128+
});
129+
return true;
130+
}
131+
console.log(`No clients registered for application: ${application}`);
132+
return false;
130133
}
131134

132135
// Example: Use this function elsewhere in your code
133136
// sendToApplication('photoshop', { message: 'Update available' });
134137

135138
server.listen(PORT, () => {
136-
console.log(`adb-mcp Command proxy server running on ws://localhost:${PORT}`);
137-
});
139+
console.log(
140+
`adb-mcp Command proxy server running on ws://localhost:${PORT}`
141+
);
142+
});

uxp/id/main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const app = require("indesign");
2828
const {
2929
parseAndRouteCommand,
3030
checkRequiresActiveDocument,
31-
getActiveDocumentSettings
31+
getActiveDocumentSettings,
3232
} = require("./commands/index.js");
3333

3434
const APPLICATION = "indesign";
@@ -53,7 +53,6 @@ const onCommandPacket = async (packet) => {
5353
out.status = "SUCCESS";
5454
out.activeDocument = await getActiveDocumentSettings();
5555
//out.projectItems = await getProjectContentInfo();
56-
5756
} catch (e) {
5857
out.status = "FAILURE";
5958
out.message = `Error calling ${command.action} : ${e}`;
@@ -64,9 +63,20 @@ const onCommandPacket = async (packet) => {
6463

6564
function connectToServer() {
6665
// Create new Socket.IO connection
67-
socket = io(PROXY_URL, {
68-
transports: ["websocket"],
69-
});
66+
const isWindows = require("os").platform() === "win32";
67+
68+
const socketOptions = isWindows
69+
? {
70+
transports: ["polling"],
71+
upgrade: false,
72+
rememberUpgrade: false,
73+
}
74+
: {
75+
transports: ["websocket"],
76+
};
77+
console.log(isWindows);
78+
console.log(socketOptions);
79+
socket = io(PROXY_URL, socketOptions);
7080

7181
socket.on("connect", () => {
7282
updateButton();

uxp/id/manifest.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"version": "0.85.0",
55
"main": "index.html",
66
"host": [
7-
{
8-
"app": "ID",
9-
"minVersion": "20.2.0"
10-
}
7+
{
8+
"app": "ID",
9+
"minVersion": "20.2.0"
10+
}
1111
],
1212
"manifestVersion": 5,
1313
"entrypoints": [
@@ -65,13 +65,16 @@
6565
}
6666
],
6767
"label": {
68-
"default": "Premiere MCP Agent"
68+
"default": "InDesign MCP Agent"
6969
}
7070
}
7171
],
7272
"requiredPermissions": {
7373
"network": {
74-
"domains": "all"
74+
"domains": [
75+
"all",
76+
"http://localhost:3001"
77+
]
7578
},
7679
"localFileSystem": "fullAccess"
7780
},

0 commit comments

Comments
 (0)