UNPKG

673 BJavaScriptView Raw
1"use strict";
2
3// Copyright 2017-2018 Jaco Greeff
4// This software may be modified and distributed under the terms
5// of the ISC license. See the LICENSE file for details.
6const isUndefined = require('@polkadot/util/is/undefined');
7
8const onMessageResult = require('./onMessageResult');
9
10const onMessageSubscribe = require('./onMessageSubscribe');
11
12module.exports = function onMessage(self) {
13 return message => {
14 self.l.debug(() => ['received', message.data]); // flowlint-next-line unclear-type:off
15
16 const response = JSON.parse(message.data);
17 return isUndefined(response.method) ? onMessageResult(self, response) : onMessageSubscribe(self, response);
18 };
19};
\No newline at end of file