Skip to content

Commit e52e8ce

Browse files
committed
feat: update socket URL handling and enhance detected object reporting
1 parent dd137c6 commit e52e8ce

File tree

1 file changed

+11
-4
lines changed
  • scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_object_detection

1 file changed

+11
-4
lines changed

scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_object_detection/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ const iconURI = "";
2222
// eslint-disable-next-line max-len
2323
const menuIconURI = "";
2424

25-
// const wsServerURL = `${window.location.protocol}//${window.location.hostname}:7000`;
25+
// Determine the appropriate protocol and URL for socket.io connection
26+
const getSocketURL = () => {
27+
const protocol = window.location.protocol === 'https:' ? 'https:' : 'http:';
28+
const hostname = window.location.hostname || '192.168.1.39';
29+
const port = 7000;
30+
return `${protocol}//${hostname}:${port}`;
31+
};
2632

27-
const wsServerURL = `ws://192.168.1.39:7000`;
33+
const wsServerURL = getSocketURL();
2834

2935
/**
3036
* RGB color constants for confidence visualization
@@ -71,6 +77,7 @@ class ArduinoObjectDetection {
7177
this.io = io(wsServerURL, {
7278
path: "/socket.io",
7379
transports: ["polling", "websocket"],
80+
secure:true,
7481
autoConnect: true,
7582
});
7683

@@ -171,14 +178,14 @@ ArduinoObjectDetection.prototype.getInfo = function() {
171178
{
172179
opcode: "getDetectedObjectsCount",
173180
blockType: BlockType.REPORTER,
174-
text: "number of detected objects",
181+
text: "number",
175182
func: "getDetectedObjectsCount",
176183
arguments: {},
177184
},
178185
{
179186
opcode: "getDetectedLabelsAsString",
180187
blockType: BlockType.REPORTER,
181-
text: "detected object labels",
188+
text: "labels",
182189
func: "getDetectedLabelsAsString",
183190
arguments: {},
184191
},

0 commit comments

Comments
 (0)