Skip to content

Commit

Permalink
Fix: Ensure reference to storage is not being returned, only a copy F…
Browse files Browse the repository at this point in the history
…eat: Add .isHost property
  • Loading branch information
therealPaulPlay committed Jan 25, 2025
1 parent 972f16e commit 36aa176
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Using a uuid is recommended, but it is also fine to use any other random string.
your application's name in the `id` can help to prevent overlap (e.g. your-app-012345abcdef).

- `id`: Peer's unique identifier
- `isHost`: If this peer is currently hosting or not
- `connectionCount`: Number of active peer connections (without you)
- `getStorage`: Retrieve storage object

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playpeerjs",
"version": "1.1.0",
"version": "1.1.1",
"description": "WebRTC-based wrapper for creating robust peer-2-peer multiplayer systems with ease.",
"type": "module",
"main": "dist/playpeer.js",
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ export default class PlayPeer {
* @returns {object} Get storage object
*/
get getStorage() {
return this.#storage || {};
return { ...this.#storage } || {};
}

/**
* @returns {boolean} Check if this peer is hosting
*/
get isHost() {
return this.#isHost;
}
}

0 comments on commit 36aa176

Please sign in to comment.