@kontextso/sdk-react-native 0.0.5-rc.3 → 0.0.5-rc.5
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 +59 -115
- package/dist/index.mjs +31 -87
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,14 +39,14 @@ __export(src_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(src_exports);
|
|
40
40
|
|
|
41
41
|
// src/formats/InlineAd.tsx
|
|
42
|
-
var
|
|
42
|
+
var import_react11 = require("react");
|
|
43
43
|
var import_react_native5 = require("react-native");
|
|
44
44
|
|
|
45
45
|
// src/hooks/useAdViewed.tsx
|
|
46
|
-
var
|
|
46
|
+
var import_react5 = require("react");
|
|
47
47
|
|
|
48
48
|
// src/context/AdsProvider.tsx
|
|
49
|
-
var
|
|
49
|
+
var import_react4 = __toESM(require("react"));
|
|
50
50
|
|
|
51
51
|
// src/hooks/useInitializeAds.tsx
|
|
52
52
|
var import_react = require("react");
|
|
@@ -201,7 +201,7 @@ var parseMessageText = (text) => {
|
|
|
201
201
|
var import_loglevel = __toESM(require("loglevel"));
|
|
202
202
|
|
|
203
203
|
// package.json
|
|
204
|
-
var version = "0.0.5-rc.
|
|
204
|
+
var version = "0.0.5-rc.4";
|
|
205
205
|
|
|
206
206
|
// src/hooks/useInitializeAds.tsx
|
|
207
207
|
async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
|
|
@@ -747,63 +747,8 @@ function useStreamAds({
|
|
|
747
747
|
|
|
748
748
|
// src/context/AdsProvider.tsx
|
|
749
749
|
var import_loglevel4 = __toESM(require("loglevel"));
|
|
750
|
-
|
|
751
|
-
// src/components/ErrorBoundary.tsx
|
|
752
|
-
var import_react4 = __toESM(require("react"));
|
|
753
|
-
var captureErrorFn = (adServerUrl, error, componentStack, context) => {
|
|
754
|
-
fetch(`${adServerUrl}/error`, {
|
|
755
|
-
method: "POST",
|
|
756
|
-
body: JSON.stringify({
|
|
757
|
-
error: error.message,
|
|
758
|
-
stack: componentStack,
|
|
759
|
-
context
|
|
760
|
-
})
|
|
761
|
-
}).catch((e) => {
|
|
762
|
-
console.error(e);
|
|
763
|
-
}).finally(() => {
|
|
764
|
-
console.error(error, componentStack);
|
|
765
|
-
});
|
|
766
|
-
};
|
|
767
|
-
var ErrorBoundary = class extends import_react4.default.Component {
|
|
768
|
-
constructor(props) {
|
|
769
|
-
super(props);
|
|
770
|
-
this.state = {
|
|
771
|
-
hasError: false
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
static getDerivedStateFromError() {
|
|
775
|
-
return {
|
|
776
|
-
hasError: true
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
componentDidCatch(error, info) {
|
|
780
|
-
const adServerUrl = this.props.adserverUrl;
|
|
781
|
-
const props = [
|
|
782
|
-
"adserverUrl",
|
|
783
|
-
"publisherToken",
|
|
784
|
-
"visitorId",
|
|
785
|
-
"sessionId",
|
|
786
|
-
"ads",
|
|
787
|
-
"enabledPlacements",
|
|
788
|
-
"isInitialised",
|
|
789
|
-
"isLoading",
|
|
790
|
-
"messages"
|
|
791
|
-
];
|
|
792
|
-
if (adServerUrl) {
|
|
793
|
-
captureErrorFn(adServerUrl, error, info.componentStack, this.props.reqBodyParams);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
render() {
|
|
797
|
-
if (this.state.hasError) {
|
|
798
|
-
return this.props.fallback || null;
|
|
799
|
-
}
|
|
800
|
-
return this.props.children;
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
|
|
804
|
-
// src/context/AdsProvider.tsx
|
|
805
750
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
806
|
-
var AdsContext =
|
|
751
|
+
var AdsContext = import_react4.default.createContext(null);
|
|
807
752
|
AdsContext.displayName = "AdsContext";
|
|
808
753
|
var VISITOR_ID_KEY = "brain-visitor-id";
|
|
809
754
|
var AdsProviderWithoutBoundary = ({
|
|
@@ -821,7 +766,7 @@ var AdsProviderWithoutBoundary = ({
|
|
|
821
766
|
onAdClick,
|
|
822
767
|
...props
|
|
823
768
|
}) => {
|
|
824
|
-
const [viewedAds, setViewedAds] = (0,
|
|
769
|
+
const [viewedAds, setViewedAds] = (0, import_react4.useState)([]);
|
|
825
770
|
const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
|
|
826
771
|
import_loglevel4.default.setLevel(logLevel || "ERROR");
|
|
827
772
|
const {
|
|
@@ -931,48 +876,47 @@ var AdsProvider = ({
|
|
|
931
876
|
onAdClick,
|
|
932
877
|
...props
|
|
933
878
|
}) => {
|
|
934
|
-
return
|
|
935
|
-
ErrorBoundary
|
|
936
|
-
{
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
879
|
+
return (
|
|
880
|
+
// <ErrorBoundary
|
|
881
|
+
// fallback={children}
|
|
882
|
+
// adserverUrl={adserverUrl}
|
|
883
|
+
// reqBodyParams={{
|
|
884
|
+
// publisherToken,
|
|
885
|
+
// adserverUrl,
|
|
886
|
+
// conversationId,
|
|
887
|
+
// character,
|
|
888
|
+
// userId,
|
|
889
|
+
// isLoading,
|
|
890
|
+
// messages
|
|
891
|
+
// }}
|
|
892
|
+
// >
|
|
893
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
894
|
+
AdsProviderWithoutBoundary,
|
|
895
|
+
{
|
|
896
|
+
children,
|
|
897
|
+
messages,
|
|
940
898
|
publisherToken,
|
|
899
|
+
isLoading,
|
|
941
900
|
adserverUrl,
|
|
942
|
-
|
|
901
|
+
isDisabled,
|
|
943
902
|
character,
|
|
903
|
+
conversationId,
|
|
944
904
|
userId,
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
children,
|
|
952
|
-
messages,
|
|
953
|
-
publisherToken,
|
|
954
|
-
isLoading,
|
|
955
|
-
adserverUrl,
|
|
956
|
-
isDisabled,
|
|
957
|
-
character,
|
|
958
|
-
conversationId,
|
|
959
|
-
userId,
|
|
960
|
-
logLevel,
|
|
961
|
-
onAdView,
|
|
962
|
-
onAdClick,
|
|
963
|
-
throwError: props.throwError
|
|
964
|
-
}
|
|
965
|
-
)
|
|
966
|
-
}
|
|
905
|
+
logLevel,
|
|
906
|
+
onAdView,
|
|
907
|
+
onAdClick,
|
|
908
|
+
throwError: props.throwError
|
|
909
|
+
}
|
|
910
|
+
)
|
|
967
911
|
);
|
|
968
912
|
};
|
|
969
913
|
|
|
970
914
|
// src/hooks/useAdViewed.tsx
|
|
971
|
-
var
|
|
915
|
+
var import_react6 = require("react");
|
|
972
916
|
var import_loglevel5 = __toESM(require("loglevel"));
|
|
973
917
|
function useAdViewed(ad) {
|
|
974
|
-
const context = (0,
|
|
975
|
-
const [stillMounted, setStillMounted] = (0,
|
|
918
|
+
const context = (0, import_react6.useContext)(AdsContext);
|
|
919
|
+
const [stillMounted, setStillMounted] = (0, import_react5.useState)(false);
|
|
976
920
|
const sendRequest = async () => {
|
|
977
921
|
if (!context?.adserverUrl || !ad?.id) {
|
|
978
922
|
return;
|
|
@@ -994,7 +938,7 @@ function useAdViewed(ad) {
|
|
|
994
938
|
import_loglevel5.default.error("[BRAIN] Error sending view request", e);
|
|
995
939
|
}
|
|
996
940
|
};
|
|
997
|
-
(0,
|
|
941
|
+
(0, import_react5.useEffect)(() => {
|
|
998
942
|
if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
|
|
999
943
|
return;
|
|
1000
944
|
}
|
|
@@ -1004,7 +948,7 @@ function useAdViewed(ad) {
|
|
|
1004
948
|
setStillMounted(true);
|
|
1005
949
|
}, 1e3);
|
|
1006
950
|
}, [ad]);
|
|
1007
|
-
(0,
|
|
951
|
+
(0, import_react5.useEffect)(() => {
|
|
1008
952
|
if (stillMounted) {
|
|
1009
953
|
import_loglevel5.default.log("[BRAIN] sending request");
|
|
1010
954
|
sendRequest();
|
|
@@ -1017,14 +961,14 @@ var import_loglevel8 = __toESM(require("loglevel"));
|
|
|
1017
961
|
|
|
1018
962
|
// src/components/MarkdownText.tsx
|
|
1019
963
|
var import_loglevel6 = __toESM(require("loglevel"));
|
|
1020
|
-
var
|
|
964
|
+
var import_react7 = require("react");
|
|
1021
965
|
var import_react_native2 = require("react-native");
|
|
1022
966
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1023
967
|
function MarkdownText({
|
|
1024
968
|
content,
|
|
1025
969
|
onLinkClick
|
|
1026
970
|
}) {
|
|
1027
|
-
const context = (0,
|
|
971
|
+
const context = (0, import_react7.useContext)(AdsContext);
|
|
1028
972
|
const textParts = parseMessageText(content);
|
|
1029
973
|
const styles = context?.styles?.markdownText;
|
|
1030
974
|
const linkClickHandler = (href) => {
|
|
@@ -1058,17 +1002,17 @@ function MarkdownText({
|
|
|
1058
1002
|
// src/components/VideoPlayer.tsx
|
|
1059
1003
|
var import_expo_av = require("expo-av");
|
|
1060
1004
|
var import_loglevel7 = __toESM(require("loglevel"));
|
|
1061
|
-
var
|
|
1005
|
+
var import_react9 = require("react");
|
|
1062
1006
|
var import_react_native4 = require("react-native");
|
|
1063
1007
|
|
|
1064
1008
|
// src/components/VideoProgressBar.tsx
|
|
1065
|
-
var
|
|
1009
|
+
var import_react8 = require("react");
|
|
1066
1010
|
var import_react_native3 = require("react-native");
|
|
1067
1011
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1068
1012
|
function VideoProgressBar({ videoRef }) {
|
|
1069
|
-
const [progress, setProgress] = (0,
|
|
1070
|
-
const styles = (0,
|
|
1071
|
-
(0,
|
|
1013
|
+
const [progress, setProgress] = (0, import_react8.useState)(0);
|
|
1014
|
+
const styles = (0, import_react8.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
|
|
1015
|
+
(0, import_react8.useEffect)(() => {
|
|
1072
1016
|
const interval = setInterval(() => {
|
|
1073
1017
|
if (!videoRef.current) {
|
|
1074
1018
|
return;
|
|
@@ -1101,14 +1045,14 @@ var VideoPlayer = ({
|
|
|
1101
1045
|
mediaPlacement,
|
|
1102
1046
|
onLinkClick
|
|
1103
1047
|
}) => {
|
|
1104
|
-
const videoRef = (0,
|
|
1105
|
-
const [isPlaying, setIsPlaying] = (0,
|
|
1106
|
-
const [isPaused, setIsPaused] = (0,
|
|
1107
|
-
const [isEnded, setIsEnded] = (0,
|
|
1108
|
-
const [showDownloadBadge, setShowDownloadBadge] = (0,
|
|
1109
|
-
const lastCallbackTimeRef = (0,
|
|
1110
|
-
const styles = (0,
|
|
1111
|
-
(0,
|
|
1048
|
+
const videoRef = (0, import_react9.useRef)(null);
|
|
1049
|
+
const [isPlaying, setIsPlaying] = (0, import_react9.useState)(false);
|
|
1050
|
+
const [isPaused, setIsPaused] = (0, import_react9.useState)(true);
|
|
1051
|
+
const [isEnded, setIsEnded] = (0, import_react9.useState)(false);
|
|
1052
|
+
const [showDownloadBadge, setShowDownloadBadge] = (0, import_react9.useState)(false);
|
|
1053
|
+
const lastCallbackTimeRef = (0, import_react9.useRef)(0);
|
|
1054
|
+
const styles = (0, import_react9.useContext)(AdsContext)?.styles?.videoPlayer;
|
|
1055
|
+
(0, import_react9.useEffect)(() => {
|
|
1112
1056
|
const interval = setInterval(() => {
|
|
1113
1057
|
if (videoRef.current) {
|
|
1114
1058
|
videoRef.current.getStatusAsync().then((status) => {
|
|
@@ -1191,9 +1135,9 @@ var VideoPlayer = ({
|
|
|
1191
1135
|
};
|
|
1192
1136
|
|
|
1193
1137
|
// src/hooks/useAd.tsx
|
|
1194
|
-
var
|
|
1138
|
+
var import_react10 = require("react");
|
|
1195
1139
|
function useAd({ code, messageId }) {
|
|
1196
|
-
const context = (0,
|
|
1140
|
+
const context = (0, import_react10.useContext)(AdsContext);
|
|
1197
1141
|
if (!context) {
|
|
1198
1142
|
return null;
|
|
1199
1143
|
}
|
|
@@ -1241,11 +1185,11 @@ function useAd({ code, messageId }) {
|
|
|
1241
1185
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1242
1186
|
var InlineAd = ({ code, messageId, wrapper }) => {
|
|
1243
1187
|
const ad = useAd({ code, messageId });
|
|
1244
|
-
const [linkIncluded, setLinkIncluded] = (0,
|
|
1245
|
-
const context = (0,
|
|
1188
|
+
const [linkIncluded, setLinkIncluded] = (0, import_react11.useState)(false);
|
|
1189
|
+
const context = (0, import_react11.useContext)(AdsContext);
|
|
1246
1190
|
const styles = context?.styles?.inlineAd;
|
|
1247
1191
|
useAdViewed(ad);
|
|
1248
|
-
(0,
|
|
1192
|
+
(0, import_react11.useEffect)(() => {
|
|
1249
1193
|
if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
|
|
1250
1194
|
setLinkIncluded(true);
|
|
1251
1195
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
21
21
|
|
|
22
22
|
// src/context/AdsProvider.tsx
|
|
23
|
-
import
|
|
23
|
+
import React, { useState as useState4 } from "react";
|
|
24
24
|
|
|
25
25
|
// src/hooks/useInitializeAds.tsx
|
|
26
26
|
import { useEffect, useState } from "react";
|
|
@@ -175,7 +175,7 @@ var parseMessageText = (text) => {
|
|
|
175
175
|
import log from "loglevel";
|
|
176
176
|
|
|
177
177
|
// package.json
|
|
178
|
-
var version = "0.0.5-rc.
|
|
178
|
+
var version = "0.0.5-rc.4";
|
|
179
179
|
|
|
180
180
|
// src/hooks/useInitializeAds.tsx
|
|
181
181
|
async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
|
|
@@ -721,63 +721,8 @@ function useStreamAds({
|
|
|
721
721
|
|
|
722
722
|
// src/context/AdsProvider.tsx
|
|
723
723
|
import log4 from "loglevel";
|
|
724
|
-
|
|
725
|
-
// src/components/ErrorBoundary.tsx
|
|
726
|
-
import React from "react";
|
|
727
|
-
var captureErrorFn = (adServerUrl, error, componentStack, context) => {
|
|
728
|
-
fetch(`${adServerUrl}/error`, {
|
|
729
|
-
method: "POST",
|
|
730
|
-
body: JSON.stringify({
|
|
731
|
-
error: error.message,
|
|
732
|
-
stack: componentStack,
|
|
733
|
-
context
|
|
734
|
-
})
|
|
735
|
-
}).catch((e) => {
|
|
736
|
-
console.error(e);
|
|
737
|
-
}).finally(() => {
|
|
738
|
-
console.error(error, componentStack);
|
|
739
|
-
});
|
|
740
|
-
};
|
|
741
|
-
var ErrorBoundary = class extends React.Component {
|
|
742
|
-
constructor(props) {
|
|
743
|
-
super(props);
|
|
744
|
-
this.state = {
|
|
745
|
-
hasError: false
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
static getDerivedStateFromError() {
|
|
749
|
-
return {
|
|
750
|
-
hasError: true
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
componentDidCatch(error, info) {
|
|
754
|
-
const adServerUrl = this.props.adserverUrl;
|
|
755
|
-
const props = [
|
|
756
|
-
"adserverUrl",
|
|
757
|
-
"publisherToken",
|
|
758
|
-
"visitorId",
|
|
759
|
-
"sessionId",
|
|
760
|
-
"ads",
|
|
761
|
-
"enabledPlacements",
|
|
762
|
-
"isInitialised",
|
|
763
|
-
"isLoading",
|
|
764
|
-
"messages"
|
|
765
|
-
];
|
|
766
|
-
if (adServerUrl) {
|
|
767
|
-
captureErrorFn(adServerUrl, error, info.componentStack, this.props.reqBodyParams);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
render() {
|
|
771
|
-
if (this.state.hasError) {
|
|
772
|
-
return this.props.fallback || null;
|
|
773
|
-
}
|
|
774
|
-
return this.props.children;
|
|
775
|
-
}
|
|
776
|
-
};
|
|
777
|
-
|
|
778
|
-
// src/context/AdsProvider.tsx
|
|
779
724
|
import { jsx } from "react/jsx-runtime";
|
|
780
|
-
var AdsContext =
|
|
725
|
+
var AdsContext = React.createContext(null);
|
|
781
726
|
AdsContext.displayName = "AdsContext";
|
|
782
727
|
var VISITOR_ID_KEY = "brain-visitor-id";
|
|
783
728
|
var AdsProviderWithoutBoundary = ({
|
|
@@ -905,39 +850,38 @@ var AdsProvider = ({
|
|
|
905
850
|
onAdClick,
|
|
906
851
|
...props
|
|
907
852
|
}) => {
|
|
908
|
-
return
|
|
909
|
-
ErrorBoundary
|
|
910
|
-
{
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
853
|
+
return (
|
|
854
|
+
// <ErrorBoundary
|
|
855
|
+
// fallback={children}
|
|
856
|
+
// adserverUrl={adserverUrl}
|
|
857
|
+
// reqBodyParams={{
|
|
858
|
+
// publisherToken,
|
|
859
|
+
// adserverUrl,
|
|
860
|
+
// conversationId,
|
|
861
|
+
// character,
|
|
862
|
+
// userId,
|
|
863
|
+
// isLoading,
|
|
864
|
+
// messages
|
|
865
|
+
// }}
|
|
866
|
+
// >
|
|
867
|
+
/* @__PURE__ */ jsx(
|
|
868
|
+
AdsProviderWithoutBoundary,
|
|
869
|
+
{
|
|
870
|
+
children,
|
|
871
|
+
messages,
|
|
914
872
|
publisherToken,
|
|
873
|
+
isLoading,
|
|
915
874
|
adserverUrl,
|
|
916
|
-
|
|
875
|
+
isDisabled,
|
|
917
876
|
character,
|
|
877
|
+
conversationId,
|
|
918
878
|
userId,
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
children,
|
|
926
|
-
messages,
|
|
927
|
-
publisherToken,
|
|
928
|
-
isLoading,
|
|
929
|
-
adserverUrl,
|
|
930
|
-
isDisabled,
|
|
931
|
-
character,
|
|
932
|
-
conversationId,
|
|
933
|
-
userId,
|
|
934
|
-
logLevel,
|
|
935
|
-
onAdView,
|
|
936
|
-
onAdClick,
|
|
937
|
-
throwError: props.throwError
|
|
938
|
-
}
|
|
939
|
-
)
|
|
940
|
-
}
|
|
879
|
+
logLevel,
|
|
880
|
+
onAdView,
|
|
881
|
+
onAdClick,
|
|
882
|
+
throwError: props.throwError
|
|
883
|
+
}
|
|
884
|
+
)
|
|
941
885
|
);
|
|
942
886
|
};
|
|
943
887
|
|