versacall-core-library-react 2.0.74 → 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,44 +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 protocol = urlArray[0]; // 'http' or 'https'
133
- const modifiedUrl = urlArray[urlArray.length - 1];
134
- const isSecure = protocol === 'https';
135
130
 
136
- // Use dynamic secure flag based on protocol
137
- client = emitter.connect({
138
- host: modifiedUrl,
139
- port: 9090,
140
- secure: isSecure // ws:// for http, wss:// for https
141
- });
142
- client.on('disconnect', () => {
143
- this.props.core.log('system', namespace, methodName, 'Emitter Disconnect');
144
- if (this.state.connected === true) {
145
- this.setState({
146
- connected: false
147
- });
148
- notifyConnectionChanged(false);
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;
149
137
  }
150
- });
151
- client.on('offline', () => {
152
- this.props.core.log('system', namespace, methodName, 'Emitter Offline');
153
- if (this.state.connected === true) {
154
- this.setState({
155
- connected: false
156
- });
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');
157
149
  notifyConnectionChanged(false);
158
- }
159
- });
160
- client.on('message', msg => {
161
- processMessage(msg.channel, JSON.parse(msg.asString()));
162
- });
163
- client.on('error', error => {
164
- this.props.core.log('error', namespace, methodName, error);
165
- });
150
+ });
151
+ client.on('offline', () => {
152
+ props.core.log('system', namespace, methodName, 'Emitter Offline');
153
+ notifyConnectionChanged(false);
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
+ }
166
166
  }
167
167
  updateChannel(id, data) {
168
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": 74
5
+ "build": 75
6
6
  },
7
7
  "name": "versacall-core-library-react",
8
- "version": "2.0.74",
8
+ "version": "2.0.75",
9
9
  "description": "Versacall Core Library",
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.js",