File tree Expand file tree Collapse file tree 5 files changed +29
-1
lines changed Expand file tree Collapse file tree 5 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ export class SSEClientTransport implements Transport {
22
22
}
23
23
24
24
start ( ) : Promise < void > {
25
+ if ( this . _eventSource ) {
26
+ throw new Error (
27
+ "SSEClientTransport already started! If using Client class, note that connect() calls start() automatically." ,
28
+ ) ;
29
+ }
30
+
25
31
return new Promise ( ( resolve , reject ) => {
26
32
this . _eventSource = new EventSource ( this . _url . href ) ;
27
33
this . _abortController = new AbortController ( ) ;
Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ export class StdioClientTransport implements Transport {
45
45
* Starts the server process and prepares to communicate with it.
46
46
*/
47
47
async start ( ) : Promise < void > {
48
+ if ( this . _process ) {
49
+ throw new Error (
50
+ "StdioClientTransport already started! If using Client class, note that connect() calls start() automatically." ,
51
+ ) ;
52
+ }
53
+
48
54
return new Promise ( ( resolve , reject ) => {
49
55
this . _process = spawn (
50
56
this . _serverParams . command ,
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ export class WebSocketClientTransport implements Transport {
19
19
}
20
20
21
21
start ( ) : Promise < void > {
22
+ if ( this . _socket ) {
23
+ throw new Error (
24
+ "WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically." ,
25
+ ) ;
26
+ }
27
+
22
28
return new Promise ( ( resolve , reject ) => {
23
29
this . _socket = new WebSocket ( this . _url , SUBPROTOCOL ) ;
24
30
Original file line number Diff line number Diff line change @@ -37,7 +37,9 @@ export class SSEServerTransport implements Transport {
37
37
*/
38
38
async start ( ) : Promise < void > {
39
39
if ( this . _sseResponse ) {
40
- throw new Error ( "Already connected!" ) ;
40
+ throw new Error (
41
+ "SSEServerTransport already started! If using Server class, note that connect() calls start() automatically." ,
42
+ ) ;
41
43
}
42
44
43
45
this . res . writeHead ( 200 , {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { Transport } from "../shared/transport.js";
11
11
*/
12
12
export class StdioServerTransport implements Transport {
13
13
private _readBuffer : ReadBuffer = new ReadBuffer ( ) ;
14
+ private _started = false ;
14
15
15
16
constructor (
16
17
private _stdin : Readable = process . stdin ,
@@ -34,6 +35,13 @@ export class StdioServerTransport implements Transport {
34
35
* Starts listening for messages on stdin.
35
36
*/
36
37
async start ( ) : Promise < void > {
38
+ if ( this . _started ) {
39
+ throw new Error (
40
+ "StdioServerTransport already started! If using Server class, note that connect() calls start() automatically." ,
41
+ ) ;
42
+ }
43
+
44
+ this . _started = true ;
37
45
this . _stdin . on ( "data" , this . _ondata ) ;
38
46
this . _stdin . on ( "error" , this . _onerror ) ;
39
47
}
You can’t perform that action at this time.
0 commit comments