• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-js / 10793905985

10 Sep 2024 01:51PM UTC coverage: 84.407% (+0.004%) from 84.403%
10793905985

push

github

web-flow
bump: [#4684] Update multiple dependencies inside public libraries to latest version (#4739)

* Update dependencies in libraries' projects

* Fix some issues in testing projects

* Update root package.json typescript and @types/node versions

* Fix @types/express problem in yarn.lock

* Fix pipelines

10011 of 13158 branches covered (76.08%)

Branch coverage included in aggregate %.

23 of 31 new or added lines in 13 files covered. (74.19%)

5 existing lines in 4 files now uncovered.

20433 of 22910 relevant lines covered (89.19%)

7159.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.09
/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts
1
/**
2
 * @module botframework-streaming
3
 */
4
/**
5
 * Copyright (c) Microsoft Corporation. All rights reserved.
6
 * Licensed under the MIT License.
7
 */
8
import { connect } from 'net';
2✔
9
import { ProtocolAdapter } from '../protocolAdapter';
2✔
10
import { RequestHandler } from '../requestHandler';
11
import { StreamingRequest } from '../streamingRequest';
12
import { RequestManager } from '../payloads';
2✔
13
import { PayloadReceiver, PayloadSender } from '../payloadTransport';
2✔
14
import { NamedPipeTransport } from './namedPipeTransport';
2✔
15
import { IStreamingTransportClient, IReceiveResponse } from '../interfaces';
16

17
/**
18
 * Streaming transport client implementation that uses named pipes for inter-process communication.
19
 */
20
export class NamedPipeClient implements IStreamingTransportClient {
2✔
21
    private readonly _baseName: string;
22
    private readonly _requestHandler: RequestHandler;
23
    private readonly _sender: PayloadSender;
24
    private readonly _receiver: PayloadReceiver;
25
    private readonly _requestManager: RequestManager;
26
    private readonly _protocolAdapter: ProtocolAdapter;
27
    private readonly _autoReconnect: boolean;
28
    private _isDisconnecting: boolean;
29

30
    /**
31
     * Creates a new instance of the [NamedPipeClient](xref:botframework-streaming.NamedPipeClient) class.
32
     *
33
     * @param baseName The named pipe to connect to.
34
     * @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this client.
35
     * @param autoReconnect Optional setting to determine if the client sould attempt to reconnect automatically on disconnection events. Defaults to true.
36
     */
37
    constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect = true) {
×
38
        this._baseName = baseName;
2✔
39
        this._requestHandler = requestHandler;
2✔
40
        this._autoReconnect = autoReconnect;
2✔
41
        this._requestManager = new RequestManager();
2✔
42
        this._sender = new PayloadSender();
2✔
43
        this._sender.disconnected = this.onConnectionDisconnected.bind(this);
2✔
44
        this._receiver = new PayloadReceiver();
2✔
45
        this._receiver.disconnected = this.onConnectionDisconnected.bind(this);
2✔
46
        this._protocolAdapter = new ProtocolAdapter(
2✔
47
            this._requestHandler,
48
            this._requestManager,
49
            this._sender,
50
            this._receiver
51
        );
52
    }
53

54
    /**
55
     * Establish a connection with no custom headers.
56
     */
57
    async connect(): Promise<void> {
58
        const outgoingPipeName: string =
59
            NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerIncomingPath;
1✔
60
        const outgoing = connect(outgoingPipeName);
1✔
61
        const incomingPipeName: string =
62
            NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerOutgoingPath;
1✔
63
        const incoming = connect(incomingPipeName);
1✔
64
        // TODO: Fix INodeSocket type. Related issue https://github.com/microsoft/botbuilder-js/issues/4684.
NEW
65
        this._sender.connect(new NamedPipeTransport(outgoing as any));
1✔
NEW
66
        this._receiver.connect(new NamedPipeTransport(incoming as any));
1✔
67
    }
68

69
    /**
70
     * Disconnect the client.
71
     */
72
    disconnect(): void {
73
        this._sender.disconnect();
3✔
74
        this._receiver.disconnect();
3✔
75
    }
76

77
    /**
78
     * Task used to send data over this client connection.
79
     *
80
     * @param request The [StreamingRequest](xref:botframework-streaming.StreamingRequest) to send.
81
     * @returns A promise for an instance of [IReceiveResponse](xref:botframework-streaming.IReceiveResponse) on completion of the send operation.
82
     */
83
    async send(request: StreamingRequest): Promise<IReceiveResponse> {
84
        return this._protocolAdapter.sendRequest(request);
×
85
    }
86

87
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
    private onConnectionDisconnected(sender: Record<string, unknown>, args: any): void {
89
        if (!this._isDisconnecting) {
3✔
90
            this._isDisconnecting = true;
1✔
91
            try {
1✔
92
                if (this._sender.isConnected) {
1!
93
                    this._sender.disconnect();
1✔
94
                }
95

96
                if (this._receiver.isConnected) {
1!
97
                    this._receiver.disconnect();
1✔
98
                }
99

100
                if (this._autoReconnect) {
1!
101
                    this.connect()
×
102
                        .then((): void => {})
103
                        .catch((error): void => {
104
                            throw new Error(
×
105
                                `Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. `
106
                            );
107
                        });
108
                }
109
            } finally {
110
                this._isDisconnecting = false;
1✔
111
            }
112
        }
113
    }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc