noobs 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/noobs.node CHANGED
Binary file
package/index.d.ts CHANGED
@@ -1,6 +1,18 @@
1
- type Signal = { // TODO export type?
2
- id: string;
3
- code: number;
1
+ export type Signal = {
2
+ id: string; // Signal identifier, e.g. "stop"
3
+ code: number; // 0 for success, other values for errors
4
+ }
5
+
6
+ export type SceneItemPosition = {
7
+ x: number; // X position in pixels
8
+ y: number; // Y position in pixels
9
+ scaleX: number; // X scaling factor
10
+ scaleY: number; // Y scaling factor
11
+ };
12
+
13
+ export type SourceDimensions = {
14
+ height: number; // Height in pixels, before scaling
15
+ width: number; // Width in pixels, before scaling
4
16
  }
5
17
 
6
18
  interface Noobs {
@@ -18,7 +30,8 @@ interface Noobs {
18
30
  StopRecording(): void;
19
31
  GetLastRecording(): string;
20
32
 
21
- UpdateSource(x: number, y: number, scale: number): void;
33
+ GetSourcePos(src: string): SceneItemPosition & SourceDimensions;
34
+ SetSourcePos(src: string, pos: SceneItemPosition): void;
22
35
 
23
36
  InitPreview(hwnd: Buffer): void;
24
37
  ShowPreview(x: number, y: number, width: number, height: number): void;
@@ -26,4 +39,4 @@ interface Noobs {
26
39
  }
27
40
 
28
41
  declare const noobs: Noobs;
29
- export = noobs;
42
+ export default noobs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noobs",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "A native Node.js addon with libobs bindings for Warcraft Recorder.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/main.cpp CHANGED
@@ -157,22 +157,63 @@ Napi::Value ObsHidePreview(const Napi::CallbackInfo& info) {
157
157
  return info.Env().Undefined();
158
158
  }
159
159
 
160
- Napi::Value ObsUpdateSourcePos(const Napi::CallbackInfo& info) {
160
+ Napi::Value ObsGetSourcePos(const Napi::CallbackInfo& info) {
161
161
  if (!obs) {
162
162
  blog(LOG_ERROR, "ObsUpdateSource called but obs is not initialized");
163
163
  throw std::runtime_error("Obs not initialized");
164
164
  }
165
165
 
166
- bool valid = info.Length() == 3 &&
167
- info[0].IsNumber() && // X position (px)
168
- info[1].IsNumber() && // Y position (px)
169
- info[2].IsNumber(); // Scale (multiplier)
166
+ bool valid = info.Length() == 1 && info[0].IsString();
170
167
 
171
- int x = info[0].As<Napi::Number>().Int32Value();
172
- int y = info[1].As<Napi::Number>().Int32Value();
173
- float scale = info[2].As<Napi::Number>().FloatValue();
168
+ if (!valid) {
169
+ Napi::TypeError::New(info.Env(), "Invalid arguments passed to ObsGetSourcePos").ThrowAsJavaScriptException();
170
+ return info.Env().Undefined();
171
+ }
172
+
173
+ std::string name = info[0].As<Napi::String>().Utf8Value();
174
+
175
+ vec2 pos; vec2 size; vec2 scale;
176
+ obs->getSourcePos(name, &pos, &size, &scale);
177
+
178
+ Napi::Object result = Napi::Object::New(info.Env());
179
+ result.Set("x", Napi::Number::New(info.Env(), pos.x));
180
+ result.Set("y", Napi::Number::New(info.Env(), pos.y));
181
+ result.Set("width", Napi::Number::New(info.Env(), size.x));
182
+ result.Set("height", Napi::Number::New(info.Env(), size.y));
183
+ result.Set("scaleX", Napi::Number::New(info.Env(), scale.x));
184
+ result.Set("scaleY", Napi::Number::New(info.Env(), scale.y));
185
+ return result;
186
+ }
187
+
188
+ Napi::Value ObsSetSourcePos(const Napi::CallbackInfo& info) {
189
+ if (!obs) {
190
+ blog(LOG_ERROR, "ObsUpdateSource called but obs is not initialized");
191
+ throw std::runtime_error("Obs not initialized");
192
+ }
193
+
194
+ bool valid = info.Length() == 5 &&
195
+ info[0].IsString() && // Source name
196
+ info[1].IsNumber() && // X position (px)
197
+ info[2].IsNumber() && // Y position (px)
198
+ info[3].IsNumber() && // Scale factor (X)
199
+ info[4].IsNumber(); // Scale factor (Y)
200
+
201
+ if (!valid) {
202
+ Napi::TypeError::New(info.Env(), "Invalid arguments passed to ObsSetSourcePos").ThrowAsJavaScriptException();
203
+ return info.Env().Undefined();
204
+ }
205
+
206
+ std::string name = info[0].As<Napi::String>().Utf8Value();
207
+
208
+ float x = info[1].As<Napi::Number>().FloatValue();
209
+ float y = info[2].As<Napi::Number>().FloatValue();
210
+ vec2 pos = { x, y };
211
+
212
+ float scaleX = info[3].As<Napi::Number>().FloatValue();
213
+ float scaleY = info[4].As<Napi::Number>().FloatValue();
214
+ vec2 scale = { scaleX, scaleY };
174
215
 
175
- obs->updateSourcePos(x, y, scale);
216
+ obs->setSourcePos(name, &pos, &scale);
176
217
  return info.Env().Undefined();
177
218
  }
178
219
 
@@ -185,7 +226,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
185
226
  exports.Set("StopRecording", Napi::Function::New(env, ObsStopRecording));
186
227
  exports.Set("GetLastRecording", Napi::Function::New(env, ObsGetLastRecording));
187
228
 
188
- exports.Set("UpdateSourcePos", Napi::Function::New(env, ObsUpdateSourcePos));
229
+ exports.Set("GetSourcePos", Napi::Function::New(env, ObsGetSourcePos));
230
+ exports.Set("SetSourcePos", Napi::Function::New(env, ObsSetSourcePos));
189
231
 
190
232
  exports.Set("InitPreview", Napi::Function::New(env, ObsInitPreview));
191
233
  exports.Set("ShowPreview", Napi::Function::New(env, ObsShowPreview));
@@ -613,18 +613,42 @@ std::string ObsInterface::getLastRecording() {
613
613
  return path;
614
614
  }
615
615
 
616
- void ObsInterface::updateSourcePos(int x, int y, float scale) {
617
- blog(LOG_INFO, "ObsInterface::moveSource called at (%d, %d)", x, y);
618
- obs_sceneitem_t *item = obs_scene_find_source(scene, "video_source");
616
+ void ObsInterface::getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale)
617
+ {
618
+ blog(LOG_INFO, "ObsInterface::getSourcePos called");
619
+
620
+ obs_source_t *src = obs_get_source_by_name(name.c_str());
621
+ obs_sceneitem_t *item = obs_scene_find_source(scene, name.c_str());
622
+
623
+ if (!src) {
624
+ blog(LOG_ERROR, "Did not find source for video ");
625
+ return;
626
+ }
619
627
 
620
628
  if (!item) {
621
629
  blog(LOG_ERROR, "Did not find scene item for video source");
622
630
  return;
623
631
  }
624
632
 
625
- struct vec2 pos = { (float)x, (float)y };
626
- obs_sceneitem_set_pos(item, &pos);
633
+ obs_sceneitem_get_pos(item, pos);
634
+ obs_sceneitem_get_scale(item, scale);
635
+
636
+ // Pre-scaled sizes.
637
+ size->x = obs_source_get_width(src);
638
+ size->y = obs_source_get_height(src);
639
+
640
+ blog(LOG_INFO, "ObsInterface::getSourcePos exited");
641
+ }
642
+
643
+ void ObsInterface::setSourcePos(std::string name, vec2* pos, vec2* scale) {
644
+ blog(LOG_INFO, "ObsInterface::moveSource called");
645
+ obs_sceneitem_t *item = obs_scene_find_source(scene, name.c_str());
646
+
647
+ if (!item) {
648
+ blog(LOG_ERROR, "Did not find scene item for video source");
649
+ return;
650
+ }
627
651
 
628
- struct vec2 scalep = { scale, scale };
629
- obs_sceneitem_set_scale(item, &scalep);
652
+ obs_sceneitem_set_pos(item, pos);
653
+ obs_sceneitem_set_scale(item, scale);
630
654
  }
@@ -24,7 +24,8 @@ class ObsInterface {
24
24
  void stopRecording();
25
25
  std::string getLastRecording();
26
26
 
27
- void updateSourcePos(int x, int y, float scale);
27
+ void getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale); // Size is returned to allow clients to calculate scale.
28
+ void setSourcePos(std::string name, vec2* pos, vec2* scale); // Size does not get set here because it's set by the source itself.
28
29
 
29
30
  void initPreview(HWND parent); // Must call this before showPreview to setup resources.
30
31
  void showPreview(int x, int y, int width, int height); // Also used for moving and resizing.