@4players/odin-nodejs 0.7.1 → 0.7.3

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.
@@ -617,7 +617,8 @@ void OdinRoom::RemoveEventListener(const Napi::CallbackInfo &info) {
617
617
  _eventListeners[eventName].Release();
618
618
  _eventListeners.erase(eventName);
619
619
  } else {
620
- _audioDataReceivedEventListener.Release();
620
+ // Stop the native thread and this will also release the callback function
621
+ _started = false;
621
622
  }
622
623
  }
623
624
 
@@ -699,6 +700,7 @@ void OdinRoom::HandleAudioData()
699
700
 
700
701
  // Release the thread-safe function
701
702
  _audioDataReceivedEventListener.Release();
703
+ _audioDataReceivedEventListener = NULL;
702
704
  } );
703
705
  }
704
706
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4players/odin-nodejs",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "",
5
5
  "main": "index.cjs",
6
6
  "types": "index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "gypfile": true,
19
19
  "type": "module",
20
20
  "dependencies": {
21
- "@4players/odin-foundation": "^0.1.3",
21
+ "@4players/odin-foundation": "^0.2.0",
22
22
  "@4players/odin-tokens": "^1.3.0",
23
23
  "audio-buffer-stream": "^1.1.0",
24
24
  "audio-decode": "^2.1.1",
@@ -27,7 +27,6 @@
27
27
  "node-gyp-build": "^4.6.0",
28
28
  "openai": "^3.2.1",
29
29
  "prompt-sync": "^4.2.0",
30
- "segfault-handler": "^1.3.0",
31
30
  "throttle": "^1.0.3",
32
31
  "wav": "^1.0.2"
33
32
  },
package/test.js DELETED
@@ -1,211 +0,0 @@
1
- const accessKey = "Ad4R7/hpCx1U5yGvC61oNBeJ/fWiW7dodvXWW7MEwrjg";
2
- const roomName = "Hallo";
3
- const userName = "My Bot";
4
-
5
- import odin from '../../index.cjs';
6
- const {OdinRoom, OdinClient} = odin;
7
-
8
- import wav from 'wav';
9
- import { Configuration, OpenAIApi } from "openai";
10
- import fs from 'fs';
11
-
12
- const configuration = new Configuration({
13
- apiKey: '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'
14
- });
15
- const openai = new OpenAIApi(configuration);
16
-
17
- //const token = odin.generateAccessToken(accessKey, roomName, userName);
18
- //console.log(token);
19
-
20
- const userData = {
21
- name: "Recorder Bot",
22
- seed: "123",
23
- userId: "Bot007",
24
- outputMuted: 1,
25
- platform: "ODIN JS Bot SDK",
26
- version: "0.1"
27
- }
28
-
29
- const fileRecorder = {};
30
-
31
- const data = new TextEncoder().encode(JSON.stringify(userData));
32
-
33
- const odinClient = new OdinClient(accessKey);
34
- const room2 = odinClient.createRoom(roomName, userName);
35
-
36
-
37
- //odin.startup();
38
-
39
- //room2 = odin.initRoom(token);
40
- room2.setEventListener((event) => {
41
- console.log(event);
42
- });
43
-
44
- room2.addEventListener('PeerJoined', (event) => {
45
- console.log("Received PeerJoined event", event);
46
- console.log(JSON.parse(new TextDecoder().decode(event.userData)));
47
- });
48
-
49
- room2.addEventListener('PeerLeft', (event) => {
50
- console.log("Received PeerLeft event", event);
51
- });
52
-
53
- room2.addEventListener('MediaActivity', (event) => {
54
- console.log("Media", event);
55
- if (event.state) {
56
- // User started talking
57
- if (!fileRecorder[event.mediaId]) {
58
- const timer = new Date().getTime();
59
- const fileName = `./recording_${event.peerId}_${event.mediaId}_${timer}.wav`;
60
- console.log(fileName);
61
- fileRecorder[event.mediaId] = {
62
- wavEncoder: new wav.FileWriter(fileName, {
63
- channels: 1,
64
- sampleRate: 48000,
65
- bitDepth: 16
66
- }),
67
- fileName: fileName
68
- };
69
- } else {
70
- if (fileRecorder[event.mediaId].timer) {
71
- clearTimeout(fileRecorder[event.mediaId].timer);
72
- delete fileRecorder[event.mediaId].timer;
73
- }
74
- }
75
- } else {
76
- // User stopped talking
77
- if (fileRecorder[event.mediaId]) {
78
- if (!fileRecorder[event.mediaId].timer) {
79
- fileRecorder[event.mediaId].timer = setTimeout(() => {
80
- fileRecorder[event.mediaId].wavEncoder.end();
81
-
82
- try {
83
- const file = fs.createReadStream(fileRecorder[event.mediaId].fileName);
84
- openai.createTranscription(file, "whisper-1").then((response) => {
85
- console.log("TRANSACTION", response.data.text);
86
- });
87
- } catch (e) {
88
- console.log("Failed to transcribe: ", e);
89
- }
90
-
91
-
92
- delete fileRecorder[event.mediaId];
93
- }, 2000);
94
- }
95
- }
96
- }
97
- });
98
-
99
- //const input = prompt('Press any key?');
100
- //const odinClient = new OdinClient(accessKey);
101
- //const room2 = new OdinRoom(token);
102
-
103
- room2.join("gateway.odin.4players.io", data);
104
-
105
- console.log("ROOM-ID:", room2.id);
106
-
107
- const message = {
108
- kind: 'message',
109
- payload: {
110
- text: 'Hello World'
111
- }
112
- }
113
-
114
- const fileWriter = new wav.FileWriter('./recording.wav', {
115
- channels: 1,
116
- sampleRate: 48000,
117
- bitDepth: 16
118
- });
119
-
120
- room2.addEventListener('AudioDataReceived', (data) => {
121
- //console.log("Received AudioDataReceived event from peer", data.peerId, "with mediaId", data.mediaId, "and event", data.samples32);
122
- //console.log(Float32Array.from(data.samples32));
123
-
124
- // Getting an array of the sample buffer
125
- /*
126
- let ui32 = new Float32Array(data.samples32.buffer);
127
- console.log(ui32);
128
-
129
- let ui16 = new Int16Array(data.samples16.buffer);
130
- console.log(ui16);
131
- */
132
-
133
- fileWriter.file.write(data.samples16, (error) => {
134
-
135
- });
136
-
137
-
138
- if (fileRecorder[data.mediaId]) {
139
- fileRecorder[data.mediaId].wavEncoder.file.write(data.samples16, (error) => {
140
- if (error) {
141
- console.log("Failed to write audio file");
142
- }
143
- });
144
- }
145
- });
146
-
147
- room2.sendMessage(new TextEncoder().encode(JSON.stringify(message)));
148
-
149
- console.log("Press any key to stop");
150
- const stdin = process.stdin;
151
- stdin.resume();
152
- stdin.setEncoding( 'utf8' );
153
- stdin.on( 'data', function( key )
154
- {
155
- console.log("Shutting down");
156
- room2.close();
157
- fileWriter.end();
158
-
159
- process.exit();
160
- });
161
-
162
-
163
-
164
- /*
165
- const room = odin.createRoom();
166
-
167
- let error = 0;
168
- try {
169
- error = odin.joinRoom(room, "gateway.odin.4players.io", token);
170
- } catch(e) {
171
- console.log(error);
172
- console.log(odin.formatError(error));
173
- }
174
-
175
- const userData = {
176
- name: "Recorder Bot",
177
- seed: "123",
178
- userId: "Bot007",
179
- outputMuted: 1,
180
- platform: "ODIN JS Bot SDK",
181
- version: "0.1"
182
- }
183
-
184
- const data = new TextEncoder().encode(JSON.stringify(userData));
185
-
186
- odin.updatePeerUserData(room, data);
187
- */
188
- //const name = prompt('Press any key?');
189
- /*
190
- odin.closeRoom(room);
191
- odin.destroyRoom(room);
192
- odin.shutdown();
193
- */
194
- /*
195
-
196
- const tokenGenerator = new TokenGenerator(accessKey);
197
- const token = tokenGenerator.createToken(roomName, userName);
198
-
199
- console.log(token);
200
-
201
- const testAddon = require('./build/Release/testaddon.node')
202
- console.log(testAddon.hello());
203
- console.log(testAddon.add(5,10));
204
-
205
- const classInstance = new testAddon.ClassExample(4.3);
206
- console.log('Testing class initial value : ',classInstance.getValue());
207
- console.log('After adding 3.3 : ',classInstance.add(3.3));
208
-
209
- const odinClient = new testAddon.OdinClient();
210
- odinClient.joinRoom(accessKey, roomName, userName);
211
- */