diff --git a/package.json b/package.json
index a83bb4f..a7c0e38 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,8 @@
"description": "Meetecho adapter for the Janus WebRTC Server",
"version": "1.6.9",
"type": "module",
+ "main": "src/janode.js",
+ "types": "./types/janode.d",
"keywords": [
"janus",
"webrtc",
@@ -24,16 +26,48 @@
"license": "ISC",
"main": "./src/janode.js",
"exports": {
- ".": "./src/janode.js",
- "./plugins/audiobridge": "./src/plugins/audiobridge-plugin.js",
- "./plugins/echotest": "./src/plugins/echotest-plugin.js",
- "./plugins/streaming": "./src/plugins/streaming-plugin.js",
- "./plugins/videoroom": "./src/plugins/videoroom-plugin.js"
+ ".": {
+ "import": {
+ "types": "./types/janode.d.ts",
+ "default": "./src/janode.js"
+ }
+ },
+ "./plugins/echotest": {
+ "import": {
+ "types": "./types/plugins/echotest-plugin.d.ts",
+ "default": "./src/plugins/echotest-plugin.js"
+ }
+ },
+ "./plugins/streaming": {
+ "import": {
+ "types": "./types/plugins/streaming-plugin.d.ts",
+ "default": "./src/plugins/streaming-plugin.js"
+ }
+ },
+ "./plugins/videoroom": {
+ "import": {
+ "types": "./types/plugins/videoroom-plugin.d.ts",
+ "default": "./src/plugins/videoroom-plugin.js"
+ }
+ },
+ "./plugins/audiobridge": {
+ "import": {
+ "types": "./types/plugins/audiobridge-plugin.d.ts",
+ "default": "./src/plugins/audiobridge-plugin.js"
+ }
+ },
+ "./session": {
+ "import": "./types/session.d.ts"
+ },
+ "./connection": {
+ "import": "./types/connection.d.ts"
+ }
},
"files": [
"src/*.js",
"src/utils/*.js",
- "src/plugins/*.js"
+ "src/plugins/*.js",
+ "types/**/*"
],
"dependencies": {
"isomorphic-ws": "^4.0.1",
diff --git a/types/configuration.d.ts b/types/configuration.d.ts
new file mode 100644
index 0000000..8620f34
--- /dev/null
+++ b/types/configuration.d.ts
@@ -0,0 +1,47 @@
+import { ServerObjectConf } from './janode.js'
+export default Configuration;
+/**
+ * Class representing a Janode configuration.
+ * The purpose of the class is basically filtering the input config and distinguish Janus API and Admin API connections.
+ */
+type AddressConfig = {
+ url: string
+ apisecret?: string
+}
+declare class Configuration {
+ /**
+ * Create a configuration.
+ *
+ * @private
+ * @param {module:janode~RawConfiguration} config
+ */
+ private constructor();
+ address: AddressConfig[];
+ retry_time_secs: number;
+ max_retries: number;
+ is_admin: boolean;
+ /**
+ * Get the server list of this configuration.
+ *
+ * @returns {module:janode~ServerObjectConf[]} The address array
+ */
+ getAddress(): ServerObjectConf;
+ /**
+ * Get the number of seconds between any attempt.
+ *
+ * @returns {number} The value of the property
+ */
+ getRetryTimeSeconds(): number;
+ /**
+ * Get the max number of retries.
+ *
+ * @returns {number} The value of the property
+ */
+ getMaxRetries(): number;
+ /**
+ * Check if the configuration is for an admin connection.
+ *
+ * @returns {boolean} True if the configuration will be used for an admin connection
+ */
+ isAdmin(): boolean;
+}
diff --git a/types/connection.d.ts b/types/connection.d.ts
new file mode 100644
index 0000000..e62a154
--- /dev/null
+++ b/types/connection.d.ts
@@ -0,0 +1,212 @@
+import Session from './session.js'
+import { EventEmitter } from 'events'
+export default Connection;
+/**
+ * Class representing a Janode connection.
+ *
+ * Specific transports are picked by checking the connection URI.
+ *
+ * This class implements both the Janus API and Admin API.
+ *
+ * Connection extends EventEmitter, so an instance can emit events and users can subscribe to them.
+ *
+ * Users are not expected to create Connection instances, but insted use the Janode.connect() API.
+ *
+ * @hideconstructor
+ */
+declare class Connection extends EventEmitter {
+ /**
+ * Create a Janode Connection.
+ *
+ * @param {module:configuration~Configuration} server_config - The Janode configuration as created by the Configuration constructor.
+ */
+ constructor(server_config: any);
+ /**
+ * The configuration in use for this connection.
+ *
+ * @private
+ * @type {module:configuration~Configuration}
+ */
+ private _config;
+ /**
+ * The transaction manager used by this connection.
+ *
+ * @private
+ * @type {module:tmanager~TransactionManager}
+ */
+ private _tm;
+ /**
+ * Keep track of the sessions.
+ *
+ * @private
+ * @type {Map}
+ */
+ private _sessions;
+ /**
+ * The iterator to select available Janus addresses.
+ *
+ * @private
+ * @type {module:utils~CircularIterator}
+ */
+ private _address_iterator;
+ /**
+ * A numerical identifier assigned for logging purposes.
+ *
+ * @type {number}
+ */
+ id: number;
+ /**
+ * A more descriptive, not unique string (used for logging).
+ *
+ * @type {string}
+ */
+ name: string;
+ /**
+ * The internal transport that will be used for the connection.
+ *
+ * @typedef {object} Transport
+ * @property {function} open
+ * @property {function} close
+ * @property {function} send
+ * @property {function} getRemoteHostname
+ */
+ _transport: WsTransport | UnixTransport | {
+ open: (_: any) => Promise;
+ close: (_: any) => Promise;
+ send: (_: any) => Promise;
+ getRemoteHostname: (_: any) => never;
+ };
+ /**
+ * Cleanup the connection closing all owned transactions and emitting the destroyed event
+ * and removing all registered listeners.
+ *
+ * @private
+ * @param {boolean} graceful - True if this is an expected disconnection
+ */
+ private _signalClose;
+ /**
+ * Open a connection using the transport defined open method.
+ * Users do not need to call this method, since the connection is opened by Janode.connect().
+ *
+ * @returns {Promise} A promise resolving with the Janode connection
+ */
+ open(): Promise;
+ /**
+ * Manage a message sent to this session. If a session is involved let it manage the message.
+ * If the message involves a owned transaction and the response is a definitive one,
+ * the transaction will be closed.
+ *
+ * @private
+ * @param {object} janus_message
+ */
+ private _handleMessage;
+ /**
+ * Decorate request with apisecret, token and transaction (if missing).
+ *
+ * @private
+ * @param {object} request
+ */
+ private _decorateRequest;
+ /**
+ * Gracefully close the connection using the transport defined close method.
+ *
+ * @returns {Promise}
+ */
+ close(): Promise;
+ /**
+ * Send a request from this connection using the transport defined send method.
+ *
+ * @param {object} request - The request to be sent
+ * @returns {Promise