@4players/odin-plugin-web 1.0.0-alpha.9 → 1.0.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/cmake/dependencies.cmake +31 -0
  3. package/cmake/options.cmake +53 -0
  4. package/esbuild.config.ts +49 -0
  5. package/lib/plugin/index.d.ts +42 -49
  6. package/lib/plugin/index.js +1 -292
  7. package/lib/worker/shared.js +1 -0
  8. package/lib/worker/unshared.js +1 -0
  9. package/package.json +34 -29
  10. package/lib/plugin/audioController.d.ts +0 -107
  11. package/lib/plugin/audioController.js +0 -488
  12. package/lib/plugin/config.d.ts +0 -10
  13. package/lib/plugin/config.js +0 -10
  14. package/lib/plugin/connectionPool.d.ts +0 -16
  15. package/lib/plugin/connectionPool.js +0 -110
  16. package/lib/plugin/mainConnection.d.ts +0 -39
  17. package/lib/plugin/mainConnection.js +0 -293
  18. package/lib/plugin/roomConnection.d.ts +0 -36
  19. package/lib/plugin/roomConnection.js +0 -303
  20. package/lib/plugin/rpcConnection.d.ts +0 -48
  21. package/lib/plugin/rpcConnection.js +0 -234
  22. package/lib/plugin/token.d.ts +0 -17
  23. package/lib/plugin/token.js +0 -78
  24. package/lib/wasm/index.d.ts +0 -97
  25. package/lib/worker/buffers.d.ts +0 -42
  26. package/lib/worker/buffers.js +0 -79
  27. package/lib/worker/common.d.ts +0 -45
  28. package/lib/worker/common.js +0 -7
  29. package/lib/worker/config.d.ts +0 -8
  30. package/lib/worker/config.js +0 -11
  31. package/lib/worker/index.d.ts +0 -3
  32. package/lib/worker/index.js +0 -1
  33. package/lib/worker/memory.d.ts +0 -9
  34. package/lib/worker/memory.js +0 -29
  35. package/lib/worker/messages.d.ts +0 -14
  36. package/lib/worker/messages.js +0 -15
  37. package/lib/worker/packet.d.ts +0 -11
  38. package/lib/worker/packet.js +0 -59
  39. package/lib/worker/shared/capture.d.ts +0 -28
  40. package/lib/worker/shared/capture.js +0 -63
  41. package/lib/worker/shared/index.d.ts +0 -3
  42. package/lib/worker/shared/index.js +0 -148
  43. package/lib/worker/shared/messages.d.ts +0 -67
  44. package/lib/worker/shared/messages.js +0 -64
  45. package/lib/worker/shared/playback.d.ts +0 -21
  46. package/lib/worker/shared/playback.js +0 -78
  47. package/lib/worker/unshared/capture.d.ts +0 -28
  48. package/lib/worker/unshared/capture.js +0 -66
  49. package/lib/worker/unshared/index.d.ts +0 -3
  50. package/lib/worker/unshared/index.js +0 -171
  51. package/lib/worker/unshared/messages.d.ts +0 -81
  52. package/lib/worker/unshared/messages.js +0 -80
  53. package/lib/worker/unshared/playback.d.ts +0 -23
  54. package/lib/worker/unshared/playback.js +0 -83
package/README.md CHANGED
@@ -14,7 +14,7 @@ Contact us through the listed methods below to receive answers to your questions
14
14
 
15
15
  Join our official Discord server to chat with us directly and become a part of the 4Players ODIN community.
16
16
 
17
- [![Join us on Discord](https://developers.4players.io/images/join_discord.png)](https://4np.de/discord)
17
+ [![Join us on Discord](https://www.4players.io/images/join_discord.png)](https://4np.de/discord)
18
18
 
19
19
  ### Twitter
20
20
 
@@ -0,0 +1,31 @@
1
+ include(FetchContent)
2
+
3
+ ### Opus audio codec
4
+
5
+ message(STATUS "Installing Opus audio codec")
6
+
7
+ set(OPUS_BUILD_SHARED_LIBRARY CACHE BOOL OFF FORCE)
8
+ set(OPUS_BUILD_PROGRAMS CACHE BOOL ON FORCE)
9
+ set(OPUS_BUILD_TESTING CACHE BOOL OFF FORCE)
10
+ set(BUILD_TESTING CACHE BOOL OFF FORCE)
11
+ set(STACK_PROTECTOR_SUPPORTED CACHE BOOL OFF FORCE)
12
+ set(FORTIFY_SOURCE_SUPPORTED CACHE BOOL OFF FORCE)
13
+
14
+ FetchContent_Declare(
15
+ opus
16
+ GIT_REPOSITORY https://gitlab.4players.de/odin/deps/opus.git
17
+ GIT_TAG v1.5.2
18
+ )
19
+ FetchContent_MakeAvailable(opus)
20
+ target_link_libraries(${CMAKE_EXECUTABLE_NAME} PUBLIC opus)
21
+
22
+ ### RNN VAD
23
+
24
+ message(STATUS "Installing RNN VAD")
25
+
26
+ FetchContent_Declare(
27
+ rnn_vad
28
+ GIT_REPOSITORY https://gitlab.4players.de/odin/deps/rnn-vad.git
29
+ )
30
+ FetchContent_MakeAvailable(rnn_vad)
31
+ target_link_libraries(${CMAKE_EXECUTABLE_NAME} PUBLIC rnn_vad)
@@ -0,0 +1,53 @@
1
+ ### Set global compiler flags
2
+
3
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
4
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
5
+
6
+ ### Set compiler flags for the release configuration
7
+
8
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
9
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
10
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O3")
11
+
12
+ ### Set compiler flags for the debug configuration
13
+
14
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
15
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
16
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g")
17
+
18
+ ### Conditional logic to include pthread when SharedArrayBuffer is enabled
19
+
20
+ if(NOT DEFINED SHARED_MEMORY)
21
+ message(STATUS "Enabling SharedArrayBuffer")
22
+
23
+ set(EXPORT_NAME "OdinWasmUnsharedMemory")
24
+ set(SHARED_MEMORY 0)
25
+ else()
26
+ message(STATUS "Disabling SharedArrayBuffer")
27
+
28
+ set(EXPORT_NAME "OdinWasmSharedMemory")
29
+ set(SHARED_MEMORY 1)
30
+
31
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pthread")
32
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -pthread")
33
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pthread")
34
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pthread")
35
+ endif()
36
+
37
+ ### Set flags for WebAssembly target output
38
+
39
+ set_target_properties(${CMAKE_EXECUTABLE_NAME} PROPERTIES
40
+ CXX_STANDARD 20
41
+ LINK_FLAGS "--bind \
42
+ -s SHARED_MEMORY=${SHARED_MEMORY} \
43
+ -s EXPORT_NAME=Load${EXPORT_NAME} \
44
+ -s MODULARIZE=1 \
45
+ -s WASM=1 \
46
+ -s SINGLE_FILE=1 \
47
+ -s ALLOW_TABLE_GROWTH=1 \
48
+ -s BINARYEN_ASYNC_COMPILATION=0 \
49
+ -s FILESYSTEM=0 \
50
+ -s ENVIRONMENT=web,worker \
51
+ -s EXPORTED_FUNCTIONS=_malloc,_free \
52
+ -s EXPORTED_RUNTIME_METHODS=HEAPU8,HEAPF32,HEAPU32,HEAP32"
53
+ )
@@ -0,0 +1,49 @@
1
+ import * as esbuild from 'esbuild';
2
+ import type { BuildOptions } from 'esbuild'; // Optional: for type safety
3
+
4
+ const packageVersion = process.env.npm_package_version;
5
+ const distPath = 'dist/plugin';
6
+
7
+ if (!packageVersion) {
8
+ console.error(
9
+ 'Error: npm_package_version is not set. Please run this script using an npm script (e.g., npm run bundle).'
10
+ );
11
+ process.exit(1);
12
+ }
13
+
14
+ const sharedConfig: BuildOptions = {
15
+ entryPoints: ['lib/plugin/index.js'],
16
+ bundle: true,
17
+ minify: true,
18
+ platform: 'browser',
19
+ };
20
+
21
+ async function main() {
22
+ console.log(`Starting esbuild for version: ${packageVersion}`);
23
+ try {
24
+ // IIFE Build
25
+ let path = `${distPath}/${packageVersion}/odin-plugin.js`;
26
+ await esbuild.build({
27
+ ...sharedConfig,
28
+ format: 'iife',
29
+ globalName: 'ODIN_PLUGIN',
30
+ outfile: path,
31
+ });
32
+ console.log(`Successfully built: ${path}`);
33
+ path = `${distPath}/${packageVersion}/odin-plugin.esm.js`;
34
+ // ESM Build
35
+ await esbuild.build({
36
+ ...sharedConfig,
37
+ format: 'esm',
38
+ outfile: path,
39
+ });
40
+ console.log(`Successfully built: ${path}.js`);
41
+ console.log('Build completed successfully.');
42
+ } catch (error) {
43
+ console.error('Build failed:');
44
+ console.error(error);
45
+ process.exit(1);
46
+ }
47
+ }
48
+
49
+ main().catch(console.error);
@@ -1,52 +1,45 @@
1
- import { ConnectionPool } from './connectionPool';
2
- import { Backend } from '@4players/odin-common';
3
- import { AudioCapture, AudioContextFactory, AudioPlayback, CreateAudioCaptureParameters, CreateAudioPlaybackParameters, Device, Volume } from './audioController';
4
- import { MainConnection } from './mainConnection';
5
- export type Media = Backend.Media;
6
- export type JoinRoomParameters = Backend.JoinRoomParameters;
7
- export interface DeviceParameters {
8
- readonly device?: Device;
9
- onStatusChanged?: Backend.OnStatusChanged;
1
+ import { Backend, LogRecord, Logger } from '@4players/odin-common';
2
+
3
+ export type OnLogMessage = (formattedString: string, record: LogRecord) => void;
4
+ export type VifConfig = {
5
+ enabled: true;
6
+ attenuationLimit: number;
7
+ postFilterBeta: number;
8
+ } | {
9
+ enabled: false;
10
+ };
11
+ export type CreateAudioCaptureParameters = Backend.CreateAudioCaptureParameters & {
12
+ readonly device?: WebDevice;
13
+ };
14
+ export type AudioContextFactory = (sampleRate: number | undefined) => Promise<AudioContext>;
15
+ export type DeviceInfo = {
16
+ name: string;
17
+ deviceId: string;
18
+ kind: "audioinput" | "audiooutput";
19
+ };
20
+ export interface WebDevice extends Backend.Device {
21
+ readonly device: DeviceInfo;
10
22
  }
11
- export declare class WebPlugin implements Backend.Plugin {
12
- readonly version = "1";
13
- private _NextRoomId;
14
- private _PlaybackVolume;
15
- private readonly _ConnectionPool;
16
- private readonly _AudioController;
17
- get playbackVolume(): Backend.Volume;
18
- static create(audioContextFactory: AudioContextFactory): Promise<WebPlugin>;
19
- private constructor();
20
- joinRoom(parameters: JoinRoomParameters): Room;
21
- createAudioPlayback(parameters: CreateAudioPlaybackParameters): Promise<AudioPlayback>;
22
- createAudioCapture(parameters: CreateAudioCaptureParameters): Promise<AudioCapture>;
23
- enumerateDevices(): Promise<Device[]>;
24
- setOutputVolume(volume: Volume): void;
25
- setOutputDevice(device: DeviceParameters): Promise<void>;
26
- close(): void;
23
+ export interface WebDeviceParameters extends Backend.DeviceParameters {
24
+ readonly device?: WebDevice;
25
+ onStatusChanged?: Backend.OnStatusChanged;
27
26
  }
28
- export declare class Room implements Backend.Room {
29
- private readonly _Id;
30
- private readonly _Connection;
31
- private readonly _OnEvent;
32
- private readonly _Captures;
33
- private readonly _Playbacks;
34
- private readonly _Peers;
35
- private readonly _AvailableMediaIds;
36
- get mainConnection(): MainConnection | undefined;
37
- constructor(id: number, connectionPool: ConnectionPool, parameters: JoinRoomParameters);
38
- request(method: string, properties: unknown): Promise<unknown>;
39
- link(media: Media): void;
40
- unlink(media: Media): void;
41
- close(): void;
42
- private _HandleEvent;
43
- private _HandleKnownEvent;
44
- private _HandleConnectionLost;
45
- private _HandleRoomUpdate;
46
- private _HandleRoomJoined;
47
- private _HandlePeerUpdate;
48
- private _HandlePeerJoined;
49
- private _HandlePeerLeft;
50
- private _HandleMediaStart;
51
- private _HandleMediaStopped;
27
+ export declare function createPlugin(audioContextFactory: AudioContextFactory, options?: WebPluginOptions): WebPlugin;
28
+ export interface WebPluginOptions {
29
+ logger?: Logger;
30
+ onLogMessage?: OnLogMessage;
52
31
  }
32
+ export declare const SESSION_ID: string;
33
+ export interface WebPlugin extends Backend.Plugin {
34
+ joinRoom(parameters: Backend.JoinRoomParameters): WebRoom;
35
+ enumerateDevices(): Promise<WebDevice[]>;
36
+ setOutputDevice(device: WebDeviceParameters): Promise<void>;
37
+ createAudioCapture(parameters: CreateAudioCaptureParameters): Promise<WebAudioCapture>;
38
+ }
39
+ export interface WebRoom extends Backend.Room {
40
+ }
41
+ export interface WebAudioCapture extends Backend.AudioCapture {
42
+ setVif(config: VifConfig): void;
43
+ }
44
+
45
+ export {};