Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hyperledger fabric 如何在用户应用程序中获取通知?_Hyperledger Fabric_Hyperledger_Blockchain_Hyperledger Composer_Ibm Blockchain - Fatal编程技术网

Hyperledger fabric 如何在用户应用程序中获取通知?

Hyperledger fabric 如何在用户应用程序中获取通知?,hyperledger-fabric,hyperledger,blockchain,hyperledger-composer,ibm-blockchain,Hyperledger Fabric,Hyperledger,Blockchain,Hyperledger Composer,Ibm Blockchain,在区块链中,我发出了一个与特定交易关联的事件。我也在我的事务API中订阅了该事件。但是在API中订阅事件之后我该怎么办?我不知道如何使用区块链端发出的订阅事件在我的前端或用户应用程序中生成通知。请提供帮助。您可以使用WebSocket在JS中使用WebSocket获取URL上发生的事件 class Events { constructor() { // Listen for events this.socket = new WebSocket(Ev

在区块链中,我发出了一个与特定交易关联的事件。我也在我的事务API中订阅了该事件。但是在API中订阅事件之后我该怎么办?我不知道如何使用区块链端发出的订阅事件在我的前端或用户应用程序中生成通知。请提供帮助。

您可以使用WebSocket在JS中使用WebSocket获取URL上发生的事件

class Events {

      constructor() {

        // Listen for events
        this.socket = new WebSocket(Events.URL_TRANSACTION);
        this.socket.addEventListener('open', evt => this.doSocketOpen(evt));
        this.socket.addEventListener('close', evt => this.doSocketClose(evt));
        this.socket.addEventListener('message', evt => this.doSocketMessage(evt));

        // Load initial data
        this.xhr = new XMLHttpRequest();
        this.xhr.addEventListener('load', evt => this.doInitialLoad1(evt));
        this.xhr.open('GET', Events.URL_ASSET1, true);
        this.xhr.send(null);

      }

      // Initial data loaded
      doInitialLoad1(evt) {

        var data = JSON.parse(this.xhr.responseText);
        console.log(data);

      }


      // FYI
      doSocketClose(evt) {
        console.log('Close.');
      }

      // Transaction has taken place
      doSocketMessage(evt) {

        let data = JSON.parse(evt.data); // getting event data here
        console.log(data);

      }

      // FYI
      doSocketOpen(evt) {
        console.log('Open.');
      }
    }

    Events.newData = '';
    Events.URL_ASSET1 = 'http://localhost:3000/api/org.demo.SampleAsset';
    Events.URL_TRANSACTION = 'ws://localhost:3000';
    let app = new Events();

上述代码将连续监视给定的URL&如果发生任何事件,则将调用函数doSocketMessage。

此示例应用程序中显示了消费事件的示例?代码->视频链接位于:->