@@ -567,8 +567,8 @@ export class Chain {
567567 /**
568568 * Set and connect to the peer to be used as the event source.
569569 */
570- eventHubConnect ( peeraddr : string ) :void {
571- this . eventHub . setPeerAddr ( peeraddr ) ;
570+ eventHubConnect ( peerUrl : string , opts ?: GRPCOptions ) :void {
571+ this . eventHub . setPeerAddr ( peerUrl , opts ) ;
572572 this . eventHub . connect ( ) ;
573573 } ;
574574
@@ -2861,7 +2861,9 @@ export class ChainCodeCBE {
28612861 */
28622862export class EventHub {
28632863 // peer addr to connect to
2864- private peeraddr : string ;
2864+ private ep : Endpoint ;
2865+ // grpc options
2866+ private opts : GRPCOptions ;
28652867 // grpc events interface
28662868 private events : any ;
28672869 // grpc event client interface
@@ -2880,12 +2882,14 @@ export class EventHub {
28802882 this . chaincodeRegistrants = new HashTable ( ) ;
28812883 this . blockRegistrants = new Set ( ) ;
28822884 this . txRegistrants = new HashTable ( ) ;
2883- this . peeraddr = null ;
2885+ this . ep = null ;
28842886 this . connected = false ;
28852887 }
28862888
2887- public setPeerAddr ( peeraddr : string ) {
2888- this . peeraddr = peeraddr ;
2889+ public setPeerAddr ( peeraddr : string , opts ?:GRPCOptions ) {
2890+ let pem = getPemFromOpts ( opts ) ;
2891+ this . opts = getOptsFromOpts ( opts ) ;
2892+ this . ep = new Endpoint ( peeraddr , pem ) ;
28892893 }
28902894
28912895 public isconnected ( ) {
@@ -2894,9 +2898,9 @@ export class EventHub {
28942898
28952899 public connect ( ) {
28962900 if ( this . connected ) return ;
2897- if ( ! this . peeraddr ) throw Error ( "Must set peer address before connecting." ) ;
2901+ if ( ! this . ep ) throw Error ( "Must set peer address before connecting." ) ;
28982902 this . events = grpc . load ( __dirname + "/protos/events.proto" ) . protos ;
2899- this . client = new this . events . Events ( this . peeraddr , grpc . credentials . createInsecure ( ) ) ;
2903+ this . client = new this . events . Events ( this . ep . addr , this . ep . creds , this . opts ) ;
29002904 this . call = this . client . chat ( ) ;
29012905 this . connected = true ;
29022906 this . registerBlockEvent ( this . txCallback ) ;
0 commit comments