@4players/odin-nodejs 0.8.0 → 0.9.0
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/cppsrc/odinroom.cpp
CHANGED
|
@@ -331,6 +331,8 @@ Napi::Object OdinRoom::Init(Napi::Env env, Napi::Object exports) {
|
|
|
331
331
|
Napi::Function func = DefineClass(env, "OdinRoom", {
|
|
332
332
|
InstanceMethod<&OdinRoom::Join>("join", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
333
333
|
InstanceMethod<&OdinRoom::UpdatePeerUserData>("updateOwnUserData", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
334
|
+
InstanceMethod<&OdinRoom::UpdatePosition>("updatePosition", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
335
|
+
InstanceMethod<&OdinRoom::SetPositionScale>("setPositionScale", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
334
336
|
InstanceMethod<&OdinRoom::SendMessage>("sendMessage", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
335
337
|
InstanceMethod<&OdinRoom::SetEventListener>("setEventListener", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
336
338
|
InstanceMethod<&OdinRoom::AddEventListener>("addEventListener", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
@@ -365,6 +367,50 @@ Napi::Object OdinRoom::Init(Napi::Env env, Napi::Object exports) {
|
|
|
365
367
|
return exports;
|
|
366
368
|
}
|
|
367
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Updates the position of this room. Requires x, y and z coordinates as parameters.
|
|
372
|
+
* @param info Napi::CallbackInfo
|
|
373
|
+
*/
|
|
374
|
+
void OdinRoom::UpdatePosition(const Napi::CallbackInfo &info)
|
|
375
|
+
{
|
|
376
|
+
Napi::Env env = info.Env();
|
|
377
|
+
|
|
378
|
+
if (info.Length() != 3 || !info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber()) {
|
|
379
|
+
Napi::TypeError::New(env, "Provide x, y and z coordinates as numbers").ThrowAsJavaScriptException();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
float x = info[0].ToNumber();
|
|
383
|
+
float y = info[1].ToNumber();
|
|
384
|
+
float z = info[2].ToNumber();
|
|
385
|
+
|
|
386
|
+
OdinReturnCode error = odin_room_update_position(_roomHandle, x, y, z);
|
|
387
|
+
if (odin_is_error(error))
|
|
388
|
+
{
|
|
389
|
+
OdinUtilities::ThrowNapiException(env, error, "Failed to update position");
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Sets the position scale for this room. Requires a scale as a parameter.
|
|
395
|
+
* @param info Napi::CallbackInfo
|
|
396
|
+
*/
|
|
397
|
+
void OdinRoom::SetPositionScale(const Napi::CallbackInfo &info)
|
|
398
|
+
{
|
|
399
|
+
Napi::Env env = info.Env();
|
|
400
|
+
|
|
401
|
+
if (info.Length() != 1 || !info[0].IsNumber()) {
|
|
402
|
+
Napi::TypeError::New(env, "Provide scale as number").ThrowAsJavaScriptException();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
float scale = info[0].ToNumber();
|
|
406
|
+
|
|
407
|
+
OdinReturnCode error = odin_room_set_position_scale(_roomHandle, scale);
|
|
408
|
+
if (odin_is_error(error))
|
|
409
|
+
{
|
|
410
|
+
OdinUtilities::ThrowNapiException(env, error, "Failed to set position scale");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
368
414
|
/**
|
|
369
415
|
* Joins the Odin room. Requires a gateway URL as a parameter and optionally initial peer data.
|
|
370
416
|
* @param info Napi::CallbackInfo
|
package/cppsrc/odinroom.h
CHANGED
|
@@ -56,6 +56,8 @@ private:
|
|
|
56
56
|
EventData* PrepareEventData(OdinEvent* event);
|
|
57
57
|
static uint16_t GetMediaIdFromHandle(OdinMediaStreamHandle handle);
|
|
58
58
|
void HandleAudioData();
|
|
59
|
+
void UpdatePosition(const Napi::CallbackInfo &info);
|
|
60
|
+
void SetPositionScale(const Napi::CallbackInfo &info);
|
|
59
61
|
|
|
60
62
|
Napi::Value CreateAudioStream(const Napi::CallbackInfo &info);
|
|
61
63
|
};
|
package/odin.room.d.ts
CHANGED
|
@@ -445,6 +445,34 @@ export declare class OdinRoom {
|
|
|
445
445
|
*/
|
|
446
446
|
updateOwnUserData(userData: Uint8Array): void;
|
|
447
447
|
|
|
448
|
+
/**
|
|
449
|
+
* Updates the three-dimensional position of the current peer in this room.
|
|
450
|
+
* The server utilizes the provided coordinates to perform automatic culling among peers in the same
|
|
451
|
+
* room, based on unit circles with a radius of `1.0`. This feature is particularly beneficial in
|
|
452
|
+
* scenarios involving a large number of peers within the same room, enabling peers to interact or
|
|
453
|
+
* 'see' each other only when in close proximity. To modify the distance sensitivity for position
|
|
454
|
+
* updates, use `setPositionScale`.
|
|
455
|
+
*
|
|
456
|
+
* Note: Use this before calling `join` to set the initial peer position upon connect.
|
|
457
|
+
*
|
|
458
|
+
* @param x - The new x position of the peer.
|
|
459
|
+
* @param y - The new y position of the peer.
|
|
460
|
+
* @param z - The new z position of the peer.
|
|
461
|
+
*/
|
|
462
|
+
updatePosition(x: number, y: number, z: number): void;
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Sets the scaling factor for coordinates supplied to `updatePosition`, facilitating
|
|
466
|
+
* adaptation to your game's unique coordinate system requirements. Peers are visible to each other
|
|
467
|
+
* only within a unit circle of radius `1.0`. When altering a peer's position, ensure the position
|
|
468
|
+
* is scaled such that the maximum distance remains one or less. This scaling can be performed
|
|
469
|
+
* manually or by specifying the multiplicative scale here.
|
|
470
|
+
*
|
|
471
|
+
* Note: It's crucial to maintain consistent scaling across all client applications.
|
|
472
|
+
* @param scale - The new scaling factor to use.
|
|
473
|
+
*/
|
|
474
|
+
setPositionScale(scale: number);
|
|
475
|
+
|
|
448
476
|
/**
|
|
449
477
|
* Closes the room and disconnects from the server.
|
|
450
478
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4players/odin-nodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "NodeJS bindings for the ODIN SDK. Use for AI enhanced human interactions, content moderation and audio processing features in a backend.",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"types": "index.d.ts",
|
|
Binary file
|
|
Binary file
|