Subscribing to an existing connection

To subscribe to an existing connection, you can use the subscribeToConnection method with the Subscribe API.

The Subscribe API enables you to connect to a conversation or a meeting in listen-only mode. Read more at Subscribe API > Try subscribing to an audio stream.

📘

Authentication

Your Symbl API Credentials, your App ID and App Secret, are required for authentication. Learn how to get them in the Authenticate section.

🚧

Import Web SDK

View the Importing section for the various ways to import the Web SDK.


(async () => {

    try {

        // We recommend to remove appId and appSecret authentication for production applications.
        // See authentication section for more details
        const symbl = new Symbl({
            appId: '<your App ID>',
            appSecret: '<your App Secret>',
            // accessToken: '<your Access Toknen>'
        });
        
        // Open a Symbl Streaming API WebSocket Connection.
        const connection = await symbl.subscribeToConnection("<YOUR SESSION ID>");

        // Retrieve real-time transcription from the conversation
        connection.on("speech_recognition", (speechData) => {
          const { punctuated } = speechData;
          const name = speechData.user ? speechData.user.name : "User";
          console.log(`${name}: `, punctuated.transcript);
        });
        
        // This is just a helper method meant for testing purposes.
        // Waits 60 seconds before continuing to the next API call.
        await Symbl.wait(60000);;
        
        // Closes the WebSocket connection.
        connection.disconnect();
    } catch(e) {
        // Handle errors here.
    }

})();