Compare commits

..

No commits in common. "79bbf5c144fb8b14ee43cc3d3cd96bd46f8aefa1" and "bb657e5af0fe2156ff783b2b48a8ad7fa40f899c" have entirely different histories.

2 changed files with 157 additions and 166 deletions

21
dist/index.js vendored
View File

@ -71,12 +71,8 @@ export class SwarmClient extends Client {
} }
async _listen() { async _listen() {
if (!this._connectionListener) { if (!this._connectionListener) {
this._connectionListener = this.connectModule( this._connectionListener = this.connectModule("listenConnections", { swarm: this.swarm }, async (socketId) => {
"listenConnections", const socket = this._sockets.get(socketId) ?? (await createSocket(socketId, this));
{ swarm: this.swarm },
async (socketId) => {
const socket =
this._sockets.get(socketId) ?? (await createSocket(socketId, this));
socket.on("close", () => { socket.on("close", () => {
this._sockets.delete(socketId); this._sockets.delete(socketId);
}); });
@ -84,8 +80,7 @@ export class SwarmClient extends Client {
this._sockets.set(socketId, socket); this._sockets.set(socketId, socket);
} }
this.emit("connection", socket); this.emit("connection", socket);
} });
);
} }
await this._connectionListener[1]; await this._connectionListener[1];
this._connectionListener = undefined; this._connectionListener = undefined;
@ -137,13 +132,9 @@ export class Socket extends Client {
await this.swarm.emitAsync("setup", this); await this.swarm.emitAsync("setup", this);
} }
on(event, listener, options) { on(event, listener, options) {
const [update, promise] = this.connectModule( const [update, promise] = this.connectModule("socketListenEvent", { id: this.id, event: event }, (data) => {
"socketListenEvent",
{ id: this.id, event: event },
(data) => {
this.emit(event, data); this.emit(event, data);
} });
);
this.trackEvent(event, update); this.trackEvent(event, update);
promise.then(() => { promise.then(() => {
this.off(event, listener); this.off(event, listener);
@ -178,7 +169,7 @@ export class Socket extends Client {
this.eventUpdates[event].push(update); this.eventUpdates[event].push(update);
} }
} }
export const MODULE = "_AVbH2uOdd4s4hypKB3QqaP1kxJO_Q5m6y4hsEro6dpVJQ"; export const MODULE = "_AVKgzVYC8Sb_qiTA6kw5BDzQ4Ch-8D4sldQJl8dXF9oTw";
export const createClient = factory(SwarmClient, MODULE); export const createClient = factory(SwarmClient, MODULE);
const socketFactory = factory(Socket, MODULE); const socketFactory = factory(Socket, MODULE);
const createSocket = async (...args) => { const createSocket = async (...args) => {

View File

@ -255,7 +255,7 @@ export class Socket extends Client {
} }
} }
export const MODULE = "_AVbH2uOdd4s4hypKB3QqaP1kxJO_Q5m6y4hsEro6dpVJQ"; export const MODULE = "_AVKgzVYC8Sb_qiTA6kw5BDzQ4Ch-8D4sldQJl8dXF9oTw";
export const createClient = factory<SwarmClient>(SwarmClient, MODULE); export const createClient = factory<SwarmClient>(SwarmClient, MODULE);