Skip to main content

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
ingcentral-service
ode_modules@rc-exwslibsubscription.js:22:21)
at new Subscription (C:Projects
ingcentral-service
ode_modules@rc-exwslibsubscription.js:19:14)
at WebSocketExtension.subscribe (C:Projects
ingcentral-service
ode_modules@rc-exwslibindex.js:315:30)
at Subscription.<anonymous> (C:Projects
ingcentral-service
ode_modules@ringcentralsubscriptionslibSubscriptions.js:89:58)
at step (C:Projects
ingcentral-service
ode_modules@ringcentralsubscriptionslibSubscriptions.js:48:23)
at Object.next (C:Projects
ingcentral-service
ode_modules@ringcentralsubscriptionslibSubscriptions.js:29:53)
at fulfilled (C:Projects
ingcentral-service
ode_modules@ringcentralsubscriptionslibSubscriptions.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


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.


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


Reply