openrtc-netcode 2.0.1 → 2.1.0
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.
- package/README.md +1 -1
- package/dist/client.d.ts +3 -112
- package/dist/client.js +16 -16
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/objects.d.ts +1 -1
- package/dist/objects.js +1 -1
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +2 -2
- package/dist/roomRuntime.d.ts +2 -2
- package/dist/roomRuntime.js +4 -4
- package/dist/types.d.ts +13 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ relay/direct, WebRTC DataChannel upgrades, and MoQ routes when enabled. Live
|
|
|
10
10
|
membership and signaling use the OpenRTC coordination gateway; neither core
|
|
11
11
|
netcode nor its payload path uses Firebase, Firestore, or RTDB.
|
|
12
12
|
|
|
13
|
-
`
|
|
13
|
+
`preferredTransports` filters OpenRTC's typed application-readiness
|
|
14
14
|
query; it does not request promotion. OpenRTC owns optional transport promotion
|
|
15
15
|
and recovery, while netcode only observes route events. Netcode consumes one
|
|
16
16
|
already-activated room handle, so it never retains an unused user or space
|
package/dist/client.d.ts
CHANGED
|
@@ -1,112 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { CreateLobbyOptions, JoinLobbyOptions, NetcodeClient as NetcodeClientInterface, NetcodeEventHandler, NetcodeEventName, NetcodeLobby, NetcodeMessageHandler, NetcodeOptions, NetcodePeer, NetcodePeerStats, SendOptions } from './types.js';
|
|
5
|
-
export declare class OpenRtcNetcodeClient implements NetcodeClientInterface {
|
|
6
|
-
private readonly options;
|
|
7
|
-
private runtime;
|
|
8
|
-
private localPeerId;
|
|
9
|
-
private currentLobby;
|
|
10
|
-
private currentRoomId;
|
|
11
|
-
private fallbackChannel;
|
|
12
|
-
private lobbyMetadata;
|
|
13
|
-
private memberMetadata;
|
|
14
|
-
private seq;
|
|
15
|
-
private started;
|
|
16
|
-
private stopped;
|
|
17
|
-
private stopWatchingRoom;
|
|
18
|
-
private stopRuntimeConnections;
|
|
19
|
-
private stopIncomingNetcodeChannel;
|
|
20
|
-
private peerPingTimer;
|
|
21
|
-
private readonly emitter;
|
|
22
|
-
private readonly messageListeners;
|
|
23
|
-
private readonly peersById;
|
|
24
|
-
private readonly peerStatsById;
|
|
25
|
-
private readonly connectionsByPeer;
|
|
26
|
-
private readonly channelsByPeer;
|
|
27
|
-
private readonly pendingChannelsByPeer;
|
|
28
|
-
private readonly connectionIds;
|
|
29
|
-
private readonly pendingPeerIds;
|
|
30
|
-
private readonly directSendWarnings;
|
|
31
|
-
private readonly introPeerIds;
|
|
32
|
-
private readonly seenEnvelopeIds;
|
|
33
|
-
private readonly seenEnvelopeOrder;
|
|
34
|
-
private readonly latestStateQueues;
|
|
35
|
-
private readonly stateStore;
|
|
36
|
-
private readonly objectStore;
|
|
37
|
-
private readonly voiceController;
|
|
38
|
-
constructor(options?: NetcodeOptions);
|
|
39
|
-
get peerId(): string | null;
|
|
40
|
-
get lobby(): NetcodeLobby | null;
|
|
41
|
-
get peers(): NetcodePeer[];
|
|
42
|
-
get peerStats(): NetcodePeerStats[];
|
|
43
|
-
get state(): ReplicatedState;
|
|
44
|
-
get objects(): ReplicatedObjectStore;
|
|
45
|
-
get voice(): NetcodeVoiceController;
|
|
46
|
-
start(): Promise<void>;
|
|
47
|
-
stop(): Promise<void>;
|
|
48
|
-
createLobby(options?: CreateLobbyOptions): Promise<NetcodeLobby>;
|
|
49
|
-
joinLobby(lobbyId: string, options?: JoinLobbyOptions): Promise<NetcodeLobby>;
|
|
50
|
-
joinOrCreateLobby(lobbyId: string, options?: JoinLobbyOptions): Promise<NetcodeLobby>;
|
|
51
|
-
private activateLobby;
|
|
52
|
-
private joinLobbyWithRetry;
|
|
53
|
-
private getRoomMembersWithRetry;
|
|
54
|
-
leaveLobby(): Promise<void>;
|
|
55
|
-
send(peerId: string, type: string, payload: unknown, options?: SendOptions): Promise<void>;
|
|
56
|
-
broadcast(type: string, payload: unknown, options?: SendOptions): Promise<void>;
|
|
57
|
-
on<K extends NetcodeEventName>(event: K, handler: NetcodeEventHandler<K>): () => void;
|
|
58
|
-
onMessage<T = unknown>(type: string, handler: NetcodeMessageHandler<T>): () => void;
|
|
59
|
-
setLobbyData(key: string, value: string): Promise<void>;
|
|
60
|
-
setMemberData(key: string, value: string): Promise<void>;
|
|
61
|
-
private handleRoomMembers;
|
|
62
|
-
private reconcileMesh;
|
|
63
|
-
private attachConnection;
|
|
64
|
-
private sendPeerIntro;
|
|
65
|
-
private queuePeerIntro;
|
|
66
|
-
private handleConnectionMessage;
|
|
67
|
-
private markEnvelopeSeen;
|
|
68
|
-
private handleHello;
|
|
69
|
-
private handleUserMessage;
|
|
70
|
-
private handleStateSnapshot;
|
|
71
|
-
private handleStatePatch;
|
|
72
|
-
private handleObjectSnapshot;
|
|
73
|
-
private handleObjectUpsert;
|
|
74
|
-
private handleObjectRemove;
|
|
75
|
-
private handleLobbyMetadata;
|
|
76
|
-
private handleMemberMetadata;
|
|
77
|
-
private handleVoiceSignal;
|
|
78
|
-
private handlePong;
|
|
79
|
-
private sendStateSnapshot;
|
|
80
|
-
private sendObjectSnapshot;
|
|
81
|
-
private broadcastMemberMetadata;
|
|
82
|
-
private startPeerPingLoop;
|
|
83
|
-
private refreshPeerPayloadState;
|
|
84
|
-
private stopPeerPingLoop;
|
|
85
|
-
private broadcastEnvelope;
|
|
86
|
-
private broadcastLatestState;
|
|
87
|
-
private sendEnvelope;
|
|
88
|
-
private sendDirectEnvelope;
|
|
89
|
-
private warnDirectSendFailure;
|
|
90
|
-
private openFallbackChannel;
|
|
91
|
-
private closeFallbackChannel;
|
|
92
|
-
private resolveNetcodeChannel;
|
|
93
|
-
private resolvePeerTicket;
|
|
94
|
-
private attachNetcodeChannel;
|
|
95
|
-
private registerIncomingNetcodeChannel;
|
|
96
|
-
private readIncomingNetcodeStream;
|
|
97
|
-
private closeNetcodeChannels;
|
|
98
|
-
private createEnvelope;
|
|
99
|
-
private resolveStateOwner;
|
|
100
|
-
private upsertPeer;
|
|
101
|
-
private updatePeerStats;
|
|
102
|
-
private resolvePeerTransport;
|
|
103
|
-
private isPeerPayloadReady;
|
|
104
|
-
private resolvePayloadConnection;
|
|
105
|
-
private payloadReadinessOptions;
|
|
106
|
-
private refreshLobby;
|
|
107
|
-
private requireRuntime;
|
|
108
|
-
private requireLobby;
|
|
109
|
-
private registerNetcodeChannel;
|
|
110
|
-
}
|
|
111
|
-
export declare function createNetcode(options?: NetcodeOptions): OpenRtcNetcodeClient;
|
|
112
|
-
export declare function shouldInitiateConnection(localPeerId: string, remotePeerId: string): boolean;
|
|
1
|
+
import type { NetcodeClient as NetcodeClientInterface, NetcodeOptions } from './types.js';
|
|
2
|
+
export declare function createNetcode(options?: NetcodeOptions): NetcodeClientInterface;
|
|
3
|
+
export declare function shouldInitiate(localPeerId: string, remotePeerId: string): boolean;
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypedEmitter } from './events.js';
|
|
2
|
-
import { decodeEnvelope, encodeEnvelope, isRecord, NETCODE_PROTOCOL,
|
|
3
|
-
import { isNetcodeObjectState,
|
|
2
|
+
import { decodeEnvelope, encodeEnvelope, isRecord, NETCODE_PROTOCOL, PROTOCOL_VERSION, } from './protocol.js';
|
|
3
|
+
import { isNetcodeObjectState, ObjectStore } from './objects.js';
|
|
4
4
|
import { ReplicatedState } from './state.js';
|
|
5
5
|
import { NetcodeVoiceController } from './voice.js';
|
|
6
6
|
import { runtimeFromRoom } from './roomRuntime.js';
|
|
@@ -13,7 +13,7 @@ const CHANNEL_OPEN_TIMEOUT_MS = 15000;
|
|
|
13
13
|
const UPGRADED_PAYLOAD_TRANSPORTS = new Set(['webrtc', 'webrtc-lan', 'moq']);
|
|
14
14
|
const textEncoder = new TextEncoder();
|
|
15
15
|
const textDecoder = new TextDecoder();
|
|
16
|
-
|
|
16
|
+
class ClientImpl {
|
|
17
17
|
constructor(options = {}) {
|
|
18
18
|
this.options = options;
|
|
19
19
|
this.runtime = null;
|
|
@@ -45,8 +45,8 @@ export class OpenRtcNetcodeClient {
|
|
|
45
45
|
this.seenEnvelopeOrder = [];
|
|
46
46
|
this.latestStateQueues = new Map();
|
|
47
47
|
this.stateStore = new ReplicatedState((options) => this.resolveStateOwner(options), (key, value, owner) => this.broadcastLatestState(`state:${key}`, 'state.patch', { key, value, owner }));
|
|
48
|
-
this.objectStore = new
|
|
49
|
-
this.voiceController = new NetcodeVoiceController(() => this.localPeerId, () => this.peers,
|
|
48
|
+
this.objectStore = new ObjectStore(() => this.localPeerId, (object) => this.broadcastLatestState(`object:${object.id}`, 'object.upsert', { object }), (id) => this.broadcastEnvelope('object.remove', { id }));
|
|
49
|
+
this.voiceController = new NetcodeVoiceController(() => this.localPeerId, () => this.peers, shouldInitiate, (peerId, signal) => this.sendEnvelope(peerId, 'voice.signal', { signal }));
|
|
50
50
|
}
|
|
51
51
|
get peerId() {
|
|
52
52
|
return this.localPeerId;
|
|
@@ -318,7 +318,7 @@ export class OpenRtcNetcodeClient {
|
|
|
318
318
|
// restart reciprocal application-key agreement on an already-admitted
|
|
319
319
|
// physical connection. Explicit legacy/test runtimes retain the
|
|
320
320
|
// deterministic mesh dial below.
|
|
321
|
-
if (this.runtime.
|
|
321
|
+
if (this.runtime.lifecycle) {
|
|
322
322
|
return;
|
|
323
323
|
}
|
|
324
324
|
const maxPeers = this.options.maxPeers ?? DEFAULT_MAX_PEERS;
|
|
@@ -326,7 +326,7 @@ export class OpenRtcNetcodeClient {
|
|
|
326
326
|
if (this.connectionsByPeer.size >= maxPeers) {
|
|
327
327
|
return;
|
|
328
328
|
}
|
|
329
|
-
if (!peer.ticket || !
|
|
329
|
+
if (!peer.ticket || !shouldInitiate(this.localPeerId, peer.id)) {
|
|
330
330
|
continue;
|
|
331
331
|
}
|
|
332
332
|
if (this.connectionsByPeer.has(peer.id) || this.pendingPeerIds.has(peer.id)) {
|
|
@@ -827,11 +827,11 @@ export class OpenRtcNetcodeClient {
|
|
|
827
827
|
}
|
|
828
828
|
registerIncomingNetcodeChannel() {
|
|
829
829
|
const runtime = this.runtime;
|
|
830
|
-
if (typeof runtime?.
|
|
830
|
+
if (typeof runtime?.onChannelStream !== 'function') {
|
|
831
831
|
return;
|
|
832
832
|
}
|
|
833
833
|
this.stopIncomingNetcodeChannel?.();
|
|
834
|
-
this.stopIncomingNetcodeChannel = runtime.
|
|
834
|
+
this.stopIncomingNetcodeChannel = runtime.onChannelStream(NETCODE_CHANNEL_ID, (incoming) => {
|
|
835
835
|
if (incoming.type !== 'bi' || !incoming.remoteNodeId || !incoming.stream) {
|
|
836
836
|
return false;
|
|
837
837
|
}
|
|
@@ -885,7 +885,7 @@ export class OpenRtcNetcodeClient {
|
|
|
885
885
|
}
|
|
886
886
|
return {
|
|
887
887
|
protocol: NETCODE_PROTOCOL,
|
|
888
|
-
v:
|
|
888
|
+
v: PROTOCOL_VERSION,
|
|
889
889
|
kind,
|
|
890
890
|
lobbyId: this.currentRoomId,
|
|
891
891
|
from: this.localPeerId,
|
|
@@ -964,21 +964,21 @@ export class OpenRtcNetcodeClient {
|
|
|
964
964
|
return channel.connection;
|
|
965
965
|
}
|
|
966
966
|
const runtime = this.runtime;
|
|
967
|
-
if (typeof runtime?.
|
|
968
|
-
return runtime.
|
|
967
|
+
if (typeof runtime?.readyConnections === 'function') {
|
|
968
|
+
return runtime.readyConnections(this.payloadReadinessOptions())
|
|
969
969
|
.find((connection) => connection.remoteNodeId === peerId || connection.deviceId === peerId)
|
|
970
970
|
?? null;
|
|
971
971
|
}
|
|
972
972
|
return this.connectionsByPeer.get(peerId) ?? null;
|
|
973
973
|
}
|
|
974
974
|
payloadReadinessOptions() {
|
|
975
|
-
const preferredTransports = this.options.
|
|
975
|
+
const preferredTransports = this.options.preferredTransports ?? [];
|
|
976
976
|
if (preferredTransports.length === 0) {
|
|
977
977
|
return {};
|
|
978
978
|
}
|
|
979
979
|
return {
|
|
980
980
|
preferredTransports,
|
|
981
|
-
|
|
981
|
+
allowFallback: true,
|
|
982
982
|
};
|
|
983
983
|
}
|
|
984
984
|
refreshLobby(members) {
|
|
@@ -1028,9 +1028,9 @@ export class OpenRtcNetcodeClient {
|
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
1030
1030
|
export function createNetcode(options = {}) {
|
|
1031
|
-
return new
|
|
1031
|
+
return new ClientImpl(options);
|
|
1032
1032
|
}
|
|
1033
|
-
export function
|
|
1033
|
+
export function shouldInitiate(localPeerId, remotePeerId) {
|
|
1034
1034
|
return localPeerId.localeCompare(remotePeerId) < 0;
|
|
1035
1035
|
}
|
|
1036
1036
|
function normalizeLobbyId(lobbyId) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createNetcode, shouldInitiate, } from './client.js';
|
|
2
2
|
export { runtimeFromRoom } from './roomRuntime.js';
|
|
3
|
-
export {
|
|
4
|
-
export { NETCODE_PROTOCOL,
|
|
3
|
+
export { ObjectStore } from './objects.js';
|
|
4
|
+
export { NETCODE_PROTOCOL, PROTOCOL_VERSION, decodeEnvelope, encodeEnvelope, isEnvelopeKind, } from './protocol.js';
|
|
5
5
|
export type { HelloBody, MetadataBody, NetcodeEnvelope, NetcodeEnvelopeKind, ObjectRemoveBody, ObjectSnapshotBody, ObjectUpsertBody, StatePatchBody, StateSnapshotBody, UserMessageBody, VoiceSignalBody, } from './protocol.js';
|
|
6
|
-
export type { CreateLobbyOptions, JoinLobbyOptions, NetVar, NetVarOptions, NetcodeClient, NetcodeEventHandler, NetcodeEventName, NetcodeEvents, NetcodeLobby, NetcodeMessage,
|
|
6
|
+
export type { CreateLobbyOptions, JoinLobbyOptions, NetVar, NetVarOptions, NetcodeClient, NetcodeEventHandler, NetcodeEventName, NetcodeEvents, NetcodeLobby, NetcodeMessage, MessageHandler, NetcodeObjectChange, NetcodeObjectState, NetcodeObjectStore, NetcodeObjectUpsert, NetcodeOptions, NetcodePeer, NetcodePeerStats, NetcodePhysicsState, NetcodeQuaternion, NetcodeReliability, NetcodeRuntime, NetcodeState, NetcodeTransform, NetcodeVector3, NetcodeVoice, NetcodeVoiceEvents, NetcodeVoiceOptions, NetcodeVoicePeer, NetcodeVoiceSignal, SendOptions, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createNetcode, shouldInitiate, } from './client.js';
|
|
2
2
|
export { runtimeFromRoom } from './roomRuntime.js';
|
|
3
|
-
export {
|
|
4
|
-
export { NETCODE_PROTOCOL,
|
|
3
|
+
export { ObjectStore } from './objects.js';
|
|
4
|
+
export { NETCODE_PROTOCOL, PROTOCOL_VERSION, decodeEnvelope, encodeEnvelope, isEnvelopeKind, } from './protocol.js';
|
package/dist/objects.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NetcodeObjectChange, NetcodeObjectStore, NetcodeObjectState, NetcodeObjectUpsert } from './types.js';
|
|
2
2
|
type ObjectListener = (change: NetcodeObjectChange) => void;
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class ObjectStore implements NetcodeObjectStore {
|
|
4
4
|
private readonly localPeerId;
|
|
5
5
|
private readonly publishUpsert;
|
|
6
6
|
private readonly publishRemove;
|
package/dist/objects.js
CHANGED
package/dist/protocol.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const NETCODE_PROTOCOL = "openrtc-netcode";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
3
3
|
export type NetcodeEnvelopeKind = 'hello' | 'peer' | 'user' | 'state.snapshot' | 'state.patch' | 'object.snapshot' | 'object.upsert' | 'object.remove' | 'lobby.meta' | 'member.meta' | 'voice.signal' | 'ping' | 'pong';
|
|
4
4
|
export interface NetcodeEnvelope<TBody = unknown> {
|
|
5
5
|
protocol: typeof NETCODE_PROTOCOL;
|
|
6
|
-
v: typeof
|
|
6
|
+
v: typeof PROTOCOL_VERSION;
|
|
7
7
|
kind: NetcodeEnvelopeKind;
|
|
8
8
|
lobbyId: string;
|
|
9
9
|
from: string;
|
package/dist/protocol.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const NETCODE_PROTOCOL = 'openrtc-netcode';
|
|
2
|
-
export const
|
|
2
|
+
export const PROTOCOL_VERSION = 1;
|
|
3
3
|
export function encodeEnvelope(envelope) {
|
|
4
4
|
return JSON.stringify(envelope);
|
|
5
5
|
}
|
|
@@ -8,7 +8,7 @@ export function decodeEnvelope(value) {
|
|
|
8
8
|
if (!isRecord(candidate)) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
-
if (candidate.protocol !== NETCODE_PROTOCOL || candidate.v !==
|
|
11
|
+
if (candidate.protocol !== NETCODE_PROTOCOL || candidate.v !== PROTOCOL_VERSION) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
14
|
if (!isEnvelopeKind(candidate.kind)) {
|
package/dist/roomRuntime.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Room } from 'openrtc';
|
|
2
2
|
import type { NetcodeRuntime } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Adapts one OpenRTC 2.0 capability handle to netcode's transport-only runtime
|
|
5
5
|
* contract. It never creates a second room, user scope, or base space.
|
|
6
6
|
*/
|
|
7
|
-
export declare function runtimeFromRoom(room:
|
|
7
|
+
export declare function runtimeFromRoom(room: Room): NetcodeRuntime;
|
package/dist/roomRuntime.js
CHANGED
|
@@ -23,7 +23,7 @@ function peerMember(peer) {
|
|
|
23
23
|
export function runtimeFromRoom(room) {
|
|
24
24
|
const connections = () => room.diagnostics.connections();
|
|
25
25
|
return {
|
|
26
|
-
|
|
26
|
+
lifecycle: true,
|
|
27
27
|
channels: room.channels,
|
|
28
28
|
initialize: async () => undefined,
|
|
29
29
|
start: async () => undefined,
|
|
@@ -81,8 +81,8 @@ export function runtimeFromRoom(room) {
|
|
|
81
81
|
scope: `v2:room:${room.id}`,
|
|
82
82
|
existingRouteOnly: true,
|
|
83
83
|
}),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|| connection.
|
|
84
|
+
onChannelStream: (channelId, callback) => room.channels.onIncomingChannel(channelId, callback),
|
|
85
|
+
readyConnections: () => connections().filter((connection) => typeof connection.isPayloadReady !== 'function'
|
|
86
|
+
|| connection.isPayloadReady()),
|
|
87
87
|
};
|
|
88
88
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ReadinessOptions as OpenRtcApplicationPayloadReadinessOptions, IncomingStream, ScopedChannelOptions, ScopedLogicalChannel } from 'openrtc/runtime';
|
|
2
|
+
import type { Room } from 'openrtc';
|
|
3
3
|
import type { MetadataBody, NetcodeEnvelope, ObjectRemoveBody, ObjectSnapshotBody, ObjectUpsertBody, StatePatchBody, StateSnapshotBody, UserMessageBody, VoiceSignalBody } from './protocol.js';
|
|
4
4
|
export interface NetcodeRuntime {
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ export interface NetcodeRuntime {
|
|
|
7
7
|
* Protocol layers must observe its connections instead of issuing a
|
|
8
8
|
* second ticket dial for the same avenue.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
lifecycle?: boolean;
|
|
11
11
|
initialize?(): Promise<void> | void;
|
|
12
12
|
start?(): Promise<void> | void;
|
|
13
13
|
stop?(): Promise<void> | void;
|
|
@@ -25,17 +25,17 @@ export interface NetcodeRuntime {
|
|
|
25
25
|
ticket: string;
|
|
26
26
|
timeoutMs?: number;
|
|
27
27
|
}): Promise<RuntimeConnectionLike>;
|
|
28
|
-
connectScopedChannel(options:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
channels?:
|
|
28
|
+
connectScopedChannel(options: ScopedChannelOptions): Promise<ScopedLogicalChannel>;
|
|
29
|
+
onChannelStream(channelId: string, callback: (stream: IncomingStream) => boolean | void): () => void;
|
|
30
|
+
readyConnections(options?: ReadinessOptions): RuntimeConnectionLike[];
|
|
31
|
+
channels?: Room['channels'];
|
|
32
32
|
}
|
|
33
33
|
export type NetcodeReliability = 'reliable';
|
|
34
34
|
export interface NetcodeOptions {
|
|
35
35
|
runtime?: NetcodeRuntime;
|
|
36
36
|
/** Preferred 2.0 path: one already-activated ephemeral match room. */
|
|
37
|
-
room?:
|
|
38
|
-
|
|
37
|
+
room?: Room;
|
|
38
|
+
preferredTransports?: ReadinessOptions['preferredTransports'];
|
|
39
39
|
displayName?: string;
|
|
40
40
|
maxPeers?: number;
|
|
41
41
|
localFallback?: boolean;
|
|
@@ -211,7 +211,7 @@ export interface NetcodeEvents {
|
|
|
211
211
|
}
|
|
212
212
|
export type NetcodeEventName = keyof NetcodeEvents;
|
|
213
213
|
export type NetcodeEventHandler<K extends NetcodeEventName> = (payload: NetcodeEvents[K]) => void;
|
|
214
|
-
export type
|
|
214
|
+
export type MessageHandler<T = unknown> = (message: NetcodeMessage<T>) => void;
|
|
215
215
|
export interface NetcodeMessage<T = unknown> {
|
|
216
216
|
type: string;
|
|
217
217
|
payload: T;
|
|
@@ -236,7 +236,7 @@ export interface NetcodeClient {
|
|
|
236
236
|
send(peerId: string, type: string, payload: unknown, options?: SendOptions): Promise<void>;
|
|
237
237
|
broadcast(type: string, payload: unknown, options?: SendOptions): Promise<void>;
|
|
238
238
|
on<K extends NetcodeEventName>(event: K, handler: NetcodeEventHandler<K>): () => void;
|
|
239
|
-
onMessage<T = unknown>(type: string, handler:
|
|
239
|
+
onMessage<T = unknown>(type: string, handler: MessageHandler<T>): () => void;
|
|
240
240
|
setLobbyData(key: string, value: string): Promise<void>;
|
|
241
241
|
setMemberData(key: string, value: string): Promise<void>;
|
|
242
242
|
}
|
|
@@ -250,7 +250,7 @@ export type RuntimeConnectionLike = {
|
|
|
250
250
|
parallelTransport?: string | null;
|
|
251
251
|
};
|
|
252
252
|
getAvailableTransports?(): string[];
|
|
253
|
-
|
|
253
|
+
isPayloadReady?(options?: ReadinessOptions): boolean;
|
|
254
254
|
onUpgradeStateChange?(callback: (state: 'none' | 'upgrading' | 'upgraded' | 'failed') => void): void;
|
|
255
255
|
requestWebRTCUpgrade?(reason?: string): void;
|
|
256
256
|
send(message: unknown): Promise<void> | void;
|
|
@@ -258,7 +258,7 @@ export type RuntimeConnectionLike = {
|
|
|
258
258
|
onDisconnect(callback: () => void): void | (() => void);
|
|
259
259
|
disconnect?(): Promise<void> | void;
|
|
260
260
|
};
|
|
261
|
-
export type
|
|
261
|
+
export type ReadinessOptions = OpenRtcApplicationPayloadReadinessOptions;
|
|
262
262
|
export type RuntimeMemberLike = {
|
|
263
263
|
nodeId?: string;
|
|
264
264
|
userId?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openrtc-netcode",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test:watch": "vitest"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"openrtc": "^2.0
|
|
45
|
+
"openrtc": "^2.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^24.10.1",
|