Skip to content

Commit

Permalink
3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RSamaium committed Nov 27, 2023
1 parent 8ead762 commit aa11d8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sync-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-room-client",
"version": "3.0.0",
"version": "3.0.1",
"description": "",
"main": "./dist/simple-room-client.umd.cjs",
"module": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion sync-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-room",
"version": "3.0.0",
"version": "3.0.2",
"description": "",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
22 changes: 17 additions & 5 deletions sync-server/src/testing/mock-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,35 @@ class MiddlewareHandler {


class MockIo {
events: Map<string, any> = new Map()
events: Map<string, any[]> = new Map()
eventsOnce: Map<string, any> = new Map()

on(name: string, value) {
this.events.set(name, value)
this.events.set(name, [...(this.events.get(name) || []), value])
}

off(name: string) {
if (this.eventsOnce.has(name)) {
this.eventsOnce.delete(name)
return
}
this.events.delete(name)
}

once(name: string, value) {
this.on(name, value)
this.eventsOnce.set(name, value)
}

_trigger(name: string, data, client?) {
const fn = this.events.get(name)
if (fn) fn(data, client)
const events = this.events.get(name) || []
for (const event of events) {
event(data, client)
}
const eventOnce = this.eventsOnce.get(name)
if (eventOnce) {
eventOnce(data, client)
this.eventsOnce.delete(name)
}
}
}

Expand Down

0 comments on commit aa11d8b

Please sign in to comment.