simple-room-client
Advanced tools
Comparing version
@@ -0,1 +1,4 @@ | ||
type ListenOptions = { | ||
encoded?: boolean; | ||
}; | ||
export declare class WorldClass { | ||
@@ -37,5 +40,6 @@ socket: any; | ||
*/ | ||
listen(socket: any, transformData?: Function): this; | ||
listen(socket: any, options?: ListenOptions): this; | ||
reset(): void; | ||
} | ||
export declare const World: WorldClass; | ||
export {}; |
@@ -53,3 +53,5 @@ import msgpack from 'msgpack-lite'; | ||
*/ | ||
listen(socket, transformData) { | ||
listen(socket, options = {}) { | ||
if (options.encoded === undefined) | ||
options.encoded = true; | ||
this.socket = socket; | ||
@@ -59,6 +61,11 @@ this.socket.on('uid', (response) => { | ||
}); | ||
this.socket.on('connect', () => { | ||
this.obs$.next({}); | ||
}); | ||
this.socket.on('w', (response) => { | ||
const bufView = new Uint8Array(response); | ||
const decode = msgpack.decode(bufView); | ||
const [roomId, time, data] = decode; | ||
if (options.encoded) { | ||
const bufView = new Uint8Array(response); | ||
response = msgpack.decode(bufView); | ||
} | ||
const [roomId, time, data] = response; | ||
const lastRoomId = this.obs$.value.roomId; | ||
@@ -65,0 +72,0 @@ let mergeData = {}; |
{ | ||
"name": "simple-room-client", | ||
"version": "2.0.6", | ||
"version": "3.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/simple-room-client.umd.cjs", |
@@ -8,2 +8,6 @@ import msgpack from 'msgpack-lite' | ||
type ListenOptions = { | ||
encoded?: boolean | ||
} | ||
export class WorldClass { | ||
@@ -60,3 +64,5 @@ socket: any | ||
*/ | ||
listen(socket, transformData?: Function) { | ||
listen(socket, options: ListenOptions = {}) { | ||
if (options.encoded === undefined) options.encoded = true | ||
this.socket = socket | ||
@@ -66,6 +72,16 @@ this.socket.on('uid', (response) => { | ||
}) | ||
this.socket.on('connect', () => { | ||
this.obs$.next({}) | ||
}) | ||
this.socket.on('w', (response) => { | ||
const bufView = new Uint8Array(response) | ||
const decode = msgpack.decode(bufView) | ||
const [roomId, time, data] = decode | ||
if (options.encoded) { | ||
const bufView = new Uint8Array(response) | ||
response = msgpack.decode(bufView) | ||
} | ||
const [roomId, time, data] = response | ||
const lastRoomId = this.obs$.value.roomId | ||
@@ -94,3 +110,3 @@ let mergeData: any = {} | ||
} | ||
if (data.users) { | ||
@@ -97,0 +113,0 @@ mergeData.users = this.users.detectChanges(mergeData.users) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
139561
0.76%3031
0.9%0
-100%