News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Encountering 'Cannot read properties of undefined (reading 'addEventListener')' within my application
Tags: errors, subscription, sdk
Feb 27, 2024 at 10:33am   •   1 replies  •  0 likes
Dev Admin

/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/subscription.js:22

this.wse.ws.addEventListener('message', this.eventListener);

^


TypeError: Cannot read properties of undefined (reading 'addEventListener')

at Subscription.setupWsEventListener (/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/subscription.js:22:21)

at new Subscription (/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/subscription.js:19:14)

at WebSocketExtension.subscribe (/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/index.js:315:30)

at Subscription.<anonymous> (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:89:58)

at step (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:48:23)

at Object.next (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:29:53)

at fulfilled (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:20:58)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)


const sendMessage = require("./src/sendMessage");
const { SDK } = require("@ringcentral/sdk");
const { Subscriptions } = require("@ringcentral/subscriptions");

const logger = require('pino')(
    {
        messageKey: "message",
        formatters: {
            level: (label) => {
                return { level: label };
            },
        }
    }
);

const sdk = new SDK({
    server: process.env.RC_ENV !== "production" ? SDK.server.sandbox : SDK.server.production,
    clientId: process.env.RC_CLIENT,
    clientSecret: process.env.RC_SECRET
});

const platform = sdk.platform();
const subscriptions = new Subscriptions({
    sdk: sdk,
});

const main = async () => {
    // login
    await platform.login({
        jwt: process.env.RC_JWT,
    });

    // subscribe
    const subscription = subscriptions.createSubscription();
    subscription.on(subscription.events.notification, (evt) => {
        console.log(JSON.stringify(evt, null, 2));
    });
    await subscription.setEventFilters(['/restapi/v1.0/account/~/telephony/sessions']).register();

    // trigger events
    subscription
        .register()
        .then(() => logger.info("Subscribed to events."))
        .catch((err) => {
            logger.error({ err }, err.message)
        });
};

main();
1 Answer
answered on Feb 27, 2024 at 11:18am  

I have no problem running your code on my machine. Can you update the RingCentral SDK and the Subscription plugin to make sure you get the latest version.

"@ringcentral/sdk"

"@ringcentral/subscriptions"


 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us