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
Cannot read properties "addEventListener" when initialising new subscription
Tags: sdk, subscription
Feb 12, 2024 at 2:11am   •   2 replies  •  1 likes
Api User

Hello,


i took the example directly from https://www.npmjs.com/package/@ringcentral/subscriptions and used it on my application.


import 'dotenv/config'

import {SDK} from '@ringcentral/sdk';
import {Subscriptions} from '@ringcentral/subscriptions';

// init
const sdk = new SDK({
    server: 'https://platform.devtest.ringcentral.com',
    clientId: process.env.RC_APP_KEY,
    clientSecret: process.env.RC_APP_SECRET
});
const platform = sdk.platform();
const subscriptions = new Subscriptions({
    sdk: sdk,
});

const main = async () => {
    // login
    await platform.login({
        'jwt': process.env.RC_LOGIN_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/~/extension/~/message-store'])
        .register();

    // trigger events
    const r = await platform.get('/restapi/v1.0/account/~/extension/~');
    const ext = await r.json();
    platform.post('/restapi/v1.0/account/~/extension/~/company-pager', {
        from: {extensionId: ext.id},
        to: [{extensionId: ext.id}],
        text: 'Hello world!',
    });
};

main();

When trying to run, i get the error:

TypeError: Cannot read properties of undefined (reading 'addEventListener')
    at Subscription.setupWsEventListener (C:\Projects\ringcentral-service\node_modules\@rc-ex\ws\lib\subscription.js:22:21)
    at new Subscription (C:\Projects\ringcentral-service\node_modules\@rc-ex\ws\lib\subscription.js:19:14)
    at WebSocketExtension.subscribe (C:\Projects\ringcentral-service\node_modules\@rc-ex\ws\lib\index.js:315:30)
    at Subscription.<anonymous> (C:\Projects\ringcentral-service\node_modules\@ringcentral\subscriptions\lib\Subscriptions.js:89:58)
    at step (C:\Projects\ringcentral-service\node_modules\@ringcentral\subscriptions\lib\Subscriptions.js:48:23)
    at Object.next (C:\Projects\ringcentral-service\node_modules\@ringcentral\subscriptions\lib\Subscriptions.js:29:53)
    at fulfilled (C:\Projects\ringcentral-service\node_modules\@ringcentral\subscriptions\lib\Subscriptions.js:20:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Apparently the parameter 'ws' in /@rc-ex/ws/lib/subscription.js is undefined, resulting in an error when trying to add listeners.

Any help is appreciated

sdk version is 5.0.1

subscpriptions version is 5.0.1

Node version is v.18.17.1


on Feb 26, 2024 at 2:45am   •  0 likes

I'm also experiencing this, did you manage to resolve?

1 Answer
answered on Feb 26, 2024 at 2:45am  

I'm experiencing the same issue, did you manage to resolve this ?


 0
answered on Feb 12, 2024 at 8:52am  

I created a demo application to test and it worked for me: https://github.com/tylerlong/rc-subscription-js-demo

You may run "yarn test" to test it after creating a ".env" file.


 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