document-process-manager
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -5,2 +5,3 @@ import path from 'node:path' | ||
import watch from 'glob-watcher' | ||
import { WebSocketServer } from 'ws' | ||
import Socket from './socket/index.js' | ||
@@ -14,2 +15,6 @@ export default class Sockets extends EventTarget { | ||
#target | ||
#boundAdd | ||
#boundChange | ||
#boundUnlink | ||
#boundServerUpgrade | ||
#_watcher | ||
@@ -21,5 +26,10 @@ #_boundAdd | ||
super() | ||
this.#boundServerUpgrade = this.#serverUpgrade.bind(this) | ||
this.#boundAdd = this.#add.bind(this) | ||
this.#boundChange = this.#change.bind(this) | ||
this.#boundUnlink = this.#unlink.bind(this) | ||
this.#settings = $settings | ||
this.#dpm = $dpm | ||
this.#watcher | ||
this.server.on('upgrade', this.#boundServerUpgrade) | ||
} | ||
@@ -58,17 +68,17 @@ get server() { return this.#dpm.server } | ||
} | ||
get #boundAdd() { | ||
if(this.#_boundAdd !== undefined) { return this.#_boundAdd} | ||
this.#_boundAdd = this.#add.bind(this) | ||
return this.#_boundAdd | ||
#serverUpgrade($request, $socket, $head) { | ||
iterateSockets: | ||
for(const $webSocket of Array.from(this)) { | ||
const { pathname } = new URL($request.url, $webSocket.url.origin) | ||
if( | ||
pathname === $webSocket.url.pathname && | ||
$webSocket.active === true | ||
) { | ||
$webSocket.webSocketServer.handleUpgrade($request, $socket, $head, function done($ws) { | ||
$webSocket.webSocketServer.emit('connection', $ws, $request) | ||
}) | ||
break iterateSockets | ||
} | ||
} | ||
} | ||
get #boundChange() { | ||
if(this.#_boundChange !== undefined) { return this.#_boundChange} | ||
this.#_boundChange = this.#change.bind(this) | ||
return this.#_boundChange | ||
} | ||
get #boundUnlink() { | ||
if(this.#_boundUnlink !== undefined) { return this.#_boundUnlink} | ||
this.#_boundUnlink = this.#unlink.bind(this) | ||
return this.#_boundUnlink | ||
} | ||
async #add($path) { | ||
@@ -75,0 +85,0 @@ const socketPath = path.join(process.env.PWD, $path) |
@@ -13,2 +13,3 @@ import { URL } from 'node:url' | ||
#url | ||
constructor($settings, $sockets) { | ||
@@ -51,3 +52,3 @@ super() | ||
path: this.url.pathname, | ||
server: this.#sockets.server, | ||
noServer: true, | ||
}) | ||
@@ -73,4 +74,4 @@ this.#webSocketServer.on('connection', this.#websocketServerConnection.bind(this)) | ||
#websocketServerError($error) { console.error($error) } | ||
#websocketOpen() {} | ||
#websocketClose() {} | ||
#websocketOpen($event) { console.log($event) } | ||
#websocketClose($event) { console.log($event) } | ||
#websocketError($error) { console.error($error) } | ||
@@ -77,0 +78,0 @@ #websocketMessage($data, $isBinary) { |
@@ -5,3 +5,3 @@ { | ||
"description": "Document Process Manager (DPM)", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"license": "ISC", | ||
@@ -8,0 +8,0 @@ "type": "module", |
67104
1560