Skip to content

Commit 09626a1

Browse files
committed
Added a warning for detectStart() called more than once
1 parent b20d85a commit 09626a1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Handpose/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Handpose {
2828
* @property {string} detectorModelUrl - The file path or URL to the hand detector model when using "tfjs" runtime.
2929
* @property {string} landmarkModelUrl - The file path or URL to the hand landmark model when using "mediapipe" runtime.
3030
*/
31+
3132
/**
3233
* Create Handpose.
3334
* @param {configOptions} options - An object with options.
@@ -45,9 +46,10 @@ class Handpose {
4546
this.detectMedia = null;
4647
this.detectCallback = null;
4748

48-
//flags for detectStart() and detectStop()
49-
this.detecting = false;
50-
this.signalStop = false;
49+
// flags for detectStart() and detectStop()
50+
this.detecting = false; // true when detection loop is running
51+
this.signalStop = false; // true when detectStop() is called and detecting is true
52+
this.prevCall = ""; // "start" or "stop", used for giving warning messages with detectStart() is called twice in a row
5153

5254
this.ready = callCallback(this.loadModel(), callback);
5355
}
@@ -135,17 +137,25 @@ class Handpose {
135137
this.detecting = true;
136138
this.detectLoop();
137139
}
140+
if (this.prevCall === "start") {
141+
console.warn(
142+
"detectStart() was called more than once without calling detectStop(). The lastest detectStart() call will be used and the previous calls will be ignored."
143+
);
144+
}
145+
this.prevCall = "start";
138146
}
139147

140148
/**
141-
* Stop the detection loop before next frame update
149+
* Stop the detection loop before next detection loop runs.
142150
*/
143151
detectStop() {
144152
if (this.detecting) this.signalStop = true;
153+
this.prevCall = "stop";
145154
}
146155

147156
/**
148157
* Internal function to call estimateHands in a loop
158+
* Can be started by detectStart() and terminated by detectStop()
149159
*
150160
* @private
151161
*/

0 commit comments

Comments
 (0)