question

Api User avatar image
Api User asked Dev Admin commented

Cannot read properties "addEventListener" when initialising new subscription

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


sdksubscription
1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Dev Admin avatar image Dev Admin commented ·

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

0 Likes 0 ·

1 Answer

Tyler Liu avatar image
Tyler Liu answered

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.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys