versacall-core-library-react 2.0.73 → 2.0.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,8 @@ const handlers = [];
19
19
  const connectionChangedHandlers = [];
20
20
  const subscribingHandlers = [];
21
21
  let client;
22
+ let clientInitialized = false; // ✅ NEW: Track if client is initialized
23
+
22
24
  function compareChannelInfo(ci1, ci2) {
23
25
  if (ci1 !== null) {
24
26
  if (ci2 !== null) {
@@ -125,50 +127,42 @@ class ChannelsProvider extends _react.Component {
125
127
  constructor(props) {
126
128
  const methodName = 'constructor()';
127
129
  super(props);
128
- this.state = {
129
- connected: true
130
- };
131
- const urlArray = props.core.baseUrl.split('://');
132
- const modifiedUrl = urlArray[urlArray.length - 1];
133
- client = emitter.connect({
134
- host: modifiedUrl,
135
- port: 9090,
136
- secure: true
137
- });
138
- client.on('connect', conack => {
139
- this.props.core.log('system', namespace, methodName, 'Emitter Connect', conack);
140
- if (this.state.connected === false) {
141
- this.resubscribeToChannels();
142
- this.setState({
143
- connected: true
144
- });
145
- notifyConnectionChanged(true);
130
+
131
+ // ✅ FIXED: Check if props are ready before initializing
132
+ if (!clientInitialized) {
133
+ if (!props.core || !props.core.baseUrl) {
134
+ // Props not ready yet, will retry on next instance
135
+ console.log('ChannelsProvider: Core props not ready, deferring client initialization');
136
+ return;
146
137
  }
147
- });
148
- client.on('disconnect', () => {
149
- this.props.core.log('system', namespace, methodName, 'Emitter Disconnect');
150
- if (this.state.connected === true) {
151
- this.setState({
152
- connected: false
153
- });
138
+ const urlArray = props.core.baseUrl.split('://');
139
+ const protocol = urlArray[0];
140
+ const modifiedUrl = urlArray[urlArray.length - 1];
141
+ const isSecure = protocol === 'https';
142
+ client = emitter.connect({
143
+ host: modifiedUrl,
144
+ port: 9090,
145
+ secure: isSecure
146
+ });
147
+ client.on('disconnect', () => {
148
+ props.core.log('system', namespace, methodName, 'Emitter Disconnect');
154
149
  notifyConnectionChanged(false);
155
- }
156
- });
157
- client.on('offline', () => {
158
- this.props.core.log('system', namespace, methodName, 'Emitter Offline');
159
- if (this.state.connected === true) {
160
- this.setState({
161
- connected: false
162
- });
150
+ });
151
+ client.on('offline', () => {
152
+ props.core.log('system', namespace, methodName, 'Emitter Offline');
163
153
  notifyConnectionChanged(false);
164
- }
165
- });
166
- client.on('message', msg => {
167
- processMessage(msg.channel, JSON.parse(msg.asString()));
168
- });
169
- client.on('error', error => {
170
- this.props.core.log('error', namespace, methodName, error);
171
- });
154
+ });
155
+ client.on('message', msg => {
156
+ processMessage(msg.channel, JSON.parse(msg.asString()));
157
+ });
158
+ client.on('error', error => {
159
+ props.core.log('error', namespace, methodName, error);
160
+ });
161
+ clientInitialized = true;
162
+ props.core.log('system', namespace, methodName, 'Emitter Connect (Singleton)');
163
+ } else if (props.core && props.core.baseUrl) {
164
+ props.core.log('system', namespace, methodName, 'Reusing existing Emitter connection');
165
+ }
172
166
  }
173
167
  updateChannel(id, data) {
174
168
  const existing = channelTimeoutHandlers.find(x => x.id === id);
package/package.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "versacall": {
3
3
  "title": "Versacall Core Library React",
4
4
  "applicationType": "react-library",
5
- "build": 73
5
+ "build": 75
6
6
  },
7
7
  "name": "versacall-core-library-react",
8
- "version": "2.0.73",
8
+ "version": "2.0.75",
9
9
  "description": "Versacall Core Library",
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.js",