1- import { PeerGroupAgentConfig , PeerInfo , PeerSource } from 'mesh/agents/peer' ;
1+ import { ObjectDiscoveryPeerSource , PeerGroupAgentConfig , PeerInfo , PeerSource } from 'mesh/agents/peer' ;
22import { Mesh , PeerGroupInfo , SyncMode , UsageToken } from 'mesh/service/Mesh' ;
33import { MeshCommand ,
44 JoinPeerGroup , LeavePeerGroup ,
@@ -14,7 +14,7 @@ import { MeshCommand,
1414 ForwardPeerGroupState } from './MeshHost' ;
1515
1616import { RNGImpl } from 'crypto/random' ;
17- import { Context , Hash , HashedObject } from 'data/model' ;
17+ import { Context , Hash , HashedObject , MutableObject } from 'data/model' ;
1818import { AsyncStream , BufferedAsyncStream , BufferingAsyncStreamSource } from 'util/streams' ;
1919import { ObjectDiscoveryReply } from 'mesh/agents/discovery' ;
2020import { Endpoint } from 'mesh/agents/network' ;
@@ -23,12 +23,15 @@ import { WebRTCConnectionEvent, WebRTCConnectionsHost } from 'net/transport';
2323import { Identity } from 'data/identity' ;
2424import { ObjectSpawnAgent , SpawnCallback } from 'mesh/agents/spawn' ;
2525import { PeerGroupState } from 'mesh/agents/peer/PeerGroupState' ;
26+ import { Resources } from 'spaces/Resources' ;
27+ import { MeshInterface } from './MeshInterface' ;
28+ import { SyncState , SyncObserver } from 'mesh/agents/state' ;
2629
2730/* Access a mesh remotely, see the MeshHost class. */
2831
2932type RequestId = string ;
3033
31- class MeshProxy {
34+ class MeshProxy implements MeshInterface {
3235
3336 commandForwardingFn : ( cmd : MeshCommand ) => void ;
3437 discoveryStreamSources : Map < string , BufferingAsyncStreamSource < ObjectDiscoveryReply > > ;
@@ -497,6 +500,38 @@ class MeshProxy {
497500
498501 }
499502
503+ // We do not need to bridge this request to the MeshHost: the ObjectDiscoveryPeerSource receives a reference
504+ // to this mesh, that's already bridged.
505+ async getDiscoveryPeerGroup ( obj : HashedObject , resources ?: Resources ) : Promise < PeerGroupInfo > {
506+
507+ resources = resources || obj . getResources ( ) ;
508+
509+ if ( resources === undefined ) {
510+ throw new Error ( 'Could not find a valid resources object to use for the discovery peer group.' ) ;
511+ }
512+
513+ let localPeer = resources . getPeersForDiscovery ( ) [ 0 ] ;
514+ let peerSource = new ObjectDiscoveryPeerSource ( this as any as Mesh , obj , resources . config . linkupServers , LinkupAddress . fromURL ( localPeer . endpoint , localPeer . identity ) , resources . getEndointParserForDiscovery ( ) ) ;
515+
516+ return {
517+ id : Mesh . discoveryPeerGroupId ( obj ) ,
518+ localPeer : localPeer ,
519+ peerSource : peerSource
520+ } ;
521+
522+ }
523+
524+ getSyncState ( _mut : MutableObject , _peerGroupId ?: string | undefined ) : Promise < SyncState | undefined > {
525+ throw new Error ( 'Method not implemented.' ) ;
526+ }
527+
528+ addSyncObserver ( _obs : SyncObserver , _mut : MutableObject , _peerGroupId ?: string | undefined ) : void {
529+ throw new Error ( 'Method not implemented.' ) ;
530+ }
531+
532+ removeSyncObserver ( _obs : SyncObserver , _mut : MutableObject , _peerGroupId ?: string | undefined ) : void {
533+ throw new Error ( 'Method not implemented.' ) ;
534+ }
500535
501536}
502537
0 commit comments