chayns-api 1.0.8 → 1.0.9

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.
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AppWrapper = void 0;
7
+ var _lodash = _interopRequireDefault(require("lodash.throttle"));
7
8
  var _IChaynsReact = require("../types/IChaynsReact");
8
9
  var _appCall = _interopRequireDefault(require("../util/appCall"));
9
10
  var _deviceHelper = _interopRequireWildcard(require("../util/deviceHelper"));
10
- var _visibilityChangeListener = require("../calls/visibilityChangeListener");
11
11
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
12
12
  var _sendMessage = require("../calls/sendMessage");
13
13
  var _apiListenerHelper = require("../helper/apiListenerHelper");
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
 
20
20
  class AppWrapper {
21
21
  values = null;
22
- accessToken = "";
22
+ accessToken = '';
23
23
  mapOldApiToNew(retVal) {
24
24
  var _window, _window2, _AppInfo$TappSelected;
25
25
  const {
@@ -122,7 +122,7 @@ class AppWrapper {
122
122
  }
123
123
  resolve((_v$retVal2 = v === null || v === void 0 ? void 0 : v.retVal) !== null && _v$retVal2 !== void 0 ? _v$retVal2 : v);
124
124
  };
125
- value.callback = "window." + callbackName;
125
+ value.callback = 'window.' + callbackName;
126
126
  (0, _appCall.default)({
127
127
  action,
128
128
  value
@@ -133,50 +133,83 @@ class AppWrapper {
133
133
  getAccessToken: async () => ({
134
134
  accessToken: this.accessToken
135
135
  }),
136
- // addGeoLocationListener: async (value , callback) => {
137
- // return invokeAppCall({
138
- // 'action': 14,
139
- // 'value': {
140
- // 'permanent': false,
141
- // callback: callback
142
- // }
143
- // });
144
- // },
145
- // addScrollListener: async (value, callback) => {
146
- //
147
- // },
136
+ addGeoLocationListener: async (value, callback) => {
137
+ const {
138
+ id,
139
+ shouldInitialize
140
+ } = (0, _apiListenerHelper.addApiListener)('geoLocationListener', callback);
141
+ if (shouldInitialize) {
142
+ this.appCall(14, {
143
+ permanent: true
144
+ }, {
145
+ callback: v => {
146
+ var _v$accuracy, _v$code;
147
+ (0, _apiListenerHelper.dispatchApiEvent)('geoLocationListener', {
148
+ latitude: v.latitude,
149
+ longitude: v.longitude,
150
+ accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
151
+ speed: v.speed,
152
+ code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
153
+ });
154
+ }
155
+ });
156
+ }
157
+ return id;
158
+ },
159
+ addScrollListener: async (value, callback) => {
160
+ let throttledCallback = callback;
161
+ if (value.throttle) {
162
+ throttledCallback = (0, _lodash.default)(callback, value.throttle);
163
+ }
164
+ const {
165
+ id,
166
+ shouldInitialize
167
+ } = (0, _apiListenerHelper.addApiListener)('scrollListener', throttledCallback);
168
+ if (shouldInitialize) {
169
+ window.addEventListener('scroll', this.scrollListener = () => {
170
+ void (async () => {
171
+ (0, _apiListenerHelper.dispatchApiEvent)('scrollListener', {
172
+ scrollX: window.scrollX,
173
+ scrollY: window.scrollY
174
+ });
175
+ })();
176
+ });
177
+ }
178
+ return id;
179
+ },
148
180
  addVisibilityChangeListener: async callback => {
181
+ const {
182
+ id,
183
+ shouldInitialize
184
+ } = (0, _apiListenerHelper.addApiListener)('visibilityChangeListener', callback);
185
+ if (shouldInitialize) {
186
+ this.appCall(60, {}, {
187
+ callback: v => {
188
+ (0, _apiListenerHelper.dispatchApiEvent)('visibilityChangeListener', {
189
+ isVisible: v.tappEvent === _IChaynsReact.TappEvent.OnShow,
190
+ tappEvent: v.tappEvent
191
+ });
192
+ }
193
+ });
194
+ }
195
+ return id;
196
+ },
197
+ addWindowMetricsListener: async callback => {
149
198
  const {
150
199
  id,
151
200
  shouldInitialize
152
201
  } = (0, _apiListenerHelper.addApiListener)('windowMetricsListener', callback);
153
- this.appCall(60, {}, {
154
- callback: v => {
155
- console.log("v", v);
156
- (0, _apiListenerHelper.dispatchApiEvent)("windowMetricsListener", {
157
- isVisible: v.tappEvent === _IChaynsReact.TappEvent.OnShow,
158
- tappEvent: v.tappEvent
159
- });
160
- }
161
- });
202
+ if (shouldInitialize) {
203
+ window.addEventListener('resize', this.resizeListener = () => {
204
+ void (async () => {
205
+ (0, _apiListenerHelper.dispatchApiEvent)('windowMetricsListener', await this.functions.getWindowMetrics());
206
+ })();
207
+ });
208
+ }
162
209
  return id;
163
210
  },
164
- // addWindowMetricsListener: async (callback) => {
165
- // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
166
- //
167
- // if (shouldInitialize) {
168
- // window.addEventListener('resize', this.resizeListener = () => {
169
- // void (async() => {
170
- // dispatchApiEvent('windowMetricsListener', {
171
- //
172
- // });
173
- // })();
174
- // })
175
- // }
176
- // return id;
177
- // },
178
211
  customCallbackFunction: async () => {
179
- this.notImplemented("customCallbackFunction");
212
+ this.notImplemented('customCallbackFunction');
180
213
  },
181
214
  getAvailableSharingServices: async () => {
182
215
  const res = await this.appCall(79);
@@ -264,9 +297,9 @@ class AppWrapper {
264
297
  awaitResult: false
265
298
  });
266
299
  },
267
- // openUrl: async (value) => {
268
- //
269
- // },
300
+ openUrl: async value => {
301
+ window.open(value.url);
302
+ },
270
303
  openVideo: async value => {
271
304
  this.appCall(15, {
272
305
  url: value.url
@@ -280,19 +313,41 @@ class AppWrapper {
280
313
  });
281
314
  },
282
315
  refreshData: async value => {
283
- this.notImplemented("refreshData");
284
- },
285
- // removeGeoLocationListener: async (id) => {
286
- // },
287
- // removeScrollListener: async (id) => {
288
- // },
289
- removeVisibilityChangeListener(number) {
290
- (0, _visibilityChangeListener.removeVisibilityChangeListener)(number);
291
- return Promise.resolve();
292
- },
293
- // removeWindowMetricsListener: async (id) => {
294
- //
295
- // },
316
+ this.notImplemented('refreshData');
317
+ },
318
+ removeGeoLocationListener: async id => {
319
+ const {
320
+ shouldRemove
321
+ } = (0, _apiListenerHelper.removeApiListener)('geoLocationListener', id);
322
+ if (shouldRemove) {
323
+ // App does not support removal of request geo location call with permanent true which makes this a no-op
324
+ }
325
+ },
326
+ removeScrollListener: async id => {
327
+ const {
328
+ shouldRemove
329
+ } = (0, _apiListenerHelper.removeApiListener)('scrollListener', id);
330
+ if (shouldRemove && this.scrollListener) {
331
+ window.removeEventListener('scroll', this.scrollListener);
332
+ this.scrollListener = null;
333
+ }
334
+ },
335
+ removeVisibilityChangeListener: async id => {
336
+ const {
337
+ shouldRemove
338
+ } = (0, _apiListenerHelper.removeApiListener)('visibilityChangeListener', id);
339
+ if (shouldRemove) {
340
+ // App does not support removal of onActivate callback which makes this a no-op
341
+ }
342
+ },
343
+ removeWindowMetricsListener: async id => {
344
+ const shouldRemove = (0, _apiListenerHelper.removeApiListener)('windowMetricsListener', id);
345
+ if (shouldRemove) {
346
+ void this.exposedFunctions.removeWindowMetricsListener(id);
347
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
348
+ this.resizeListener = null;
349
+ }
350
+ },
296
351
  selectPage: async options => {
297
352
  void this.appCall(2, {
298
353
  id: options.id,
@@ -323,7 +378,7 @@ class AppWrapper {
323
378
  return (0, _sendMessage.sendMessageToUser)(this, message, userId);
324
379
  },
325
380
  setAdminMode: async () => {
326
- this.notImplemented("setAdminMode");
381
+ this.notImplemented('setAdminMode');
327
382
  },
328
383
  setDisplayTimeout: async enabled => {
329
384
  this.appCall(94, {
@@ -348,10 +403,10 @@ class AppWrapper {
348
403
  }, callback));
349
404
  },
350
405
  setHeight: async () => {
351
- this.notImplemented("setOverlay");
406
+ this.notImplemented('setOverlay');
352
407
  },
353
408
  setOverlay: async () => {
354
- this.notImplemented("setOverlay");
409
+ this.notImplemented('setOverlay');
355
410
  },
356
411
  setRefreshScrollEnabled: async isEnabled => {
357
412
  this.appCall(0, {
@@ -367,7 +422,7 @@ class AppWrapper {
367
422
  return await this.appCall(34, value);
368
423
  },
369
424
  setTempDesignSettings: async () => {
370
- this.notImplemented("setTempDesignSettings");
425
+ this.notImplemented('setTempDesignSettings');
371
426
  },
372
427
  setWaitCursor: async value => {
373
428
  void this.appCall(1, {
@@ -2,13 +2,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2
2
  /* eslint-disable */
3
3
  // @ts-nocheck
4
4
 
5
+ import throttle from 'lodash.throttle';
5
6
  import { Environment, Font, Gender, IconType, RuntimeEnviroment, TappEvent } from '../types/IChaynsReact';
6
- import invokeAppCall from "../util/appCall";
7
- import getDeviceInfo, { getScreenSize } from "../util/deviceHelper";
8
- import { removeVisibilityChangeListener } from "../calls/visibilityChangeListener";
9
- import getUserInfo from "../calls/getUserInfo";
10
- import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from "../calls/sendMessage";
11
- import { addApiListener, dispatchApiEvent } from "../helper/apiListenerHelper";
7
+ import invokeAppCall from '../util/appCall';
8
+ import getDeviceInfo, { getScreenSize } from '../util/deviceHelper';
9
+ import getUserInfo from '../calls/getUserInfo';
10
+ import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
11
+ import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
12
12
  export class AppWrapper {
13
13
  mapOldApiToNew(retVal) {
14
14
  var _window, _window2, _AppInfo$TappSelected;
@@ -86,56 +86,89 @@ export class AppWrapper {
86
86
  }
87
87
  constructor() {
88
88
  _defineProperty(this, "values", null);
89
- _defineProperty(this, "accessToken", "");
89
+ _defineProperty(this, "accessToken", '');
90
90
  _defineProperty(this, "counter", 0);
91
91
  _defineProperty(this, "functions", {
92
92
  getAccessToken: async () => ({
93
93
  accessToken: this.accessToken
94
94
  }),
95
- // addGeoLocationListener: async (value , callback) => {
96
- // return invokeAppCall({
97
- // 'action': 14,
98
- // 'value': {
99
- // 'permanent': false,
100
- // callback: callback
101
- // }
102
- // });
103
- // },
104
- // addScrollListener: async (value, callback) => {
105
- //
106
- // },
95
+ addGeoLocationListener: async (value, callback) => {
96
+ const {
97
+ id,
98
+ shouldInitialize
99
+ } = addApiListener('geoLocationListener', callback);
100
+ if (shouldInitialize) {
101
+ this.appCall(14, {
102
+ permanent: true
103
+ }, {
104
+ callback: v => {
105
+ var _v$accuracy, _v$code;
106
+ dispatchApiEvent('geoLocationListener', {
107
+ latitude: v.latitude,
108
+ longitude: v.longitude,
109
+ accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
110
+ speed: v.speed,
111
+ code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
112
+ });
113
+ }
114
+ });
115
+ }
116
+ return id;
117
+ },
118
+ addScrollListener: async (value, callback) => {
119
+ let throttledCallback = callback;
120
+ if (value.throttle) {
121
+ throttledCallback = throttle(callback, value.throttle);
122
+ }
123
+ const {
124
+ id,
125
+ shouldInitialize
126
+ } = addApiListener('scrollListener', throttledCallback);
127
+ if (shouldInitialize) {
128
+ window.addEventListener('scroll', this.scrollListener = () => {
129
+ void (async () => {
130
+ dispatchApiEvent('scrollListener', {
131
+ scrollX: window.scrollX,
132
+ scrollY: window.scrollY
133
+ });
134
+ })();
135
+ });
136
+ }
137
+ return id;
138
+ },
107
139
  addVisibilityChangeListener: async callback => {
140
+ const {
141
+ id,
142
+ shouldInitialize
143
+ } = addApiListener('visibilityChangeListener', callback);
144
+ if (shouldInitialize) {
145
+ this.appCall(60, {}, {
146
+ callback: v => {
147
+ dispatchApiEvent('visibilityChangeListener', {
148
+ isVisible: v.tappEvent === TappEvent.OnShow,
149
+ tappEvent: v.tappEvent
150
+ });
151
+ }
152
+ });
153
+ }
154
+ return id;
155
+ },
156
+ addWindowMetricsListener: async callback => {
108
157
  const {
109
158
  id,
110
159
  shouldInitialize
111
160
  } = addApiListener('windowMetricsListener', callback);
112
- this.appCall(60, {}, {
113
- callback: v => {
114
- console.log("v", v);
115
- dispatchApiEvent("windowMetricsListener", {
116
- isVisible: v.tappEvent === TappEvent.OnShow,
117
- tappEvent: v.tappEvent
118
- });
119
- }
120
- });
161
+ if (shouldInitialize) {
162
+ window.addEventListener('resize', this.resizeListener = () => {
163
+ void (async () => {
164
+ dispatchApiEvent('windowMetricsListener', await this.functions.getWindowMetrics());
165
+ })();
166
+ });
167
+ }
121
168
  return id;
122
169
  },
123
- // addWindowMetricsListener: async (callback) => {
124
- // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
125
- //
126
- // if (shouldInitialize) {
127
- // window.addEventListener('resize', this.resizeListener = () => {
128
- // void (async() => {
129
- // dispatchApiEvent('windowMetricsListener', {
130
- //
131
- // });
132
- // })();
133
- // })
134
- // }
135
- // return id;
136
- // },
137
170
  customCallbackFunction: async () => {
138
- this.notImplemented("customCallbackFunction");
171
+ this.notImplemented('customCallbackFunction');
139
172
  },
140
173
  getAvailableSharingServices: async () => {
141
174
  const res = await this.appCall(79);
@@ -224,9 +257,9 @@ export class AppWrapper {
224
257
  awaitResult: false
225
258
  });
226
259
  },
227
- // openUrl: async (value) => {
228
- //
229
- // },
260
+ openUrl: async value => {
261
+ window.open(value.url);
262
+ },
230
263
  openVideo: async value => {
231
264
  this.appCall(15, {
232
265
  url: value.url
@@ -240,19 +273,41 @@ export class AppWrapper {
240
273
  });
241
274
  },
242
275
  refreshData: async value => {
243
- this.notImplemented("refreshData");
244
- },
245
- // removeGeoLocationListener: async (id) => {
246
- // },
247
- // removeScrollListener: async (id) => {
248
- // },
249
- removeVisibilityChangeListener(number) {
250
- removeVisibilityChangeListener(number);
251
- return Promise.resolve();
252
- },
253
- // removeWindowMetricsListener: async (id) => {
254
- //
255
- // },
276
+ this.notImplemented('refreshData');
277
+ },
278
+ removeGeoLocationListener: async id => {
279
+ const {
280
+ shouldRemove
281
+ } = removeApiListener('geoLocationListener', id);
282
+ if (shouldRemove) {
283
+ // App does not support removal of request geo location call with permanent true which makes this a no-op
284
+ }
285
+ },
286
+ removeScrollListener: async id => {
287
+ const {
288
+ shouldRemove
289
+ } = removeApiListener('scrollListener', id);
290
+ if (shouldRemove && this.scrollListener) {
291
+ window.removeEventListener('scroll', this.scrollListener);
292
+ this.scrollListener = null;
293
+ }
294
+ },
295
+ removeVisibilityChangeListener: async id => {
296
+ const {
297
+ shouldRemove
298
+ } = removeApiListener('visibilityChangeListener', id);
299
+ if (shouldRemove) {
300
+ // App does not support removal of onActivate callback which makes this a no-op
301
+ }
302
+ },
303
+ removeWindowMetricsListener: async id => {
304
+ const shouldRemove = removeApiListener('windowMetricsListener', id);
305
+ if (shouldRemove) {
306
+ void this.exposedFunctions.removeWindowMetricsListener(id);
307
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
308
+ this.resizeListener = null;
309
+ }
310
+ },
256
311
  selectPage: async options => {
257
312
  void this.appCall(2, {
258
313
  id: options.id,
@@ -283,7 +338,7 @@ export class AppWrapper {
283
338
  return sendMessageToUser(this, message, userId);
284
339
  },
285
340
  setAdminMode: async () => {
286
- this.notImplemented("setAdminMode");
341
+ this.notImplemented('setAdminMode');
287
342
  },
288
343
  setDisplayTimeout: async enabled => {
289
344
  this.appCall(94, {
@@ -308,10 +363,10 @@ export class AppWrapper {
308
363
  }, callback));
309
364
  },
310
365
  setHeight: async () => {
311
- this.notImplemented("setOverlay");
366
+ this.notImplemented('setOverlay');
312
367
  },
313
368
  setOverlay: async () => {
314
- this.notImplemented("setOverlay");
369
+ this.notImplemented('setOverlay');
315
370
  },
316
371
  setRefreshScrollEnabled: async isEnabled => {
317
372
  this.appCall(0, {
@@ -327,7 +382,7 @@ export class AppWrapper {
327
382
  return await this.appCall(34, value);
328
383
  },
329
384
  setTempDesignSettings: async () => {
330
- this.notImplemented("setTempDesignSettings");
385
+ this.notImplemented('setTempDesignSettings');
331
386
  },
332
387
  setWaitCursor: async value => {
333
388
  void this.appCall(1, {
@@ -401,7 +456,7 @@ export class AppWrapper {
401
456
  }
402
457
  resolve((_v$retVal2 = v === null || v === void 0 ? void 0 : v.retVal) !== null && _v$retVal2 !== void 0 ? _v$retVal2 : v);
403
458
  };
404
- value.callback = "window." + callbackName;
459
+ value.callback = 'window.' + callbackName;
405
460
  invokeAppCall({
406
461
  action,
407
462
  value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",