diff --git a/cli.js b/cli.js index 4cb8701..df8520d 100755 --- a/cli.js +++ b/cli.js @@ -31,7 +31,7 @@ const out = (text, color) => { } } -const server = new WebSocket.Server({ port: 8080 }); +const server = new WebSocket.Server({ port: 3456 }); server.on('connection', (ws) => { ws.on('message', (message) => { diff --git a/index.d.ts b/index.d.ts index d7f170e..5e1510a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,2 +1,7 @@ -export default tconsole; -declare function tconsole(options: any = {}): void; +export default termsole; +interface Options { + host?: string; + port?: number; + ssl?: boolean; +} +declare function termsole(options: Options = {}): void; diff --git a/index.js b/index.js index 2006049..d40fee9 100755 --- a/index.js +++ b/index.js @@ -4,8 +4,9 @@ let ws = null; const defaultConsole = Object.assign(Object.create(Object.getPrototypeOf(console)), console); const configure = (conn) => { - // already configured - if (console.stdlog) return; + // skip if already configured + if (console._tsconsole_configured) return; + console._tsconsole_configured = true; console.log = (...args) => { sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) })); @@ -27,29 +28,27 @@ const configure = (conn) => { defaultConsole.debug.apply(defaultConsole, args); }; - console.log("[TCONSOLE] CONFIGURED"); } const release = () => { console = defaultConsole; - console.log("[TCONSOLE]: Released"); ws = null; } -const tconsole = (options = {}) => { +const termsole = (options = {}) => { if (ws) return; // already running options = { host: "localhost", - port: 8080, + port: 3456, ssl: false, ...options, } ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`); ws.onopen = () => { - console.log('[TCONSOLE]: connected'); configure(ws); + console.log('[TCONSOLE]: Connected'); }; ws.onclose = (event) => { @@ -81,4 +80,4 @@ const sendWhenConnected = (ws, msg, n = 0, maxTries = 100) => { }, 10); // wait 10 milisecond for the connection... } -export default tconsole; +export default termsole; diff --git a/package.json b/package.json index dfab950..e61ad2e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "tconsole", + "name": "termsole", "version": "1.0.0", "description": "Console log to terminal", "type": "main", @@ -15,8 +15,8 @@ }, "preferGlobal": true, "keywords": [], - "author": "", - "license": "ISC", + "author": "Ngoc Khuat ", + "license": "MIT", "bugs": { "url": "https://github.com/qnkhuat/TConsole/issues" },