mirror of
https://github.com/robbie-cahill/tunnelmole-client.git
synced 2026-08-24 02:34:13 -05:00
Sending connection info
This commit is contained in:
@@ -33,7 +33,7 @@ export default async function dispatchCommand(arg0 : any, command : Command) {
|
||||
|
||||
if (options.port) {
|
||||
// We have enough to Launch Tunnelmole
|
||||
tunnelmole(options);
|
||||
tunnelmole(options, true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { ConnectionInfo } from "../websocket/connection-info";
|
||||
|
||||
export default interface InitialiseMessage
|
||||
{
|
||||
type: string,
|
||||
clientId: string,
|
||||
apiKey?: string,
|
||||
subdomain?: string,
|
||||
connectionInfo: ConnectionInfo
|
||||
}
|
||||
+6
-1
@@ -4,10 +4,15 @@ import { initStorage } from './node-persist/storage.js';
|
||||
import { eventHandler, URL_ASSIGNED } from './events/event-handler.js';
|
||||
import { setUpAutoReconnect } from './websocket/setup-auto-reconnect.js';
|
||||
import { connect } from './websocket/connect.js';
|
||||
import { setIsCli } from './websocket/connection-info-service.js';
|
||||
|
||||
export default async function tunnelmole(options: Options): Promise<string> {
|
||||
export default async function tunnelmole(
|
||||
options: Options,
|
||||
isCli = false
|
||||
): Promise<string> {
|
||||
await initStorage();
|
||||
await initialiseClientId();
|
||||
setIsCli(isCli);
|
||||
|
||||
// Set port to 3000 if port is not specified
|
||||
if (options.port === undefined) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import validator from 'validator';
|
||||
import { messageHandlers } from "../../message-handlers.js";
|
||||
import HostipWebSocket from "./host-ip-websocket.js";
|
||||
import config from "../../config.js";
|
||||
import { getConnectionInfo } from "./connection-info-service.js";
|
||||
|
||||
const connect = (options: Options): HostipWebSocket => {
|
||||
const websocket = new HostipWebSocket(config.hostip.endpoint);
|
||||
@@ -16,9 +17,13 @@ const connect = (options: Options): HostipWebSocket => {
|
||||
const sendInitialiseMessage = async () => {
|
||||
log("Sending initialise message");
|
||||
|
||||
// Give the server basic information on the Node version and if we are using CLI or not (in which case, tunnelmole is being run from JS code)
|
||||
const connectionInfo = getConnectionInfo();
|
||||
|
||||
const initialiseMessage: InitialiseMessage = {
|
||||
type: initialise,
|
||||
clientId: await getClientId()
|
||||
clientId: await getClientId(),
|
||||
connectionInfo
|
||||
};
|
||||
|
||||
// Set api key if we have one available
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ConnectionInfo } from "./connection-info";
|
||||
|
||||
/**
|
||||
* Basic connection info, to be used for upgrade notifications and the like
|
||||
*/
|
||||
const connectionInfo: ConnectionInfo = {
|
||||
isCli: false,
|
||||
isNpm: Boolean(process.env.npm_lifecycle_event),
|
||||
nodeVersion: process.version
|
||||
}
|
||||
|
||||
const setIsCli = (isCli: boolean) => {
|
||||
connectionInfo.isCli = isCli;
|
||||
};
|
||||
|
||||
const getConnectionInfo = () => {
|
||||
return connectionInfo;
|
||||
}
|
||||
|
||||
export {
|
||||
getConnectionInfo,
|
||||
setIsCli
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
interface ConnectionInfo {
|
||||
isCli: boolean,
|
||||
isNpm: boolean,
|
||||
nodeVersion: string
|
||||
}
|
||||
|
||||
export { ConnectionInfo }
|
||||
Reference in New Issue
Block a user