Skip to content

Commit e71a2e4

Browse files
committed
refactor: use named constants for rpc versions
1 parent 0a219fe commit e71a2e4

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/room/rpc/client/RpcClientManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
RPC_REQUEST_METHOD_ATTR,
1616
RPC_REQUEST_RESPONSE_TIMEOUT_MS_ATTR,
1717
RPC_REQUEST_VERSION_ATTR,
18+
RPC_VERSION_V1,
19+
RPC_VERSION_V2,
1820
RpcError,
1921
byteLength,
2022
} from '../utils';
@@ -147,7 +149,7 @@ export default class RpcClientManager extends (EventEmitter as new () => TypedEm
147149
[RPC_REQUEST_ID_ATTR]: requestId,
148150
[RPC_REQUEST_METHOD_ATTR]: method,
149151
[RPC_REQUEST_RESPONSE_TIMEOUT_MS_ATTR]: `${responseTimeout}`,
150-
[RPC_REQUEST_VERSION_ATTR]: '2', // Latest rpc request version
152+
[RPC_REQUEST_VERSION_ATTR]: `${RPC_VERSION_V2}`,
151153
},
152154
});
153155

@@ -168,7 +170,7 @@ export default class RpcClientManager extends (EventEmitter as new () => TypedEm
168170
method,
169171
payload,
170172
responseTimeoutMs: responseTimeout,
171-
version: 1,
173+
version: RPC_VERSION_V1,
172174
}),
173175
},
174176
}),

src/room/rpc/server/RpcServerManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
RPC_REQUEST_RESPONSE_TIMEOUT_MS_ATTR,
1414
RPC_REQUEST_VERSION_ATTR,
1515
RPC_RESPONSE_DATA_STREAM_TOPIC,
16+
RPC_VERSION_V2,
1617
RpcError,
1718
type RpcInvocationData,
1819
byteLength,
@@ -144,7 +145,7 @@ export default class RpcServerManager extends (EventEmitter as new () => TypedEm
144145

145146
this.publishRpcAck(callerIdentity, requestId);
146147

147-
if (version !== 2) {
148+
if (version !== RPC_VERSION_V2) {
148149
this.publishRpcResponsePacket(
149150
callerIdentity,
150151
requestId,

src/room/rpc/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ export const RPC_REQUEST_RESPONSE_TIMEOUT_MS_ATTR = 'lk.rpc_request_response_tim
168168
/** @internal */
169169
export const RPC_REQUEST_VERSION_ATTR = 'lk.rpc_request_version';
170170

171+
/** Initial version of rpc which uses RpcRequest / RpcResponse messages.
172+
* @internal
173+
**/
174+
export const RPC_VERSION_V1 = 1;
175+
176+
/** Rpc version backed by data streams instead of RpcRequest / RpcResponse.
177+
* @internal
178+
**/
179+
export const RPC_VERSION_V2 = 2;
180+
171181
/**
172182
* @internal
173183
*/

0 commit comments

Comments
 (0)