File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
deltachat-rpc-server/npm-package Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,13 @@ export interface StartOptions {
3535 */
3636export function startDeltaChat ( directory : string , options ?: Partial < SearchOptions & StartOptions > ) : DeltaChatOverJsonRpcServer
3737
38+ export class DeltaChatOverJsonRpc extends StdioDeltaChat {
39+ constructor (
40+ directory : string ,
41+ options ?: Partial < SearchOptions & StartOptions >
42+ ) ;
43+ readonly pathToServerBinary : string ;
44+ }
3845
3946export namespace FnTypes {
4047 export type getRPCServerPath = typeof getRPCServerPath
Original file line number Diff line number Diff line change @@ -106,3 +106,46 @@ export function startDeltaChat(directory, options = {}) {
106106
107107 return dc ;
108108}
109+
110+ export class DeltaChatOverJsonRpc extends StdioDeltaChat {
111+ /**
112+ *
113+ * @param {string } directory
114+ * @param {Partial<import("./index").SearchOptions & import("./index").StartOptions> } options
115+ */
116+ constructor ( directory , options = { } ) {
117+ const pathToServerBinary = getRPCServerPath ( options ) ;
118+ const server = spawn ( pathToServerBinary , {
119+ env : {
120+ RUST_LOG : process . env . RUST_LOG ,
121+ DC_ACCOUNTS_PATH : directory ,
122+ } ,
123+ stdio : [ "pipe" , "pipe" , options . muteStdErr ? "ignore" : "inherit" ] ,
124+ } ) ;
125+
126+ server . on ( "error" , ( err ) => {
127+ throw new Error (
128+ FAILED_TO_START_SERVER_EXECUTABLE ( pathToServerBinary , err )
129+ ) ;
130+ } ) ;
131+ let shouldClose = false ;
132+
133+ server . on ( "exit" , ( ) => {
134+ if ( shouldClose ) {
135+ return ;
136+ }
137+ throw new Error ( "Server quit" ) ;
138+ } ) ;
139+
140+ super ( server . stdin , server . stdout , true ) ;
141+
142+ this . close = ( ) => {
143+ shouldClose = true ;
144+ if ( ! server . kill ( ) ) {
145+ console . log ( "server termination failed" ) ;
146+ }
147+ } ;
148+
149+ this . pathToServerBinary = pathToServerBinary ;
150+ }
151+ }
You can’t perform that action at this time.
0 commit comments