@@ -23,7 +23,7 @@ export function registerLocalMethods(
2323 schema : ISchema = { } ,
2424 methods : any [ ] = [ ] ,
2525 _connectionID : string ,
26- guest ?: Worker ,
26+ guest ?: Worker
2727) : any {
2828 const listeners : any [ ] = [ ] ;
2929 methods . forEach ( ( methodName ) => {
@@ -49,7 +49,14 @@ export function registerLocalMethods(
4949 // run function and return the results to the remote
5050 try {
5151 const result = await get ( schema , methodName ) ( ...args ) ;
52- payload . result = JSON . parse ( JSON . stringify ( result || { } ) ) ;
52+
53+ if ( ! result ) {
54+ // if the result is falsy (null, undefined, "", etc), set it directly
55+ payload . result = result ;
56+ } else {
57+ // otherwise parse a stringified version of it
58+ payload . result = JSON . parse ( JSON . stringify ( result ) ) ;
59+ }
5360 } catch ( error ) {
5461 payload . action = actions . RPC_REJECT ;
5562 payload . error = JSON . parse ( JSON . stringify ( error , Object . getOwnPropertyNames ( error ) ) ) ;
@@ -90,7 +97,7 @@ export function createRPC(
9097 _connectionID : string ,
9198 event : any ,
9299 listeners : Array < ( ) => void > = [ ] ,
93- guest ?: Worker ,
100+ guest ?: Worker
94101) {
95102 return ( ...args : any ) => {
96103 return new Promise ( ( resolve , reject ) => {
@@ -149,7 +156,7 @@ export function registerRemoteMethods(
149156 methods : any [ ] = [ ] ,
150157 _connectionID : string ,
151158 event : any ,
152- guest ?: Worker ,
159+ guest ?: Worker
153160) {
154161 const remote = { ...schema } ;
155162 const listeners : Array < ( ) => void > = [ ] ;
0 commit comments