@@ -20,18 +20,37 @@ import {
2020 isFPCCReqWaitConnectorReady ,
2121 validateFPCCMessage ,
2222} from "./protocol-fp-cloud-conn.js" ;
23- import { Logger , OnFunc } from "@adviser/cement" ;
23+ import { Logger , OnFunc , Result } from "@adviser/cement" ;
2424import { ensureLogger } from "@fireproof/core-runtime" ;
2525import { SuperThis } from "@fireproof/core-types-base" ;
2626
27+ export interface JustReady {
28+ readonly type : "ready" ;
29+ }
30+
31+ export interface PeerReady {
32+ readonly type : "peer" ;
33+ readonly peer : string ;
34+ }
35+
36+ export function isJustReady ( obj : unknown ) : obj is JustReady {
37+ return typeof obj === "object" && obj !== null && ( obj as JustReady ) . type === "ready" ;
38+ }
39+
40+ export function isPeerReady ( obj : unknown ) : obj is PeerReady {
41+ return typeof obj === "object" && obj !== null && ( obj as PeerReady ) . type === "peer" && typeof ( obj as PeerReady ) . peer === "string" ;
42+ }
43+
44+ export type Ready = JustReady | PeerReady ;
45+
2746export interface FPCCProtocol {
2847 // handle must be this bound method
2948 hash : ( ) => string ;
3049
3150 sendMessage < T extends FPCCMsgBase > ( event : FPCCSendMessage < T > , srcEvent : MessageEvent < unknown > ) : void ;
3251 handleError : ( error : unknown ) => void ;
3352 injectSend ( send : ( evt : FPCCMessage , srcEvent : MessageEvent < unknown > | string ) => FPCCMessage ) : void ;
34- ready ( ) : Promise < FPCCProtocol > ;
53+ ready ( ) : Promise < Result < Ready > > ;
3554 stop ( ) : void ;
3655}
3756
@@ -143,9 +162,10 @@ export class FPCCProtocolBase implements FPCCProtocol {
143162 throw new Error ( "Method not implemented." ) ;
144163 } ;
145164
146- ready ( ) : Promise < FPCCProtocol > {
147-
148- return Promise . resolve ( this ) ;
165+ ready ( ) : Promise < Result < Ready > > {
166+ return Promise . resolve ( Result . Ok ( {
167+ type : "ready" as const ,
168+ } ) )
149169 }
150170
151171 injectSend ( sendFn : ( msg : FPCCMessage , srcEvent : MessageEvent < unknown > | string ) => FPCCMessage ) : void {
0 commit comments