@bloopjs/web 0.0.80 → 0.0.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/netcode/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAIrC,MAAM,MAAM,uBAAuB,GAAG;IACpC,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,uBAAuB,GAC7B,IAAI,CAqJN"}
1
+ {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/netcode/scaffold.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAIrC,MAAM,MAAM,uBAAuB,GAAG;IACpC,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,uBAAuB,GAC7B,IAAI,CAmJN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloopjs/web",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "author": "Neil Sarkar",
5
5
  "type": "module",
6
6
  "repository": {
@@ -33,8 +33,8 @@
33
33
  "typescript": "^5"
34
34
  },
35
35
  "dependencies": {
36
- "@bloopjs/bloop": "0.0.80",
37
- "@bloopjs/engine": "0.0.80",
36
+ "@bloopjs/bloop": "0.0.82",
37
+ "@bloopjs/engine": "0.0.82",
38
38
  "@preact/signals": "^1.3.1",
39
39
  "partysocket": "^1.1.6",
40
40
  "preact": "^10.25.4"
@@ -1,3 +1,4 @@
1
+ import { unwrap } from "@bloopjs/bloop";
1
2
  import type { App } from "../App.ts";
2
3
  import * as Debug from "../debugui/mod.ts";
3
4
  import { logger } from "./logs.ts";
@@ -40,13 +41,16 @@ export function joinRollbackRoom(
40
41
 
41
42
  function receivePackets() {
42
43
  for (const packetData of incomingPackets) {
43
- app.sim.net.receivePacket(packetData);
44
+ app.sim.emit.packet(packetData);
44
45
 
45
46
  if (remotePeerId == null) {
46
47
  return;
47
48
  }
48
49
 
49
- const peerState = app.sim.net.getPeerState(remotePeerId);
50
+ const peerState = unwrap(
51
+ app.sim.net.peers[remotePeerId],
52
+ `Remote peer state not found for peerId ${remotePeerId}`,
53
+ );
50
54
  Debug.updatePeer(remoteStringPeerId!, {
51
55
  ack: peerState.ack,
52
56
  seq: peerState.seq,
@@ -70,7 +74,7 @@ export function joinRollbackRoom(
70
74
  return;
71
75
  }
72
76
 
73
- const packet = app.sim.net.getOutboundPacket(remotePeerId);
77
+ const packet = app.sim.getOutboundPacket(remotePeerId);
74
78
 
75
79
  if (!packet) {
76
80
  console.warn("[netcode] No packet to send");
@@ -87,7 +91,6 @@ export function joinRollbackRoom(
87
91
 
88
92
  app.joinRoom(roomId, {
89
93
  onPeerIdAssign: (peerId) => {
90
- console.log(`Assigned peer ID: ${peerId}`);
91
94
  localStringPeerId = peerId;
92
95
  },
93
96
  onBrokerMessage: (_message) => {},
@@ -95,15 +98,13 @@ export function joinRollbackRoom(
95
98
  incomingPackets.push(new Uint8Array(data));
96
99
  },
97
100
  onDataChannelClose(peerId, reliable) {
98
- console.log(`Data channel closed: ${peerId} (reliable: ${reliable})`);
99
101
  if (!reliable && remotePeerId !== null) {
100
- app.sim.net.disconnectPeer(remotePeerId);
102
+ app.sim.emit.network("peer:leave", { peerId: remotePeerId });
101
103
  sessionActive = false;
102
104
  opts?.onSessionEnd?.();
103
105
  }
104
106
  },
105
107
  onDataChannelOpen(peerId, reliable, channel) {
106
- console.log(`Data channel opened: ${peerId} (reliable: ${reliable})`);
107
108
  if (!reliable) {
108
109
  udp = channel;
109
110
 
@@ -119,15 +120,13 @@ export function joinRollbackRoom(
119
120
  remoteStringPeerId = peerId;
120
121
  Debug.setRemoteId(remotePeerId);
121
122
 
122
- // Initialize the session in the engine (2 players)
123
- app.sim.sessionInit(2);
124
-
125
123
  // Set up local and remote peers in net state
126
- app.sim.net.setLocalPeer(localPeerId);
127
- app.sim.net.connectPeer(remotePeerId);
124
+ app.sim.emit.network("peer:join", { peerId: localPeerId });
125
+ app.sim.emit.network("peer:join", { peerId: remotePeerId });
126
+ app.sim.emit.network("peer:assign_local_id", { peerId: localPeerId });
127
+ app.sim.emit.network("session:start", {});
128
128
 
129
129
  sessionActive = true;
130
- console.log(`[netcode] Session started at frame ${app.sim.time.frame}`);
131
130
  opts?.onSessionStart?.();
132
131
  }
133
132
  },
@@ -146,7 +145,7 @@ export function joinRollbackRoom(
146
145
  onPeerDisconnected(peerId) {
147
146
  Debug.removePeer(peerId);
148
147
  if (remotePeerId !== null && peerId === remoteStringPeerId) {
149
- app.sim.net.disconnectPeer(remotePeerId);
148
+ app.sim.emit.network("peer:leave", { peerId: remotePeerId });
150
149
  sessionActive = false;
151
150
  opts?.onSessionEnd?.();
152
151
  }