@@ -172,11 +172,7 @@ class PubsubBaseProtocol extends EventEmitter {
172
172
_onIncomingStream ( { protocol, stream, connection } ) {
173
173
const peerId = connection . remotePeer
174
174
const idB58Str = peerId . toB58String ( )
175
-
176
- const peer = this . _addPeer ( new Peer ( {
177
- id : peerId ,
178
- protocols : [ protocol ]
179
- } ) )
175
+ const peer = this . _addPeer ( peerId , [ protocol ] )
180
176
181
177
this . _processMessages ( idB58Str , stream , peer )
182
178
}
@@ -191,10 +187,7 @@ class PubsubBaseProtocol extends EventEmitter {
191
187
const idB58Str = peerId . toB58String ( )
192
188
this . log ( 'connected' , idB58Str )
193
189
194
- const peer = this . _addPeer ( new Peer ( {
195
- id : peerId ,
196
- protocols : this . multicodecs
197
- } ) )
190
+ const peer = this . _addPeer ( peerId , this . multicodecs )
198
191
199
192
if ( peer . isConnected ) {
200
193
return
@@ -225,15 +218,22 @@ class PubsubBaseProtocol extends EventEmitter {
225
218
/**
226
219
* Add a new connected peer to the peers map.
227
220
* @private
228
- * @param {Peer } peer internal peer
221
+ * @param {PeerId } peerId
222
+ * @param {Array<string> } protocols
229
223
* @returns {Peer }
230
224
*/
231
- _addPeer ( peer ) {
232
- const id = peer . id . toB58String ( )
225
+ _addPeer ( peerId , protocols ) {
226
+ const id = peerId . toB58String ( )
233
227
let existing = this . peers . get ( id )
234
228
235
229
if ( ! existing ) {
236
230
this . log ( 'new peer' , id )
231
+
232
+ const peer = new Peer ( {
233
+ id : peerId ,
234
+ protocols
235
+ } )
236
+
237
237
this . peers . set ( id , peer )
238
238
existing = peer
239
239
0 commit comments