Api User avatar image
Api User asked Dev Admin commented

Cannot read properties "addEventListener" when initialising new subscription


i took the example directly from 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: '',
    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(, evt => {
        console.log(JSON.stringify(evt, null, 2));
    await subscription

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


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 (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

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:

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