@4players/odin-nodejs 0.8.0 → 0.9.1
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/odinclient.cpp
CHANGED
|
@@ -46,6 +46,7 @@ OdinClient::OdinClient(const Napi::CallbackInfo& info) : Napi::ObjectWrap<OdinCl
|
|
|
46
46
|
|
|
47
47
|
if (info.Length() < 1 || !info[0].IsString()) {
|
|
48
48
|
Napi::TypeError::New(env, "Access Key required as first parameter").ThrowAsJavaScriptException();
|
|
49
|
+
return;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
_accessKey = info[0].ToString().Utf8Value();
|
|
@@ -57,6 +58,7 @@ OdinClient::OdinClient(const Napi::CallbackInfo& info) : Napi::ObjectWrap<OdinCl
|
|
|
57
58
|
_sampleRate = info[1].ToNumber();
|
|
58
59
|
} else {
|
|
59
60
|
Napi::TypeError::New(env, "Sample rate must be a number").ThrowAsJavaScriptException();
|
|
61
|
+
return;
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -65,6 +67,7 @@ OdinClient::OdinClient(const Napi::CallbackInfo& info) : Napi::ObjectWrap<OdinCl
|
|
|
65
67
|
_numChannels = info[2].ToNumber();
|
|
66
68
|
} else {
|
|
67
69
|
Napi::TypeError::New(env, "Channels must be a number").ThrowAsJavaScriptException();
|
|
70
|
+
return;
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -98,6 +101,7 @@ Napi::Value OdinClient::GenerateAccessToken(const Napi::CallbackInfo &info)
|
|
|
98
101
|
|
|
99
102
|
if (info.Length() != 2 || !info[0].IsString() || !info[1].IsString()) {
|
|
100
103
|
Napi::TypeError::New(env, "Room and User Id expected").ThrowAsJavaScriptException();
|
|
104
|
+
return env.Undefined();
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
std::string roomId = info[0].ToString().Utf8Value();
|
|
@@ -107,6 +111,7 @@ Napi::Value OdinClient::GenerateAccessToken(const Napi::CallbackInfo &info)
|
|
|
107
111
|
if (!generator)
|
|
108
112
|
{
|
|
109
113
|
Napi::TypeError::New(env, "Failed to initialize token generator, invalid access key").ThrowAsJavaScriptException();
|
|
114
|
+
return env.Undefined();
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
/*
|
|
@@ -117,6 +122,7 @@ Napi::Value OdinClient::GenerateAccessToken(const Napi::CallbackInfo &info)
|
|
|
117
122
|
if (odin_is_error(error))
|
|
118
123
|
{
|
|
119
124
|
Napi::TypeError::New(env, "Creating access token failed").ThrowAsJavaScriptException();
|
|
125
|
+
return env.Undefined();
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
/*
|
|
@@ -137,6 +143,7 @@ Napi::Value OdinClient::CreateRoom(const Napi::CallbackInfo &info) {
|
|
|
137
143
|
|
|
138
144
|
if (info.Length() != 2 || !info[0].IsString() || !info[1].IsString()) {
|
|
139
145
|
Napi::TypeError::New(env, "Room and User Id expected").ThrowAsJavaScriptException();
|
|
146
|
+
return env.Undefined();
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
std::string roomId = info[0].ToString().Utf8Value();
|
package/cppsrc/odinmedia.cpp
CHANGED
|
@@ -25,6 +25,7 @@ Napi::Value OdinMedia::MediaId(const Napi::CallbackInfo &info) {
|
|
|
25
25
|
OdinReturnCode error = odin_media_stream_media_id(_mediaStreamHandle, &out_id);
|
|
26
26
|
if (odin_is_error(error)) {
|
|
27
27
|
Napi::TypeError::New(env, "Failed to get media id").ThrowAsJavaScriptException();
|
|
28
|
+
return env.Undefined();
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
return Napi::Number::New(env, out_id);
|
|
@@ -41,10 +42,12 @@ OdinMedia::OdinMedia(const Napi::CallbackInfo &info) : Napi::ObjectWrap<OdinMedi
|
|
|
41
42
|
// Checking for room instance, sample rate (float) and channels (int)
|
|
42
43
|
if (info.Length() < 3 || !info[0].IsObject() || !info[1].IsNumber() || !info[2].IsNumber()) {
|
|
43
44
|
Napi::TypeError::New(env, "Provide an OdinRoom instance, sample rate and number of channels as number").ThrowAsJavaScriptException();
|
|
45
|
+
return;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
if (info.Length() == 4 && !info[3].IsObject()) {
|
|
47
49
|
Napi::TypeError::New(env, "Options need to be provided as an object").ThrowAsJavaScriptException();
|
|
50
|
+
return;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
_room = Napi::ObjectWrap<OdinRoom>::Unwrap(info[0].As<Napi::Object>());
|
|
@@ -227,6 +230,7 @@ void OdinMedia::SendData(const Napi::CallbackInfo &info) {
|
|
|
227
230
|
|
|
228
231
|
if (info.Length() < 1 || !info[0].IsTypedArray()) {
|
|
229
232
|
Napi::TypeError::New(env, "TypedArray required as first parameter").ThrowAsJavaScriptException();
|
|
233
|
+
return;
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
Napi::Float32Array array = info[0].As<Napi::Float32Array>();
|
package/cppsrc/odinroom.cpp
CHANGED
|
@@ -114,6 +114,7 @@ Napi::Value OdinRoom::RoomId(const Napi::CallbackInfo &info) {
|
|
|
114
114
|
if (odin_is_error(error))
|
|
115
115
|
{
|
|
116
116
|
Napi::TypeError::New(env, "Failed to get room id").ThrowAsJavaScriptException();
|
|
117
|
+
return env.Undefined();
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
return Napi::String::New(env, out_id);
|
|
@@ -303,6 +304,7 @@ OdinRoom::OdinRoom(const Napi::CallbackInfo& info) :Napi::ObjectWrap<OdinRoom>(i
|
|
|
303
304
|
|
|
304
305
|
if (info.Length() != 1 || !info[0].IsString()) {
|
|
305
306
|
Napi::TypeError::New(env, "Provide a token to create a room").ThrowAsJavaScriptException();
|
|
307
|
+
return;
|
|
306
308
|
}
|
|
307
309
|
|
|
308
310
|
_token = info[0].ToString().Utf8Value();
|
|
@@ -331,6 +333,8 @@ Napi::Object OdinRoom::Init(Napi::Env env, Napi::Object exports) {
|
|
|
331
333
|
Napi::Function func = DefineClass(env, "OdinRoom", {
|
|
332
334
|
InstanceMethod<&OdinRoom::Join>("join", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
333
335
|
InstanceMethod<&OdinRoom::UpdatePeerUserData>("updateOwnUserData", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
336
|
+
InstanceMethod<&OdinRoom::UpdatePosition>("updatePosition", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
337
|
+
InstanceMethod<&OdinRoom::SetPositionScale>("setPositionScale", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
334
338
|
InstanceMethod<&OdinRoom::SendMessage>("sendMessage", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
335
339
|
InstanceMethod<&OdinRoom::SetEventListener>("setEventListener", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
336
340
|
InstanceMethod<&OdinRoom::AddEventListener>("addEventListener", static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
|
|
@@ -365,6 +369,52 @@ Napi::Object OdinRoom::Init(Napi::Env env, Napi::Object exports) {
|
|
|
365
369
|
return exports;
|
|
366
370
|
}
|
|
367
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Updates the position of this room. Requires x, y and z coordinates as parameters.
|
|
374
|
+
* @param info Napi::CallbackInfo
|
|
375
|
+
*/
|
|
376
|
+
void OdinRoom::UpdatePosition(const Napi::CallbackInfo &info)
|
|
377
|
+
{
|
|
378
|
+
Napi::Env env = info.Env();
|
|
379
|
+
|
|
380
|
+
if (info.Length() != 3 || !info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber()) {
|
|
381
|
+
Napi::TypeError::New(env, "Provide x, y and z coordinates as numbers").ThrowAsJavaScriptException();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
float x = info[0].ToNumber();
|
|
386
|
+
float y = info[1].ToNumber();
|
|
387
|
+
float z = info[2].ToNumber();
|
|
388
|
+
|
|
389
|
+
OdinReturnCode error = odin_room_update_position(_roomHandle, x, y, z);
|
|
390
|
+
if (odin_is_error(error))
|
|
391
|
+
{
|
|
392
|
+
OdinUtilities::ThrowNapiException(env, error, "Failed to update position");
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Sets the position scale for this room. Requires a scale as a parameter.
|
|
398
|
+
* @param info Napi::CallbackInfo
|
|
399
|
+
*/
|
|
400
|
+
void OdinRoom::SetPositionScale(const Napi::CallbackInfo &info)
|
|
401
|
+
{
|
|
402
|
+
Napi::Env env = info.Env();
|
|
403
|
+
|
|
404
|
+
if (info.Length() != 1 || !info[0].IsNumber()) {
|
|
405
|
+
Napi::TypeError::New(env, "Provide scale as number").ThrowAsJavaScriptException();
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
float scale = info[0].ToNumber();
|
|
410
|
+
|
|
411
|
+
OdinReturnCode error = odin_room_set_position_scale(_roomHandle, scale);
|
|
412
|
+
if (odin_is_error(error))
|
|
413
|
+
{
|
|
414
|
+
OdinUtilities::ThrowNapiException(env, error, "Failed to set position scale");
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
368
418
|
/**
|
|
369
419
|
* Joins the Odin room. Requires a gateway URL as a parameter and optionally initial peer data.
|
|
370
420
|
* @param info Napi::CallbackInfo
|
|
@@ -374,6 +424,7 @@ void OdinRoom::Join(const Napi::CallbackInfo &info) {
|
|
|
374
424
|
|
|
375
425
|
if (info.Length() < 1) {
|
|
376
426
|
Napi::TypeError::New(env, "Gateway required as first parameter").ThrowAsJavaScriptException();
|
|
427
|
+
return;
|
|
377
428
|
}
|
|
378
429
|
|
|
379
430
|
std::string url = info[0].ToString().Utf8Value();
|
|
@@ -391,6 +442,7 @@ void OdinRoom::Join(const Napi::CallbackInfo &info) {
|
|
|
391
442
|
if (odin_is_error(error))
|
|
392
443
|
{
|
|
393
444
|
OdinUtilities::ThrowNapiException(env, error, "Failed to join room");
|
|
445
|
+
return;
|
|
394
446
|
}
|
|
395
447
|
|
|
396
448
|
_joined = true;
|
|
@@ -439,6 +491,7 @@ Napi::Value OdinRoom::CreateNewItem(const Napi::CallbackInfo& info) {
|
|
|
439
491
|
|
|
440
492
|
if (info.Length() < 1) {
|
|
441
493
|
Napi::TypeError::New(env, "Token required as first parameter").ThrowAsJavaScriptException();
|
|
494
|
+
return env.Undefined();
|
|
442
495
|
}
|
|
443
496
|
|
|
444
497
|
Napi::String token = info[0].ToString();
|
|
@@ -470,6 +523,7 @@ void OdinRoom::UpdatePeerUserData(const Napi::CallbackInfo &info) {
|
|
|
470
523
|
|
|
471
524
|
if (info.Length() != 1 || !info[0].IsTypedArray()) {
|
|
472
525
|
Napi::TypeError::New(env, "Data as byte array expected").ThrowAsJavaScriptException();
|
|
526
|
+
return;
|
|
473
527
|
}
|
|
474
528
|
|
|
475
529
|
Napi::Uint8Array data = info[0].As<Napi::Uint8Array>();
|
|
@@ -494,6 +548,7 @@ void OdinRoom::SendMessage(const Napi::CallbackInfo &info) {
|
|
|
494
548
|
|
|
495
549
|
if (info.Length() < 1 || !info[0].IsTypedArray()) {
|
|
496
550
|
Napi::TypeError::New(env, "Data as byte array expected").ThrowAsJavaScriptException();
|
|
551
|
+
return;
|
|
497
552
|
}
|
|
498
553
|
|
|
499
554
|
Napi::Uint8Array data = info[0].As<Napi::Uint8Array>();
|
|
@@ -535,6 +590,7 @@ void OdinRoom::SetEventListener(const Napi::CallbackInfo &info) {
|
|
|
535
590
|
|
|
536
591
|
if (info.Length() != 1 || !info[0].IsFunction()) {
|
|
537
592
|
Napi::TypeError::New(env, "Callback function expected").ThrowAsJavaScriptException();
|
|
593
|
+
return;
|
|
538
594
|
}
|
|
539
595
|
|
|
540
596
|
Napi::Function napiFunction = info[0].As<Napi::Function>();
|
|
@@ -552,6 +608,7 @@ void OdinRoom::AddEventListener(const Napi::CallbackInfo &info) {
|
|
|
552
608
|
|
|
553
609
|
if (info.Length() != 2 || !info[0].IsString() || !info[1].IsFunction()) {
|
|
554
610
|
Napi::TypeError::New(env, "Event Name and Callback function expected").ThrowAsJavaScriptException();
|
|
611
|
+
return;
|
|
555
612
|
}
|
|
556
613
|
|
|
557
614
|
std::string eventName = info[0].As<Napi::String>().Utf8Value();
|
|
@@ -586,6 +643,7 @@ void OdinRoom::RemoveEventListener(const Napi::CallbackInfo &info) {
|
|
|
586
643
|
|
|
587
644
|
if (info.Length() != 1 || !info[0].IsString()) {
|
|
588
645
|
Napi::TypeError::New(env, "Event Name expected").ThrowAsJavaScriptException();
|
|
646
|
+
return;
|
|
589
647
|
}
|
|
590
648
|
|
|
591
649
|
std::string eventName = info[0].As<Napi::String>().Utf8Value();
|
|
@@ -688,10 +746,12 @@ Napi::Value OdinRoom::CreateAudioStream(const Napi::CallbackInfo &info)
|
|
|
688
746
|
// Checking for input of sample rate (int) and number of channels (int)
|
|
689
747
|
if (info.Length() != 2 || !info[0].IsNumber() || !info[1].IsNumber()) {
|
|
690
748
|
Napi::TypeError::New(env, "Sample rate and number of channels expected").ThrowAsJavaScriptException();
|
|
749
|
+
return env.Undefined();
|
|
691
750
|
}
|
|
692
751
|
|
|
693
752
|
if (info.Length() == 3 && !info[2].IsObject()) {
|
|
694
753
|
Napi::TypeError::New(env, "Options need to be an object").ThrowAsJavaScriptException();
|
|
754
|
+
return env.Undefined();
|
|
695
755
|
}
|
|
696
756
|
|
|
697
757
|
if (info.Length() == 2) {
|
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.1",
|
|
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
|