Manual install
Updated
Install the Signaling SDK for your platform, using a package manager or a downloaded package.
To manually install the Signaling SDK for Web, do one of the following:
Through the Agora website
-
Extract the files in Agora Signaling SDK to a local folder. In the SDK folder, find the JS file in the
libsfolder, and save it to your project directory. -
Open the HTML file in your project directory, and add the following code to refer to the JS file:
<script src="path to the JS file"></script> -
To enable smart completions and type checking, take the following steps:
-
Go to
libs/agora-rtm-sdk.d.tsin the SDK folder, and save the TS file to your project directory. -
Add the following line to the beginning of the JS or TS file. Replace
path to the TS filewith the path toagora-rtm-sdk.d.ts./// <reference path="path to the TS file" />
-
Through npm
-
In
package.jsonfor your project, addagora-rtm-sdkand its version number to thedependenciesfield:"dependencies": { "agora-rtm-sdk": "^2.1.4-beta.0", "cors-anywhere": "^0.4.4", "livereload-js": "^4.0.1", "url": "^0.11.1" }, -
Install the dependencies:
pnpm install -
In your code, import
RTMfromagora-rtm-sdk:// Import the SDK import AgoraRTM from 'agora-rtm-sdk'; // Create a client instance const signalingEngine = new AgoraRTM.RTM('app-id', 'user-id', { token: 'temporary-token' }); // Listen for events signalingEngine.addEventListener('message', (eventArgs) => { console.log(`${eventArgs.publisher}: ${eventArgs.message}`); }); // Login try { await signalingEngine.login(); } catch (err) { console.log({ err }, 'error occurs at login.'); } // Send channel message try { await signalingEngine.publish('channel', 'hello world'); } catch (err) { console.log({ err }, 'error occurs at publish message'); }
