UNPKG

2.73 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2019 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.ChannelImplementation = void 0;
20const channel_credentials_1 = require("./channel-credentials");
21const internal_channel_1 = require("./internal-channel");
22class ChannelImplementation {
23 constructor(target, credentials, options) {
24 if (typeof target !== 'string') {
25 throw new TypeError('Channel target must be a string');
26 }
27 if (!(credentials instanceof channel_credentials_1.ChannelCredentials)) {
28 throw new TypeError('Channel credentials must be a ChannelCredentials object');
29 }
30 if (options) {
31 if (typeof options !== 'object') {
32 throw new TypeError('Channel options must be an object');
33 }
34 }
35 this.internalChannel = new internal_channel_1.InternalChannel(target, credentials, options);
36 }
37 close() {
38 this.internalChannel.close();
39 }
40 getTarget() {
41 return this.internalChannel.getTarget();
42 }
43 getConnectivityState(tryToConnect) {
44 return this.internalChannel.getConnectivityState(tryToConnect);
45 }
46 watchConnectivityState(currentState, deadline, callback) {
47 this.internalChannel.watchConnectivityState(currentState, deadline, callback);
48 }
49 /**
50 * Get the channelz reference object for this channel. The returned value is
51 * garbage if channelz is disabled for this channel.
52 * @returns
53 */
54 getChannelzRef() {
55 return this.internalChannel.getChannelzRef();
56 }
57 createCall(method, deadline, host, parentCall, propagateFlags) {
58 if (typeof method !== 'string') {
59 throw new TypeError('Channel#createCall: method must be a string');
60 }
61 if (!(typeof deadline === 'number' || deadline instanceof Date)) {
62 throw new TypeError('Channel#createCall: deadline must be a number or Date');
63 }
64 return this.internalChannel.createCall(method, deadline, host, parentCall, propagateFlags);
65 }
66}
67exports.ChannelImplementation = ChannelImplementation;
68//# sourceMappingURL=channel.js.map
\No newline at end of file