Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ombori/ga-messaging

Package Overview
Dependencies
Maintainers
14
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ombori/ga-messaging - npm Package Compare versions

Comparing version 3.92.12 to 3.92.13

src/ga-messaging.d.ts

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## 3.92.13 (2024-05-30)
### Bug Fixes
* refactored ga-messaging ([0f1b527](https://github.com/ombori/gridapp/commit/0f1b527e66150611fd31f4cea72f10ee56503198))
## 3.92.12 (2024-05-29)

@@ -8,0 +19,0 @@

9

dist/index.d.ts

@@ -11,20 +11,11 @@ export declare type Payload = {

export declare function useSubscribe(type: string, callback: (msg: Payload) => void, deps: any[]): void;
/**
* @obsolete Use setDefaultChannel instead
*/
export declare const setSpaceId: (id: string) => void;
export declare const setDefaultChannel: (channel: string) => void;
export declare const useStatus: () => boolean;
export declare const useHeartbeat: () => void;
export declare const useMobileRemote: (endpoint: string | undefined) => string | null;
declare const _default: {
usePublish: () => typeof send;
useSubscribe: typeof useSubscribe;
setSpaceId: (id: string) => void;
setDefaultChannel: (channel: string) => void;
useStatus: () => boolean;
useHeartbeat: () => void;
useMobileRemote: (endpoint: string | undefined) => string | null;
};
export default _default;
//# sourceMappingURL=index.d.ts.map

107

dist/index.js

@@ -25,3 +25,4 @@ var __assign = (this && this.__assign) || function () {

import remote from './remote';
var RECONNECT_TIMEOUT = 10000;
var RECONNECT_TIMEOUT = 5000; // 5 seconds
var CONNECTION_TIMEOUT = 3000; // 4 seconds
// Cypress has no "process", to prevent it crashing

@@ -32,3 +33,3 @@ var _a = (process && process.env) || {

var isDevelMode = NODE_ENV === 'development' && REACT_APP_MESSAGING_URL;
var ADDRESS = isDevelMode ? REACT_APP_MESSAGING_URL : 'wss://GdmAgent:8080';
var ADDRESS = isDevelMode ? REACT_APP_MESSAGING_URL : 'wss://gdmagent:8080';
if (isDevelMode) {

@@ -43,24 +44,26 @@ console.warn('Development mode enabled, connecting to ', ADDRESS);

var onmessage = _a.onmessage, onclose = _a.onclose;
// @ts-ignore
var grid = window.grid; // A socket injected by web-runtime (tizen/android/web)
if (grid && grid.socket) {
console.log('Grid-messaging: a grid socket detected, using it');
}
else {
console.log("Grid-messaging: connecting to " + ADDRESS);
}
if (grid && grid.socket) {
socket = grid.socket;
}
else {
if (!socket || socket.readyState !== WebSocket.OPEN) {
if (socket)
socket.onclose = function () { }; // dont let the old socket interfere
socket = new WebSocket(ADDRESS);
console.log("Grid-messaging: connecting to " + ADDRESS);
socket = new WebSocket(ADDRESS);
var connectionTimeout = setTimeout(function () {
if (socket && socket.readyState !== WebSocket.OPEN) {
console.warn('Connection attempt timed out, closing socket');
socket.close();
}
}
}, CONNECTION_TIMEOUT);
socket.onmessage = onmessage;
socket.onclose = onclose;
socket.onopen = function () { return console.log('ws connected'); };
socket.onerror = function (err) { return console.error('ws error', err); };
socket.onclose = function () {
clearTimeout(connectionTimeout);
console.log("ws disconnected, reconnecting in " + RECONNECT_TIMEOUT + "ms");
setTimeout(function () {
open({ onmessage: onmessage, onclose: onclose });
}, RECONNECT_TIMEOUT);
};
socket.onopen = function () {
clearTimeout(connectionTimeout);
console.log('ws connected');
};
socket.onerror = function (err) {
clearTimeout(connectionTimeout);
console.error('ws error', err);
};
};

@@ -77,9 +80,4 @@ function send() {

return socket.send(JSON.stringify(message));
// To avoid extra message proxying (and reduce latency) we handle mobile remotes directly in this library,
// all related messages are going directly to the server, skipping grid-os message bus
if (remote.isRemoteMessage(type))
return remote.publish(type, message);
if (type.indexOf('/') < 0) {
type = defaultChannel + "/" + type;
}
socket.send(JSON.stringify(__assign(__assign({}, message), { type: type })));

@@ -95,5 +93,2 @@ }

var _a = JSON.parse(incomingEvent.data), type_1 = _a.type, message_1 = __rest(_a, ["type"]);
if (type_1.indexOf('/') < 0) {
type_1 = defaultChannel + "/" + type_1;
}
handlers.forEach(function (_a) {

@@ -111,6 +106,3 @@ var handlerType = _a[0], handler = _a[1];

var onclose = function () {
console.log("ws disconnected, reconnect in " + RECONNECT_TIMEOUT + "ms");
setTimeout(function () {
open({ onmessage: onmessage, onclose: onclose });
}, RECONNECT_TIMEOUT);
console.log('ws disconnected');
};

@@ -125,8 +117,4 @@ open({

return remote.subscribe(type, callback);
var msgType = type;
if (type.indexOf('/') < 0) {
msgType = defaultChannel + "/" + type;
}
useEffect(function () {
var entry = [msgType, callback];
var entry = [type, callback];
handlers.push(entry);

@@ -138,38 +126,6 @@ return function () {

}
var defaultChannel = 'message';
/**
* @obsolete Use setDefaultChannel instead
*/
export var setSpaceId = function (id) { return setDefaultChannel(id); };
export var setDefaultChannel = function (channel) {
var url = ADDRESS;
// $samehost/anonymous stands for 'anonymous message bus on the same device via insecure websocket'
// this is intended for use with local mobile apps
if (channel === '$samehost/anonymous' || channel === 'mobileapp') {
var host = document.location.host;
url = "ws://" + host;
defaultChannel = 'mobileapp';
if (isDevelMode) {
console.log('setSpaceId is ignored in development mode');
return;
}
}
if (/^remote\//.test(channel)) {
var _a = channel.split('/'), id = _a[1];
url = "wss://ombori-mobile-endpoint.northeurope.cloudapp.azure.com/" + id;
defaultChannel = 'remote';
}
if (/^wss?:\/\//.test(channel)) {
url = channel;
}
if (url !== ADDRESS) {
ADDRESS = url;
socket.close();
open({ onmessage: onmessage, onclose: onclose }); // reconnect immediately
}
};
export var useStatus = function () {
var _a = useState(false), conn = _a[0], setConn = _a[1];
useEffect(function () {
var int = setInterval(function () { return setConn(socket && socket.readyState == socket.OPEN); }, 1000);
var int = setInterval(function () { return setConn(socket && socket.readyState === WebSocket.OPEN); }, 1000);
return function () { return clearInterval(int); };

@@ -188,14 +144,7 @@ }, []);

};
export var useMobileRemote = function (endpoint) {
var id = remote.useId();
return endpoint && id ? endpoint + "#" + id : null;
};
export default {
usePublish: usePublish,
useSubscribe: useSubscribe,
setSpaceId: setSpaceId,
setDefaultChannel: setDefaultChannel,
useStatus: useStatus,
useHeartbeat: useHeartbeat,
useMobileRemote: useMobileRemote,
};
{
"name": "@ombori/ga-messaging",
"version": "3.92.12",
"version": "3.92.13",
"main": "dist/index.js",

@@ -16,3 +16,3 @@ "license": "UNLICENSED",

},
"gitHead": "1544054cc3de075ec1639075411b43c66e3d1120"
"gitHead": "1e0caf5875b06e1daa14a48a8f7c7a3e422d3752"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc