@kontextso/sdk-react-native 3.0.7 → 3.0.8
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.
- package/dist/index.js +30 -1
- package/dist/index.mjs +30 -1
- package/package.json +1 -1
- package/src/formats/Format.tsx +43 -0
package/dist/index.js
CHANGED
|
@@ -134,6 +134,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
134
134
|
const containerRef = (0, import_react2.useRef)(null);
|
|
135
135
|
const webViewRef = (0, import_react2.useRef)(null);
|
|
136
136
|
const modalWebViewRef = (0, import_react2.useRef)(null);
|
|
137
|
+
const messageStatusRef = (0, import_react2.useRef)("none" /* None */);
|
|
137
138
|
const modalInitTimeoutRef = (0, import_react2.useRef)(null);
|
|
138
139
|
const isModalInitRef = (0, import_react2.useRef)(false);
|
|
139
140
|
const { height: windowHeight, width: windowWidth } = (0, import_react_native.useWindowDimensions)();
|
|
@@ -200,6 +201,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
200
201
|
case "init-iframe":
|
|
201
202
|
setIframeLoaded(true);
|
|
202
203
|
debug("iframe-post-message");
|
|
204
|
+
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
203
205
|
sendMessage(webViewRef, "update-iframe", code, {
|
|
204
206
|
messages: context?.messages,
|
|
205
207
|
sdk: "sdk-react-native",
|
|
@@ -250,6 +252,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
250
252
|
case "event-iframe":
|
|
251
253
|
onEvent?.(message.data);
|
|
252
254
|
context?.onAdEventInternal(message.data);
|
|
255
|
+
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
253
256
|
break;
|
|
254
257
|
}
|
|
255
258
|
},
|
|
@@ -319,6 +322,31 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
319
322
|
resetModal();
|
|
320
323
|
}
|
|
321
324
|
};
|
|
325
|
+
(0, import_react2.useEffect)(() => {
|
|
326
|
+
const interval = setInterval(() => {
|
|
327
|
+
if (messageStatusRef.current === "none" /* None */) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (messageStatusRef.current === "message-received" /* MessageReceived */) {
|
|
331
|
+
clearInterval(interval);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
debug("iframe-post-message-use-effect");
|
|
335
|
+
setIframeLoaded(true);
|
|
336
|
+
sendMessage(webViewRef, "update-iframe", code, {
|
|
337
|
+
messages: context?.messages,
|
|
338
|
+
sdk: "sdk-react-native",
|
|
339
|
+
otherParams: {
|
|
340
|
+
...otherParams,
|
|
341
|
+
_useEffect: true
|
|
342
|
+
},
|
|
343
|
+
messageId
|
|
344
|
+
});
|
|
345
|
+
}, 500);
|
|
346
|
+
return () => {
|
|
347
|
+
clearInterval(interval);
|
|
348
|
+
};
|
|
349
|
+
}, []);
|
|
322
350
|
const paramsString = (0, import_sdk_react.convertParamsToString)(otherParams);
|
|
323
351
|
(0, import_react2.useEffect)(() => {
|
|
324
352
|
if (!iframeLoaded || !context?.adServerUrl || !bid || !webViewRef.current) {
|
|
@@ -386,6 +414,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
386
414
|
},
|
|
387
415
|
onLoad: () => {
|
|
388
416
|
debug("iframe-load");
|
|
417
|
+
messageStatusRef.current = "initialized" /* Initialized */;
|
|
389
418
|
}
|
|
390
419
|
}
|
|
391
420
|
);
|
|
@@ -463,7 +492,7 @@ var import_react_native3 = require("react-native");
|
|
|
463
492
|
var import_react_native_device_info = __toESM(require("react-native-device-info"));
|
|
464
493
|
|
|
465
494
|
// package.json
|
|
466
|
-
var version = "3.0.
|
|
495
|
+
var version = "3.0.8";
|
|
467
496
|
|
|
468
497
|
// src/NativeRNKontext.ts
|
|
469
498
|
var import_react_native2 = require("react-native");
|
package/dist/index.mjs
CHANGED
|
@@ -103,6 +103,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
103
103
|
const containerRef = useRef(null);
|
|
104
104
|
const webViewRef = useRef(null);
|
|
105
105
|
const modalWebViewRef = useRef(null);
|
|
106
|
+
const messageStatusRef = useRef("none" /* None */);
|
|
106
107
|
const modalInitTimeoutRef = useRef(null);
|
|
107
108
|
const isModalInitRef = useRef(false);
|
|
108
109
|
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
|
|
@@ -169,6 +170,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
169
170
|
case "init-iframe":
|
|
170
171
|
setIframeLoaded(true);
|
|
171
172
|
debug("iframe-post-message");
|
|
173
|
+
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
172
174
|
sendMessage(webViewRef, "update-iframe", code, {
|
|
173
175
|
messages: context?.messages,
|
|
174
176
|
sdk: "sdk-react-native",
|
|
@@ -219,6 +221,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
219
221
|
case "event-iframe":
|
|
220
222
|
onEvent?.(message.data);
|
|
221
223
|
context?.onAdEventInternal(message.data);
|
|
224
|
+
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
222
225
|
break;
|
|
223
226
|
}
|
|
224
227
|
},
|
|
@@ -288,6 +291,31 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
288
291
|
resetModal();
|
|
289
292
|
}
|
|
290
293
|
};
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
const interval = setInterval(() => {
|
|
296
|
+
if (messageStatusRef.current === "none" /* None */) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (messageStatusRef.current === "message-received" /* MessageReceived */) {
|
|
300
|
+
clearInterval(interval);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
debug("iframe-post-message-use-effect");
|
|
304
|
+
setIframeLoaded(true);
|
|
305
|
+
sendMessage(webViewRef, "update-iframe", code, {
|
|
306
|
+
messages: context?.messages,
|
|
307
|
+
sdk: "sdk-react-native",
|
|
308
|
+
otherParams: {
|
|
309
|
+
...otherParams,
|
|
310
|
+
_useEffect: true
|
|
311
|
+
},
|
|
312
|
+
messageId
|
|
313
|
+
});
|
|
314
|
+
}, 500);
|
|
315
|
+
return () => {
|
|
316
|
+
clearInterval(interval);
|
|
317
|
+
};
|
|
318
|
+
}, []);
|
|
291
319
|
const paramsString = convertParamsToString(otherParams);
|
|
292
320
|
useEffect(() => {
|
|
293
321
|
if (!iframeLoaded || !context?.adServerUrl || !bid || !webViewRef.current) {
|
|
@@ -355,6 +383,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
355
383
|
},
|
|
356
384
|
onLoad: () => {
|
|
357
385
|
debug("iframe-load");
|
|
386
|
+
messageStatusRef.current = "initialized" /* Initialized */;
|
|
358
387
|
}
|
|
359
388
|
}
|
|
360
389
|
);
|
|
@@ -435,7 +464,7 @@ import { Appearance, Dimensions, PixelRatio, Platform } from "react-native";
|
|
|
435
464
|
import DeviceInfo from "react-native-device-info";
|
|
436
465
|
|
|
437
466
|
// package.json
|
|
438
|
-
var version = "3.0.
|
|
467
|
+
var version = "3.0.8";
|
|
439
468
|
|
|
440
469
|
// src/NativeRNKontext.ts
|
|
441
470
|
import { TurboModuleRegistry } from "react-native";
|
package/package.json
CHANGED
package/src/formats/Format.tsx
CHANGED
|
@@ -44,6 +44,12 @@ const getCachedContent = (context: ContextType, bidId?: string) => {
|
|
|
44
44
|
return context?.cachedContentRef?.current?.get(bidId) ?? null
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
enum MessageStatus {
|
|
48
|
+
None = 'none',
|
|
49
|
+
Initialized = 'initialized',
|
|
50
|
+
MessageReceived = 'message-received',
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatProps) => {
|
|
48
54
|
const context = useContext(AdsContext)
|
|
49
55
|
|
|
@@ -68,6 +74,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
68
74
|
const containerRef = useRef<View>(null)
|
|
69
75
|
const webViewRef = useRef<WebView>(null)
|
|
70
76
|
const modalWebViewRef = useRef<WebView>(null)
|
|
77
|
+
const messageStatusRef = useRef<MessageStatus>(MessageStatus.None)
|
|
71
78
|
const modalInitTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
72
79
|
const isModalInitRef = useRef<boolean>(false)
|
|
73
80
|
|
|
@@ -146,6 +153,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
146
153
|
case 'init-iframe':
|
|
147
154
|
setIframeLoaded(true)
|
|
148
155
|
debug('iframe-post-message')
|
|
156
|
+
messageStatusRef.current = MessageStatus.MessageReceived
|
|
149
157
|
sendMessage(webViewRef, 'update-iframe', code, {
|
|
150
158
|
messages: context?.messages,
|
|
151
159
|
sdk: 'sdk-react-native',
|
|
@@ -207,6 +215,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
207
215
|
case 'event-iframe':
|
|
208
216
|
onEvent?.(message.data)
|
|
209
217
|
context?.onAdEventInternal(message.data)
|
|
218
|
+
messageStatusRef.current = MessageStatus.MessageReceived
|
|
210
219
|
break
|
|
211
220
|
}
|
|
212
221
|
},
|
|
@@ -287,6 +296,39 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
287
296
|
}
|
|
288
297
|
}
|
|
289
298
|
|
|
299
|
+
/*
|
|
300
|
+
* Fix for Android issue in Saylo.
|
|
301
|
+
* When the iframe is loaded, the onLoad event is sometimes called two or more times.
|
|
302
|
+
* When these events fire too quickly, the init-iframe response from the server gets discarded.
|
|
303
|
+
* As a result, our SDK doesn’t send the update-iframe event back to the server, and the stream never starts.
|
|
304
|
+
* This fix will send the update-iframe event even if the init-iframe isn’t received.
|
|
305
|
+
*/
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
const interval = setInterval(() => {
|
|
308
|
+
if (messageStatusRef.current === MessageStatus.None) {
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
if (messageStatusRef.current === MessageStatus.MessageReceived) {
|
|
312
|
+
clearInterval(interval)
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
debug('iframe-post-message-use-effect')
|
|
316
|
+
setIframeLoaded(true)
|
|
317
|
+
sendMessage(webViewRef, 'update-iframe', code, {
|
|
318
|
+
messages: context?.messages,
|
|
319
|
+
sdk: 'sdk-react-native',
|
|
320
|
+
otherParams: {
|
|
321
|
+
...otherParams,
|
|
322
|
+
_useEffect: true,
|
|
323
|
+
},
|
|
324
|
+
messageId,
|
|
325
|
+
})
|
|
326
|
+
}, 500)
|
|
327
|
+
return () => {
|
|
328
|
+
clearInterval(interval)
|
|
329
|
+
}
|
|
330
|
+
}, [])
|
|
331
|
+
|
|
290
332
|
const paramsString = convertParamsToString(otherParams)
|
|
291
333
|
|
|
292
334
|
useEffect(() => {
|
|
@@ -364,6 +406,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
364
406
|
}}
|
|
365
407
|
onLoad={() => {
|
|
366
408
|
debug('iframe-load')
|
|
409
|
+
messageStatusRef.current = MessageStatus.Initialized
|
|
367
410
|
}}
|
|
368
411
|
/>
|
|
369
412
|
)
|