33 type RoomConnectOptions ,
44 RoomEvent ,
55 RpcError ,
6- RpcInvocationData ,
6+ type RpcInvocationData ,
77} from '../../src/index' ;
88
99let startTime : number ;
@@ -75,7 +75,7 @@ async function main() {
7575}
7676
7777const registerReceiverMethods = async ( greetersRoom : Room , mathGeniusRoom : Room ) : Promise < void > => {
78- await greetersRoom . localParticipant ?. registerRpcMethod (
78+ await greetersRoom . registerRpcMethod (
7979 'arrival' ,
8080 // eslint-disable-next-line @typescript-eslint/no-unused-vars
8181 async ( data : RpcInvocationData ) => {
@@ -85,52 +85,46 @@ const registerReceiverMethods = async (greetersRoom: Room, mathGeniusRoom: Room)
8585 } ,
8686 ) ;
8787
88- await mathGeniusRoom . localParticipant ?. registerRpcMethod (
89- 'square-root' ,
90- async ( data : RpcInvocationData ) => {
91- const jsonData = JSON . parse ( data . payload ) ;
92- const number = jsonData . number ;
88+ await mathGeniusRoom . registerRpcMethod ( 'square-root' , async ( data : RpcInvocationData ) => {
89+ const jsonData = JSON . parse ( data . payload ) ;
90+ const number = jsonData . number ;
9391
94- console . log (
95- `[Math Genius] I guess ${ data . callerIdentity } wants the square root of ${ number } . I've only got ${ data . responseTimeout / 1000 } seconds to respond but I think I can pull it off.` ,
96- ) ;
92+ console . log (
93+ `[Math Genius] I guess ${ data . callerIdentity } wants the square root of ${ number } . I've only got ${ data . responseTimeout / 1000 } seconds to respond but I think I can pull it off.` ,
94+ ) ;
9795
98- console . log ( `[Math Genius] *doing math*…` ) ;
99- await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
96+ console . log ( `[Math Genius] *doing math*…` ) ;
97+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
10098
101- const result = Math . sqrt ( number ) ;
102- console . log ( `[Math Genius] Aha! It's ${ result } ` ) ;
103- return JSON . stringify ( { result } ) ;
104- } ,
105- ) ;
99+ const result = Math . sqrt ( number ) ;
100+ console . log ( `[Math Genius] Aha! It's ${ result } ` ) ;
101+ return JSON . stringify ( { result } ) ;
102+ } ) ;
106103
107- await mathGeniusRoom . localParticipant ?. registerRpcMethod (
108- 'divide' ,
109- async ( data : RpcInvocationData ) => {
110- const jsonData = JSON . parse ( data . payload ) ;
111- const { numerator, denominator } = jsonData ;
104+ await mathGeniusRoom . registerRpcMethod ( 'divide' , async ( data : RpcInvocationData ) => {
105+ const jsonData = JSON . parse ( data . payload ) ;
106+ const { numerator, denominator } = jsonData ;
112107
113- console . log (
114- `[Math Genius] ${ data . callerIdentity } wants to divide ${ numerator } by ${ denominator } . Let me think...` ,
115- ) ;
108+ console . log (
109+ `[Math Genius] ${ data . callerIdentity } wants to divide ${ numerator } by ${ denominator } . Let me think...` ,
110+ ) ;
116111
117- await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
112+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
118113
119- if ( denominator === 0 ) {
120- throw new Error ( 'Cannot divide by zero' ) ;
121- }
114+ if ( denominator === 0 ) {
115+ throw new Error ( 'Cannot divide by zero' ) ;
116+ }
122117
123- const result = numerator / denominator ;
124- console . log ( `[Math Genius] ${ numerator } / ${ denominator } = ${ result } ` ) ;
125- return JSON . stringify ( { result } ) ;
126- } ,
127- ) ;
118+ const result = numerator / denominator ;
119+ console . log ( `[Math Genius] ${ numerator } / ${ denominator } = ${ result } ` ) ;
120+ return JSON . stringify ( { result } ) ;
121+ } ) ;
128122} ;
129123
130124const performGreeting = async ( room : Room ) : Promise < void > => {
131125 console . log ( "[Caller] Letting the greeter know that I've arrived" ) ;
132126 try {
133- const response = await room . localParticipant ! . performRpc ( {
127+ const response = await room . localParticipant . performRpc ( {
134128 destinationIdentity : 'greeter' ,
135129 method : 'arrival' ,
136130 payload : 'Hello' ,
@@ -145,7 +139,7 @@ const performGreeting = async (room: Room): Promise<void> => {
145139const performDisconnection = async ( room : Room ) : Promise < void > => {
146140 console . log ( '[Caller] Checking back in on the greeter...' ) ;
147141 try {
148- const response = await room . localParticipant ! . performRpc ( {
142+ const response = await room . localParticipant . performRpc ( {
149143 destinationIdentity : 'greeter' ,
150144 method : 'arrival' ,
151145 payload : 'You still there?' ,
@@ -164,7 +158,7 @@ const performDisconnection = async (room: Room): Promise<void> => {
164158const performSquareRoot = async ( room : Room ) : Promise < void > => {
165159 console . log ( "[Caller] What's the square root of 16?" ) ;
166160 try {
167- const response = await room . localParticipant ! . performRpc ( {
161+ const response = await room . localParticipant . performRpc ( {
168162 destinationIdentity : 'math-genius' ,
169163 method : 'square-root' ,
170164 payload : JSON . stringify ( { number : 16 } ) ,
@@ -180,7 +174,7 @@ const performSquareRoot = async (room: Room): Promise<void> => {
180174const performQuantumHypergeometricSeries = async ( room : Room ) : Promise < void > => {
181175 console . log ( "[Caller] What's the quantum hypergeometric series of 42?" ) ;
182176 try {
183- const response = await room . localParticipant ! . performRpc ( {
177+ const response = await room . localParticipant . performRpc ( {
184178 destinationIdentity : 'math-genius' ,
185179 method : 'quantum-hypergeometric-series' ,
186180 payload : JSON . stringify ( { number : 42 } ) ,
@@ -203,7 +197,7 @@ const performQuantumHypergeometricSeries = async (room: Room): Promise<void> =>
203197const performDivision = async ( room : Room ) : Promise < void > => {
204198 console . log ( "[Caller] Let's try dividing 10 by 0" ) ;
205199 try {
206- const response = await room . localParticipant ! . performRpc ( {
200+ const response = await room . localParticipant . performRpc ( {
207201 destinationIdentity : 'math-genius' ,
208202 method : 'divide' ,
209203 payload : JSON . stringify ( { numerator : 10 , denominator : 0 } ) ,
0 commit comments