Merge pull request #114 from stanley-cheung/master

Expose stream end event to client
This commit is contained in:
Stanley Cheung 2017-12-04 21:39:37 -08:00 committed by GitHub
commit 19e37d1794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -67,6 +67,13 @@ grpc.web.ClientReadableStream = function(
*/
this.onStatusCallback_ = null;
/**
* @private
* @type {function(...):?|null}
* The stream end callback
*/
this.onEndCallback_ = null;
/**
* @private
* @type {function(?):!grpc.web.Status}
@ -87,6 +94,11 @@ grpc.web.ClientReadableStream = function(
self.onStatusCallback_(status);
}
});
this.xhrNodeReadableStream_.on('end', function() {
if (self.onEndCallback_) {
self.onEndCallback_();
}
});
};
@ -105,6 +117,8 @@ grpc.web.ClientReadableStream.prototype.on = function(
this.onDataCallback_ = callback;
} else if (eventType == 'status') {
this.onStatusCallback_ = callback;
} else if (eventType == 'end') {
this.onEndCallback_ = callback;
}
return this;
};