@selfcommunity/react-core 0.1.2-alpha.0
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/LICENSE.md +21 -0
- package/README.md +13 -0
- package/lib/cjs/components/provider/SCAlertMessagesProvider/index.js +67 -0
- package/lib/cjs/components/provider/SCContextProvider/index.js +117 -0
- package/lib/cjs/components/provider/SCLocaleProvider/index.js +158 -0
- package/lib/cjs/components/provider/SCNotificationProvider/index.js +73 -0
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +93 -0
- package/lib/cjs/components/provider/SCRoutingProvider/index.js +146 -0
- package/lib/cjs/components/provider/SCThemeProvider/index.js +123 -0
- package/lib/cjs/components/provider/SCUserProvider/index.js +310 -0
- package/lib/cjs/components/router/index.js +91 -0
- package/lib/cjs/constants/Actions.js +6 -0
- package/lib/cjs/constants/ContextProviders.js +29 -0
- package/lib/cjs/constants/Device.js +11 -0
- package/lib/cjs/constants/Errors.js +10 -0
- package/lib/cjs/constants/Features.js +84 -0
- package/lib/cjs/constants/Locale.js +19 -0
- package/lib/cjs/constants/Notification.js +67 -0
- package/lib/cjs/constants/Notifications.js +27 -0
- package/lib/cjs/constants/Preferences.js +344 -0
- package/lib/cjs/constants/Routes.js +68 -0
- package/lib/cjs/constants/Session.js +22 -0
- package/lib/cjs/constants/Theme.js +6 -0
- package/lib/cjs/constants/WebSocket.js +10 -0
- package/lib/cjs/hooks/useSCAuth.js +340 -0
- package/lib/cjs/hooks/useSCCachingManager.js +58 -0
- package/lib/cjs/hooks/useSCConnectionsManager.js +285 -0
- package/lib/cjs/hooks/useSCFetchCategories.js +71 -0
- package/lib/cjs/hooks/useSCFetchCategory.js +68 -0
- package/lib/cjs/hooks/useSCFetchCommentObject.js +68 -0
- package/lib/cjs/hooks/useSCFetchCommentObjects.js +296 -0
- package/lib/cjs/hooks/useSCFetchCustomAdv.js +84 -0
- package/lib/cjs/hooks/useSCFetchFeedObject.js +79 -0
- package/lib/cjs/hooks/useSCFetchIncubator.js +68 -0
- package/lib/cjs/hooks/useSCFetchTag.js +68 -0
- package/lib/cjs/hooks/useSCFetchUser.js +68 -0
- package/lib/cjs/hooks/useSCFollowedCategoriesManager.js +162 -0
- package/lib/cjs/hooks/useSCFollowersManager.js +232 -0
- package/lib/cjs/hooks/useSCMediaClick.js +27 -0
- package/lib/cjs/hooks/useSCSubscribedIncubatorsManager.js +165 -0
- package/lib/cjs/hooks/useSCWebPushMessaging.js +286 -0
- package/lib/cjs/hooks/useSCWebSocket.js +120 -0
- package/lib/cjs/index.js +169 -0
- package/lib/cjs/scss/styles.scss +1 -0
- package/lib/cjs/themes/theme.js +165 -0
- package/lib/cjs/types/context.js +3 -0
- package/lib/cjs/types/index.js +22 -0
- package/lib/cjs/utils/errors.js +196 -0
- package/lib/cjs/utils/locale.js +56 -0
- package/lib/cjs/utils/logger.js +32 -0
- package/lib/cjs/utils/object.js +44 -0
- package/lib/cjs/utils/session.js +17 -0
- package/lib/cjs/utils/string.js +57 -0
- package/lib/cjs/utils/url.js +70 -0
- package/lib/cjs/utils/user.js +83 -0
- package/lib/cjs/utils/validator.js +771 -0
- package/lib/cjs/utils/webPushMessaging.js +110 -0
- package/lib/cjs/utils/websocket.js +307 -0
- package/lib/esm/api-services/src/client/index.d.ts +115 -0
- package/lib/esm/api-services/src/client/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/constants/Endpoints.d.ts +10 -0
- package/lib/esm/api-services/src/constants/Endpoints.d.ts.map +1 -0
- package/lib/esm/api-services/src/index.d.ts +24 -0
- package/lib/esm/api-services/src/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/category/index.d.ts +13 -0
- package/lib/esm/api-services/src/services/category/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/feature/index.d.ts +10 -0
- package/lib/esm/api-services/src/services/feature/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/preference/index.d.ts +16 -0
- package/lib/esm/api-services/src/services/preference/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/user/index.d.ts +16 -0
- package/lib/esm/api-services/src/services/user/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/utils/http.d.ts +6 -0
- package/lib/esm/api-services/src/utils/http.d.ts.map +1 -0
- package/lib/esm/api-services/src/utils/token.d.ts +16 -0
- package/lib/esm/api-services/src/utils/token.d.ts.map +1 -0
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js +67 -0
- package/lib/esm/components/provider/SCContextProvider/index.js +117 -0
- package/lib/esm/components/provider/SCLocaleProvider/index.js +158 -0
- package/lib/esm/components/provider/SCNotificationProvider/index.js +73 -0
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +93 -0
- package/lib/esm/components/provider/SCRoutingProvider/index.js +146 -0
- package/lib/esm/components/provider/SCThemeProvider/index.js +123 -0
- package/lib/esm/components/provider/SCUserProvider/index.js +310 -0
- package/lib/esm/components/router/index.js +91 -0
- package/lib/esm/constants/Actions.js +6 -0
- package/lib/esm/constants/ContextProviders.js +29 -0
- package/lib/esm/constants/Device.js +11 -0
- package/lib/esm/constants/Errors.js +10 -0
- package/lib/esm/constants/Features.js +84 -0
- package/lib/esm/constants/Locale.js +19 -0
- package/lib/esm/constants/Notification.js +67 -0
- package/lib/esm/constants/Notifications.js +27 -0
- package/lib/esm/constants/Preferences.js +344 -0
- package/lib/esm/constants/Routes.js +68 -0
- package/lib/esm/constants/Session.js +22 -0
- package/lib/esm/constants/Theme.js +6 -0
- package/lib/esm/constants/WebSocket.js +10 -0
- package/lib/esm/hooks/useSCAuth.js +340 -0
- package/lib/esm/hooks/useSCCachingManager.js +58 -0
- package/lib/esm/hooks/useSCConnectionsManager.js +285 -0
- package/lib/esm/hooks/useSCFetchCategories.js +71 -0
- package/lib/esm/hooks/useSCFetchCategory.js +68 -0
- package/lib/esm/hooks/useSCFetchCommentObject.js +68 -0
- package/lib/esm/hooks/useSCFetchCommentObjects.js +296 -0
- package/lib/esm/hooks/useSCFetchCustomAdv.js +84 -0
- package/lib/esm/hooks/useSCFetchFeedObject.js +79 -0
- package/lib/esm/hooks/useSCFetchIncubator.js +68 -0
- package/lib/esm/hooks/useSCFetchTag.js +68 -0
- package/lib/esm/hooks/useSCFetchUser.js +68 -0
- package/lib/esm/hooks/useSCFollowedCategoriesManager.js +162 -0
- package/lib/esm/hooks/useSCFollowersManager.js +232 -0
- package/lib/esm/hooks/useSCMediaClick.js +27 -0
- package/lib/esm/hooks/useSCSubscribedIncubatorsManager.js +165 -0
- package/lib/esm/hooks/useSCWebPushMessaging.js +286 -0
- package/lib/esm/hooks/useSCWebSocket.js +120 -0
- package/lib/esm/index.js +169 -0
- package/lib/esm/react-core/src/components/provider/SCAlertMessagesProvider/index.d.ts +37 -0
- package/lib/esm/react-core/src/components/provider/SCAlertMessagesProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCContextProvider/index.d.ts +35 -0
- package/lib/esm/react-core/src/components/provider/SCContextProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCLocaleProvider/index.d.ts +42 -0
- package/lib/esm/react-core/src/components/provider/SCLocaleProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCNotificationProvider/index.d.ts +37 -0
- package/lib/esm/react-core/src/components/provider/SCNotificationProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCPreferencesProvider/index.d.ts +38 -0
- package/lib/esm/react-core/src/components/provider/SCPreferencesProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCRoutingProvider/index.d.ts +39 -0
- package/lib/esm/react-core/src/components/provider/SCRoutingProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCThemeProvider/index.d.ts +49 -0
- package/lib/esm/react-core/src/components/provider/SCThemeProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCUserProvider/index.d.ts +38 -0
- package/lib/esm/react-core/src/components/provider/SCUserProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/router/index.d.ts +34 -0
- package/lib/esm/react-core/src/components/router/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Actions.d.ts +2 -0
- package/lib/esm/react-core/src/constants/Actions.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/ContextProviders.d.ts +6 -0
- package/lib/esm/react-core/src/constants/ContextProviders.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Device.d.ts +6 -0
- package/lib/esm/react-core/src/constants/Device.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Errors.d.ts +5 -0
- package/lib/esm/react-core/src/constants/Errors.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Features.d.ts +41 -0
- package/lib/esm/react-core/src/constants/Features.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Locale.d.ts +8 -0
- package/lib/esm/react-core/src/constants/Locale.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Notification.d.ts +55 -0
- package/lib/esm/react-core/src/constants/Notification.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Notifications.d.ts +11 -0
- package/lib/esm/react-core/src/constants/Notifications.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Routes.d.ts +29 -0
- package/lib/esm/react-core/src/constants/Routes.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Session.d.ts +10 -0
- package/lib/esm/react-core/src/constants/Session.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Theme.d.ts +2 -0
- package/lib/esm/react-core/src/constants/Theme.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCAuth.d.ts +56 -0
- package/lib/esm/react-core/src/hooks/useSCAuth.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCCachingManager.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCCachingManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCConnectionsManager.d.ts +40 -0
- package/lib/esm/react-core/src/hooks/useSCConnectionsManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategories.d.ts +17 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategories.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategory.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategory.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObject.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObject.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObjects.d.ts +54 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObjects.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCustomAdv.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCustomAdv.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchFeedObject.d.ts +21 -0
- package/lib/esm/react-core/src/hooks/useSCFetchFeedObject.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchIncubator.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchIncubator.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchTag.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchTag.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchUser.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchUser.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFollowedCategoriesManager.d.ts +37 -0
- package/lib/esm/react-core/src/hooks/useSCFollowedCategoriesManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFollowersManager.d.ts +37 -0
- package/lib/esm/react-core/src/hooks/useSCFollowersManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCMediaClick.d.ts +4 -0
- package/lib/esm/react-core/src/hooks/useSCMediaClick.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCSubscribedIncubatorsManager.d.ts +27 -0
- package/lib/esm/react-core/src/hooks/useSCSubscribedIncubatorsManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCWebPushMessaging.d.ts +9 -0
- package/lib/esm/react-core/src/hooks/useSCWebPushMessaging.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCWebSocket.d.ts +12 -0
- package/lib/esm/react-core/src/hooks/useSCWebSocket.d.ts.map +1 -0
- package/lib/esm/react-core/src/index.d.ts +77 -0
- package/lib/esm/react-core/src/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/types/context.d.ts +428 -0
- package/lib/esm/react-core/src/types/context.d.ts.map +1 -0
- package/lib/esm/react-core/src/types/index.d.ts +3 -0
- package/lib/esm/react-core/src/types/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/errors.d.ts +98 -0
- package/lib/esm/react-core/src/utils/errors.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/locale.d.ts +10 -0
- package/lib/esm/react-core/src/utils/locale.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/logger.d.ts +11 -0
- package/lib/esm/react-core/src/utils/logger.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/object.d.ts +13 -0
- package/lib/esm/react-core/src/utils/object.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/session.d.ts +6 -0
- package/lib/esm/react-core/src/utils/session.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/string.d.ts +21 -0
- package/lib/esm/react-core/src/utils/string.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/url.d.ts +22 -0
- package/lib/esm/react-core/src/utils/url.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/user.d.ts +41 -0
- package/lib/esm/react-core/src/utils/user.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/validator.d.ts +239 -0
- package/lib/esm/react-core/src/utils/validator.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/webPushMessaging.d.ts +14 -0
- package/lib/esm/react-core/src/utils/webPushMessaging.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/websocket.d.ts +177 -0
- package/lib/esm/react-core/src/utils/websocket.d.ts.map +1 -0
- package/lib/esm/react-i18n/src/index.d.ts +815 -0
- package/lib/esm/react-i18n/src/index.d.ts.map +1 -0
- package/lib/esm/scss/styles.scss +1 -0
- package/lib/esm/themes/theme.js +165 -0
- package/lib/esm/types/context.js +3 -0
- package/lib/esm/types/index.js +22 -0
- package/lib/esm/types/src/index.d.ts +9 -0
- package/lib/esm/types/src/index.d.ts.map +1 -0
- package/lib/esm/types/src/types/auth.d.ts +26 -0
- package/lib/esm/types/src/types/auth.d.ts.map +1 -0
- package/lib/esm/types/src/types/broadcastMessage.d.ts +73 -0
- package/lib/esm/types/src/types/broadcastMessage.d.ts.map +1 -0
- package/lib/esm/types/src/types/category.d.ts +100 -0
- package/lib/esm/types/src/types/category.d.ts.map +1 -0
- package/lib/esm/types/src/types/comment.d.ts +97 -0
- package/lib/esm/types/src/types/comment.d.ts.map +1 -0
- package/lib/esm/types/src/types/customAdv.d.ts +53 -0
- package/lib/esm/types/src/types/customAdv.d.ts.map +1 -0
- package/lib/esm/types/src/types/customNotification.d.ts +28 -0
- package/lib/esm/types/src/types/customNotification.d.ts.map +1 -0
- package/lib/esm/types/src/types/embed.d.ts +33 -0
- package/lib/esm/types/src/types/embed.d.ts.map +1 -0
- package/lib/esm/types/src/types/feed.d.ts +208 -0
- package/lib/esm/types/src/types/feed.d.ts.map +1 -0
- package/lib/esm/types/src/types/incubator.d.ts +53 -0
- package/lib/esm/types/src/types/incubator.d.ts.map +1 -0
- package/lib/esm/types/src/types/index.d.ts +22 -0
- package/lib/esm/types/src/types/index.d.ts.map +1 -0
- package/lib/esm/types/src/types/location.d.ts +61 -0
- package/lib/esm/types/src/types/location.d.ts.map +1 -0
- package/lib/esm/types/src/types/media.d.ts +52 -0
- package/lib/esm/types/src/types/media.d.ts.map +1 -0
- package/lib/esm/types/src/types/notification.d.ts +416 -0
- package/lib/esm/types/src/types/notification.d.ts.map +1 -0
- package/lib/esm/types/src/types/poll.d.ts +77 -0
- package/lib/esm/types/src/types/poll.d.ts.map +1 -0
- package/lib/esm/types/src/types/privateMessage.d.ts +109 -0
- package/lib/esm/types/src/types/privateMessage.d.ts.map +1 -0
- package/lib/esm/types/src/types/prize.d.ts +48 -0
- package/lib/esm/types/src/types/prize.d.ts.map +1 -0
- package/lib/esm/types/src/types/tag.d.ts +47 -0
- package/lib/esm/types/src/types/tag.d.ts.map +1 -0
- package/lib/esm/types/src/types/user.d.ts +227 -0
- package/lib/esm/types/src/types/user.d.ts.map +1 -0
- package/lib/esm/utils/errors.js +196 -0
- package/lib/esm/utils/locale.js +56 -0
- package/lib/esm/utils/logger.js +32 -0
- package/lib/esm/utils/object.js +44 -0
- package/lib/esm/utils/session.js +17 -0
- package/lib/esm/utils/src/index.d.ts +7 -0
- package/lib/esm/utils/src/index.d.ts.map +1 -0
- package/lib/esm/utils/src/utils/string.d.ts +21 -0
- package/lib/esm/utils/src/utils/string.d.ts.map +1 -0
- package/lib/esm/utils/src/utils/url.d.ts +22 -0
- package/lib/esm/utils/src/utils/url.d.ts.map +1 -0
- package/lib/esm/utils/string.js +57 -0
- package/lib/esm/utils/url.js +70 -0
- package/lib/esm/utils/user.js +83 -0
- package/lib/esm/utils/validator.js +771 -0
- package/lib/esm/utils/webPushMessaging.js +110 -0
- package/lib/esm/utils/websocket.js +307 -0
- package/lib/umd/react-core.js +2 -0
- package/lib/umd/react-core.js.LICENSE.txt +1 -0
- package/package.json +128 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.urlB64ToUint8Array = exports.loadVersionBrowser = void 0;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Take the application server's public key, which is Base64 URL-safe encoded,
|
|
8
|
+
* and convert it to a UInt8Array, because this is the expected input of the subscribe()
|
|
9
|
+
*/
|
|
10
|
+
const urlB64ToUint8Array = base64String => {
|
|
11
|
+
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
|
12
|
+
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
|
|
13
|
+
const rawData = window.atob(base64);
|
|
14
|
+
const outputArray = new Uint8Array(rawData.length);
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < rawData.length; ++i) {
|
|
17
|
+
outputArray[i] = rawData.charCodeAt(i);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return outputArray;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Get browser version to track on backend
|
|
24
|
+
* @return {{name: string, version: null}|{name: string, version: string}|{name: *, version: *}|{name: string, version}}
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.urlB64ToUint8Array = urlB64ToUint8Array;
|
|
29
|
+
|
|
30
|
+
const loadVersionBrowser = () => {
|
|
31
|
+
if ('userAgentData' in navigator) {
|
|
32
|
+
// navigator.userAgentData is not available in
|
|
33
|
+
// Firefox and Safari
|
|
34
|
+
const uaData = navigator['userAgentData']; // Outputs of navigator.userAgentData.brands[n].brand are e.g.
|
|
35
|
+
// Chrome: 'Google Chrome'
|
|
36
|
+
// Edge: 'Microsoft Edge'
|
|
37
|
+
// Opera: 'Opera'
|
|
38
|
+
|
|
39
|
+
let browsername;
|
|
40
|
+
let browserversion;
|
|
41
|
+
let chromeVersion = null;
|
|
42
|
+
|
|
43
|
+
for (let i = 0; i < uaData['brands'].length; i++) {
|
|
44
|
+
const brand = uaData['brands'][i].brand;
|
|
45
|
+
browserversion = uaData['brands'][i].version;
|
|
46
|
+
|
|
47
|
+
if (brand.match(/opera|chrome|edge|safari|firefox|msie|trident/i) !== null) {
|
|
48
|
+
// If we have a chrome match, save the match, but try to find another match
|
|
49
|
+
// E.g. Edge can also produce a false Chrome match.
|
|
50
|
+
if (brand.match(/chrome/i) !== null) {
|
|
51
|
+
chromeVersion = browserversion;
|
|
52
|
+
} // If this is not a chrome match return immediately
|
|
53
|
+
else {
|
|
54
|
+
browsername = brand.substr(brand.indexOf(' ') + 1);
|
|
55
|
+
return {
|
|
56
|
+
name: browsername,
|
|
57
|
+
version: browserversion
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} // No non-Chrome match was found. If we have a chrome match, return it.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if (chromeVersion !== null) {
|
|
65
|
+
return {
|
|
66
|
+
name: 'chrome',
|
|
67
|
+
version: chromeVersion
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
} // If no userAgentData is not present, or if no match via userAgentData was found,
|
|
71
|
+
// try to extract the browser name and version from userAgent
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const userAgent = navigator.userAgent;
|
|
75
|
+
let ua = userAgent;
|
|
76
|
+
let tem;
|
|
77
|
+
let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
78
|
+
|
|
79
|
+
if (/trident/i.test(M[1])) {
|
|
80
|
+
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
|
|
81
|
+
return {
|
|
82
|
+
name: 'IE',
|
|
83
|
+
version: tem[1] || ''
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (M[1] === 'Chrome') {
|
|
88
|
+
tem = ua.match(/\bOPR\/(\d+)/);
|
|
89
|
+
|
|
90
|
+
if (tem != null) {
|
|
91
|
+
return {
|
|
92
|
+
name: 'Opera',
|
|
93
|
+
version: tem[1]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
|
|
99
|
+
|
|
100
|
+
if ((tem = ua.match(/version\/(\d+)/i)) != null) {
|
|
101
|
+
M.splice(1, 1, tem[1]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
name: M[0],
|
|
106
|
+
version: M[1]
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.loadVersionBrowser = loadVersionBrowser;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WSClientPropTypes interface
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WSClient: manage socket connection
|
|
12
|
+
* @param options
|
|
13
|
+
* @constructor
|
|
14
|
+
*/
|
|
15
|
+
class WSClient {
|
|
16
|
+
/**
|
|
17
|
+
* Constructor
|
|
18
|
+
* @param cfg
|
|
19
|
+
*/
|
|
20
|
+
constructor(cfg) {
|
|
21
|
+
this._attempts = 1;
|
|
22
|
+
this._heartbeatInterval = null;
|
|
23
|
+
this._missedHeartbeats = 0;
|
|
24
|
+
|
|
25
|
+
if (!this.isValidOptions(cfg)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this._cfg = Object.assign({}, {
|
|
30
|
+
heartbeatMsg: null,
|
|
31
|
+
debug: false,
|
|
32
|
+
mustReconnect: true
|
|
33
|
+
}, cfg);
|
|
34
|
+
this.connect();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get instance
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
static getInstance(cfg) {
|
|
42
|
+
this._instance = this._instance || new WSClient(cfg);
|
|
43
|
+
return this._instance;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Connect
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
connect() {
|
|
51
|
+
try {
|
|
52
|
+
if (this._ws && (this.isConnecting() || this.isConnected())) {
|
|
53
|
+
// There is already a connection
|
|
54
|
+
this._cfg.debug && console.info('Websocket is connecting or already connected.');
|
|
55
|
+
return;
|
|
56
|
+
} // Callback 'connecting' if exist
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
typeof this._cfg.connecting === 'function' && this._cfg.connecting();
|
|
60
|
+
this._cfg.debug && console.info(`Connecting to ${this._cfg.uri} ...`); // Open the connection
|
|
61
|
+
|
|
62
|
+
this._ws = new WebSocket(this._cfg.uri, this._cfg.protocols);
|
|
63
|
+
this._ws.onopen = this.onOpen.bind(this);
|
|
64
|
+
this._ws.onmessage = this.onMessage.bind(this);
|
|
65
|
+
this._ws.onerror = this.onError.bind(this);
|
|
66
|
+
this._ws.onclose = this.onClose.bind(this);
|
|
67
|
+
this._timer = null;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error(err);
|
|
70
|
+
this.tryToReconnect();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Validate options
|
|
75
|
+
* @param cfg
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
isValidOptions(cfg) {
|
|
80
|
+
let _error = false;
|
|
81
|
+
|
|
82
|
+
if (!cfg) {
|
|
83
|
+
console.error('Invalid WSClient options.');
|
|
84
|
+
return _error;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!cfg.uri) {
|
|
88
|
+
console.error('Invalid WSClient Uri options.');
|
|
89
|
+
_error = true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (cfg && cfg.connecting && !(typeof cfg.connecting === 'function')) {
|
|
93
|
+
console.error('Invalid WSClient connecting options.');
|
|
94
|
+
_error = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (cfg && cfg.connected && !(typeof cfg.connected === 'function')) {
|
|
98
|
+
console.error('Invalid WSClient connected options.');
|
|
99
|
+
_error = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (cfg && cfg.receiveMessage && !(typeof cfg.receiveMessage === 'function')) {
|
|
103
|
+
console.error('Invalid WSClient receiveMessage options.');
|
|
104
|
+
_error = true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (cfg && cfg.disconnected && !(typeof cfg.disconnected === 'function')) {
|
|
108
|
+
console.error('Invalid WSClient connecting options.');
|
|
109
|
+
_error = true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (cfg && cfg.heartbeatMsg && !(typeof cfg.heartbeatMsg === 'string')) {
|
|
113
|
+
console.error('Invalid WSClient heartbeatMsg options.');
|
|
114
|
+
_error = true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (cfg && cfg.debug && !(typeof cfg.debug === 'boolean')) {
|
|
118
|
+
console.error('Invalid WSClient debug options.');
|
|
119
|
+
_error = true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return !_error;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Try to reconnect if previous connection failed
|
|
126
|
+
* Generate an interval, after that try to reconnect
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
tryToReconnect() {
|
|
131
|
+
if (this._cfg.mustReconnect && !this._timer) {
|
|
132
|
+
this._cfg.debug && console.info(`Reconnecting...`);
|
|
133
|
+
let interval = this.generateInteval(this._attempts);
|
|
134
|
+
this._timer = setTimeout(this.reconnect.bind(this), interval);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Reestablish the connection
|
|
139
|
+
* Increase the number of attempts
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
reconnect() {
|
|
144
|
+
this._attempts++;
|
|
145
|
+
this.connect();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Send heartbeat every 5 seconds
|
|
149
|
+
* If missing more than 3 heartbeats close connection
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
sendHeartbeat() {
|
|
154
|
+
try {
|
|
155
|
+
this._missedHeartbeats++;
|
|
156
|
+
if (this._missedHeartbeats > 3) throw new Error('Too many missed heartbeats.');
|
|
157
|
+
|
|
158
|
+
this._ws.send(this._cfg.heartbeatMsg);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
clearInterval(this._heartbeatInterval);
|
|
161
|
+
this._heartbeatInterval = null;
|
|
162
|
+
this._cfg.debug && console.warn(`Closing connection. Reason: ${e.message}`);
|
|
163
|
+
|
|
164
|
+
if (!this.isClosing() && !this.isClosed()) {
|
|
165
|
+
this.close();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Established the new connection
|
|
171
|
+
* Reset this._attempts counter
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
onOpen() {
|
|
176
|
+
this._cfg.debug && console.info('Connected!');
|
|
177
|
+
this._attempts = 1;
|
|
178
|
+
|
|
179
|
+
if (this._cfg.heartbeatMsg && this._heartbeatInterval === null) {
|
|
180
|
+
this._missedHeartbeats = 0;
|
|
181
|
+
this._heartbeatInterval = setInterval(this.sendHeartbeat.bind(this), 5000);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
typeof this._cfg.connected === 'function' && this._cfg.connected();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Connection closed. Try to reconnect.
|
|
188
|
+
* @param evt
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
onClose(evt) {
|
|
193
|
+
this._cfg.debug && console.info('Connection closed!');
|
|
194
|
+
typeof this._cfg.disconnected === 'function' && this._cfg.disconnected(evt);
|
|
195
|
+
this.tryToReconnect();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* An error occured
|
|
199
|
+
* @param evt
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
onError(evt) {
|
|
204
|
+
this._cfg.debug && console.error('Websocket connection is broken!');
|
|
205
|
+
this._cfg.debug && console.error(evt);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A message has arrived.
|
|
209
|
+
* If it is the heartbeat -> reset this._missedHeartbeats
|
|
210
|
+
* If it is data pass data to the callback
|
|
211
|
+
* @param evt
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
onMessage(evt) {
|
|
216
|
+
if (this._cfg.heartbeatMsg && evt.data === this._cfg.heartbeatMsg) {
|
|
217
|
+
// reset the counter for missed heartbeats
|
|
218
|
+
this._missedHeartbeats = 0;
|
|
219
|
+
} else if (typeof this._cfg.receiveMessage === 'function') {
|
|
220
|
+
return this._cfg.receiveMessage(evt.data);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Generate an interval that is randomly between 0 and 2^k - 1, where k is
|
|
225
|
+
* the number of connection attmpts, with a maximum interval of 30 seconds,
|
|
226
|
+
* so it starts at 0 - 1 seconds and maxes out at 0 - 30 seconds
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
generateInteval(k) {
|
|
231
|
+
let maxInterval = (Math.pow(2, k) - 1) * 1000; // If the generated interval is more than 30 seconds, truncate it down to 30 seconds.
|
|
232
|
+
|
|
233
|
+
if (maxInterval > 30 * 1000) {
|
|
234
|
+
maxInterval = 30 * 1000;
|
|
235
|
+
} // generate the interval to a random number between 0 and the maxInterval determined from above
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
return Math.random() * maxInterval;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Send message
|
|
242
|
+
* @param message
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
sendMessage(message) {
|
|
247
|
+
this._ws && this._ws.send(message);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get the ws state
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
getState() {
|
|
255
|
+
return this._ws && this._ws.readyState;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Check if ws is in connecting state
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
isConnecting() {
|
|
263
|
+
return this._ws && this._ws.readyState === 0;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Check if ws is connected
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
isConnected() {
|
|
271
|
+
return this._ws && this._ws.readyState === 1;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Check if ws is in closing state
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
isClosing() {
|
|
279
|
+
return this._ws && this._ws.readyState === 2;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Check if ws is closed
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
isClosed() {
|
|
287
|
+
return this._ws && this._ws.readyState === 3;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Close the connection
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
close() {
|
|
295
|
+
clearInterval(this._heartbeatInterval);
|
|
296
|
+
this._cfg.mustReconnect = false;
|
|
297
|
+
|
|
298
|
+
if (!this.isClosing() || !this.isClosed()) {
|
|
299
|
+
this._ws.close();
|
|
300
|
+
|
|
301
|
+
this._cfg.debug && console.error('Websocket closed.');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
exports.default = WSClient;
|