@@ -164,15 +164,15 @@ class RPCClient extends EventEmitter {
164
164
165
165
/**
166
166
* Send a message to the RPCServer. While socket is connecting, the message is queued and send when open.
167
- * @param {Buffer|String } buffer - String to send via websocket
167
+ * @param {Buffer|String } message - String to send via websocket
168
168
*/
169
- sendRaw ( buffer ) {
169
+ sendRaw ( message ) {
170
170
if ( [ OPEN , CLOSING ] . includes ( this . _state ) && this . _ws ) {
171
171
// can send while closing so long as websocket doesn't mind
172
- this . _ws . send ( buffer ) ;
173
- this . emit ( 'message' , { buffer , outbound : true } ) ;
172
+ this . _ws . send ( message ) ;
173
+ this . emit ( 'message' , { message , outbound : true } ) ;
174
174
} else if ( this . _state === CONNECTING ) {
175
- this . _outboundMsgBuffer . push ( buffer ) ;
175
+ this . _outboundMsgBuffer . push ( message ) ;
176
176
} else {
177
177
throw Error ( `Cannot send message in this state` ) ;
178
178
}
@@ -561,17 +561,16 @@ class RPCClient extends EventEmitter {
561
561
}
562
562
563
563
_onMessage ( buffer ) {
564
- this . emit ( 'message' , { buffer, outbound : false } ) ;
564
+ const message = buffer . toString ( 'utf8' ) ;
565
+ this . emit ( 'message' , { message, outbound : false } ) ;
565
566
566
567
let msgId = '-1' ;
567
568
let messageType ;
568
569
569
570
try {
570
- const msg = buffer . toString ( 'utf8' ) ;
571
-
572
571
let payload ;
573
572
try {
574
- payload = JSON . parse ( msg ) ;
573
+ payload = JSON . parse ( message ) ;
575
574
} catch ( err ) {
576
575
throw createRPCError ( "RpcFrameworkError" , "Message must be a JSON structure" , { } ) ;
577
576
}
0 commit comments