@@ -10,6 +10,8 @@ import type {
1010} from './shared.js' ;
1111import { deserialize , serialize } from './serializer.js' ;
1212import { DeviceNotRespondingError } from './errors.js' ;
13+ import { createPlatformBridgeFunctions } from './platform-bridge.js' ;
14+ import type { HarnessPlatformRunner } from '@react-native-harness/platforms' ;
1315
1416export type BridgeServerOptions = {
1517 port : number ;
@@ -36,6 +38,7 @@ export type BridgeServer = {
3638 event : T ,
3739 listener : BridgeServerEvents [ T ]
3840 ) => void ;
41+ updatePlatformFunctions : ( platformRunner : HarnessPlatformRunner ) => void ;
3942 dispose : ( ) => void ;
4043} ;
4144
@@ -51,15 +54,35 @@ export const getBridgeServer = async ({
5154 const emitter = new EventEmitter ( ) ;
5255 const clients = new Set < WebSocket > ( ) ;
5356
57+ const baseFunctions : BridgeServerFunctions = {
58+ reportReady : ( device ) => {
59+ emitter . emit ( 'ready' , device ) ;
60+ } ,
61+ emitEvent : ( _ , data ) => {
62+ emitter . emit ( 'event' , data ) ;
63+ } ,
64+ 'platform.actions.tap' : async ( ) => {
65+ throw new Error ( 'Platform functions not initialized' ) ;
66+ } ,
67+ 'platform.actions.inputText' : async ( ) => {
68+ throw new Error ( 'Platform functions not initialized' ) ;
69+ } ,
70+ 'platform.actions.tapElement' : async ( ) => {
71+ throw new Error ( 'Platform functions not initialized' ) ;
72+ } ,
73+ 'platform.queries.getUiHierarchy' : async ( ) => {
74+ throw new Error ( 'Platform functions not initialized' ) ;
75+ } ,
76+ 'platform.queries.findByTestId' : async ( ) => {
77+ throw new Error ( 'Platform functions not initialized' ) ;
78+ } ,
79+ 'platform.queries.findAllByTestId' : async ( ) => {
80+ throw new Error ( 'Platform functions not initialized' ) ;
81+ } ,
82+ } ;
83+
5484 const group = createBirpcGroup < BridgeClientFunctions , BridgeServerFunctions > (
55- {
56- reportReady : ( device ) => {
57- emitter . emit ( 'ready' , device ) ;
58- } ,
59- emitEvent : ( _ , data ) => {
60- emitter . emit ( 'event' , data ) ;
61- } ,
62- } satisfies BridgeServerFunctions ,
85+ baseFunctions ,
6386 [ ] ,
6487 {
6588 timeout,
@@ -69,6 +92,13 @@ export const getBridgeServer = async ({
6992 }
7093 ) ;
7194
95+ const updatePlatformFunctions = (
96+ platformRunner : HarnessPlatformRunner
97+ ) : void => {
98+ const platformFunctions = createPlatformBridgeFunctions ( platformRunner ) ;
99+ Object . assign ( baseFunctions , platformFunctions ) ;
100+ } ;
101+
72102 wss . on ( 'connection' , ( ws : WebSocket ) => {
73103 logger . debug ( 'Client connected to the bridge' ) ;
74104 ws . on ( 'close' , ( ) => {
@@ -104,6 +134,7 @@ export const getBridgeServer = async ({
104134 on : emitter . on . bind ( emitter ) ,
105135 once : emitter . once . bind ( emitter ) ,
106136 off : emitter . off . bind ( emitter ) ,
137+ updatePlatformFunctions,
107138 dispose,
108139 } ;
109140} ;
0 commit comments