@databricks/sql 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +1 -1
  2. package/dist/DBSQLClient.d.ts +15 -8
  3. package/dist/DBSQLClient.js +76 -81
  4. package/dist/DBSQLClient.js.map +1 -1
  5. package/dist/DBSQLOperation/FetchResultsHelper.d.ts +3 -3
  6. package/dist/DBSQLOperation/FetchResultsHelper.js +4 -3
  7. package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -1
  8. package/dist/DBSQLOperation/index.d.ts +19 -10
  9. package/dist/DBSQLOperation/index.js +178 -47
  10. package/dist/DBSQLOperation/index.js.map +1 -1
  11. package/dist/DBSQLParameter.d.ts +33 -0
  12. package/dist/DBSQLParameter.js +87 -0
  13. package/dist/DBSQLParameter.js.map +1 -0
  14. package/dist/DBSQLSession.d.ts +10 -7
  15. package/dist/DBSQLSession.js +188 -23
  16. package/dist/DBSQLSession.js.map +1 -1
  17. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +3 -3
  18. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +3 -4
  19. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -1
  20. package/dist/connection/auth/DatabricksOAuth/OAuthManager.d.ts +11 -3
  21. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +74 -20
  22. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
  23. package/dist/connection/auth/DatabricksOAuth/index.d.ts +4 -6
  24. package/dist/connection/auth/DatabricksOAuth/index.js +1 -1
  25. package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -1
  26. package/dist/connection/auth/PlainHttpAuthentication.d.ts +6 -3
  27. package/dist/connection/auth/PlainHttpAuthentication.js +1 -0
  28. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  29. package/dist/connection/connections/HttpConnection.d.ts +16 -9
  30. package/dist/connection/connections/HttpConnection.js +60 -51
  31. package/dist/connection/connections/HttpConnection.js.map +1 -1
  32. package/dist/connection/connections/ThriftHttpConnection.d.ts +38 -0
  33. package/dist/connection/connections/ThriftHttpConnection.js +134 -0
  34. package/dist/connection/connections/ThriftHttpConnection.js.map +1 -0
  35. package/dist/connection/contracts/IAuthentication.d.ts +2 -2
  36. package/dist/connection/contracts/IConnectionOptions.d.ts +17 -19
  37. package/dist/connection/contracts/IConnectionProvider.d.ts +6 -3
  38. package/dist/contracts/IClientContext.d.ts +10 -0
  39. package/dist/{connection/contracts/IThriftConnection.js → contracts/IClientContext.js} +1 -1
  40. package/dist/contracts/IClientContext.js.map +1 -0
  41. package/dist/contracts/IDBSQLClient.d.ts +4 -0
  42. package/dist/contracts/IDBSQLSession.d.ts +34 -0
  43. package/dist/contracts/IDriver.d.ts +24 -0
  44. package/dist/contracts/IDriver.js +3 -0
  45. package/dist/contracts/IDriver.js.map +1 -0
  46. package/dist/errors/OperationStateError.js +2 -1
  47. package/dist/errors/OperationStateError.js.map +1 -1
  48. package/dist/errors/ParameterError.d.ts +2 -0
  49. package/dist/errors/ParameterError.js +6 -0
  50. package/dist/errors/ParameterError.js.map +1 -0
  51. package/dist/errors/StagingError.d.ts +2 -0
  52. package/dist/errors/StagingError.js +6 -0
  53. package/dist/errors/StagingError.js.map +1 -0
  54. package/dist/hive/HiveDriver.d.ts +8 -5
  55. package/dist/hive/HiveDriver.js +23 -23
  56. package/dist/hive/HiveDriver.js.map +1 -1
  57. package/dist/index.d.ts +2 -1
  58. package/dist/index.js +4 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/result/ArrowResult.d.ts +3 -1
  61. package/dist/result/ArrowResult.js +6 -4
  62. package/dist/result/ArrowResult.js.map +1 -1
  63. package/dist/result/CloudFetchResult.d.ts +2 -1
  64. package/dist/result/CloudFetchResult.js +5 -3
  65. package/dist/result/CloudFetchResult.js.map +1 -1
  66. package/dist/result/JsonResult.d.ts +3 -1
  67. package/dist/result/JsonResult.js +2 -1
  68. package/dist/result/JsonResult.js.map +1 -1
  69. package/dist/utils/index.d.ts +1 -2
  70. package/dist/utils/index.js +1 -3
  71. package/dist/utils/index.js.map +1 -1
  72. package/dist/version.d.ts +1 -1
  73. package/dist/version.js +1 -1
  74. package/package.json +3 -5
  75. package/thrift/TCLIService.d.ts +2 -1
  76. package/thrift/TCLIService.js +1 -1
  77. package/thrift/TCLIService_types.d.ts +11 -3
  78. package/thrift/TCLIService_types.js +41 -4
  79. package/dist/DBSQLOperation/CompleteOperationHelper.d.ts +0 -13
  80. package/dist/DBSQLOperation/CompleteOperationHelper.js +0 -56
  81. package/dist/DBSQLOperation/CompleteOperationHelper.js.map +0 -1
  82. package/dist/DBSQLOperation/OperationStatusHelper.d.ts +0 -16
  83. package/dist/DBSQLOperation/OperationStatusHelper.js +0 -138
  84. package/dist/DBSQLOperation/OperationStatusHelper.js.map +0 -1
  85. package/dist/DBSQLOperation/SchemaHelper.d.ts +0 -13
  86. package/dist/DBSQLOperation/SchemaHelper.js +0 -74
  87. package/dist/DBSQLOperation/SchemaHelper.js.map +0 -1
  88. package/dist/connection/contracts/IThriftConnection.d.ts +0 -4
  89. package/dist/connection/contracts/IThriftConnection.js.map +0 -1
  90. package/dist/node_modules/thrift/LICENSE +0 -306
  91. package/dist/node_modules/thrift/README.md +0 -210
  92. package/dist/node_modules/thrift/lib/nodejs/README.md +0 -142
  93. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/binary.js +0 -168
  94. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/binary_protocol.js +0 -367
  95. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/browser.js +0 -49
  96. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/buffered_transport.js +0 -186
  97. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/compact_protocol.js +0 -915
  98. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/connection.js +0 -396
  99. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/create_client.js +0 -54
  100. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/framed_transport.js +0 -185
  101. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/header_protocol.js +0 -258
  102. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/header_transport.js +0 -341
  103. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +0 -292
  104. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/index.js +0 -76
  105. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +0 -32
  106. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/int64_util.js +0 -91
  107. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/json_parse.js +0 -299
  108. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/json_protocol.js +0 -799
  109. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/log.js +0 -87
  110. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +0 -63
  111. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +0 -73
  112. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/protocol.js +0 -22
  113. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/server.js +0 -123
  114. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/thrift.js +0 -241
  115. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/transport.js +0 -22
  116. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/web_server.js +0 -567
  117. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/ws_connection.js +0 -286
  118. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/ws_transport.js +0 -206
  119. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/xhr_connection.js +0 -280
  120. package/dist/node_modules/thrift/package.json +0 -72
  121. package/dist/utils/areHeadersEqual.d.ts +0 -2
  122. package/dist/utils/areHeadersEqual.js +0 -49
  123. package/dist/utils/areHeadersEqual.js.map +0 -1
@@ -1,286 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- var util = require('util');
20
- var WebSocket = require('isomorphic-ws');
21
- var EventEmitter = require("events").EventEmitter;
22
- var thrift = require('./thrift');
23
-
24
- var TBufferedTransport = require('./buffered_transport');
25
- var TJSONProtocol = require('./json_protocol');
26
- var InputBufferUnderrunError = require('./input_buffer_underrun_error');
27
-
28
- var createClient = require('./create_client');
29
- var jsEnv = require('browser-or-node');
30
- exports.WSConnection = WSConnection;
31
-
32
- /**
33
- * @class
34
- * @name WSConnectOptions
35
- * @property {string} transport - The Thrift layered transport to use (TBufferedTransport, etc).
36
- * @property {string} protocol - The Thrift serialization protocol to use (TJSONProtocol, etc.).
37
- * @property {string} path - The URL path to connect to (e.g. "/", "/mySvc", "/thrift/quoteSvc", etc.).
38
- * @property {object} headers - A standard Node.js header hash, an object hash containing key/value
39
- * pairs where the key is the header name string and the value is the header value string.
40
- * @property {boolean} secure - True causes the connection to use wss, otherwise ws is used.
41
- * @property {object} wsOptions - Options passed on to WebSocket.
42
- * @example
43
- * //Use a secured websocket connection
44
- * // uses the buffered transport layer, uses the JSON protocol and directs RPC traffic
45
- * // to wss://thrift.example.com:9090/hello
46
- * var thrift = require('thrift');
47
- * var options = {
48
- * transport: thrift.TBufferedTransport,
49
- * protocol: thrift.TJSONProtocol,
50
- * path: "/hello",
51
- * secure: true
52
- * };
53
- * var con = thrift.createWSConnection("thrift.example.com", 9090, options);
54
- * con.open()
55
- * var client = thrift.createWSClient(myService, connection);
56
- * client.myServiceFunction();
57
- * con.close()
58
- */
59
-
60
- /**
61
- * Initializes a Thrift WSConnection instance (use createWSConnection() rather than
62
- * instantiating directly).
63
- * @constructor
64
- * @param {string} host - The host name or IP to connect to.
65
- * @param {number} port - The TCP port to connect to.
66
- * @param {WSConnectOptions} options - The configuration options to use.
67
- * @throws {error} Exceptions other than ttransport.InputBufferUnderrunError are rethrown
68
- * @event {error} The "error" event is fired when a Node.js error event occurs during
69
- * request or response processing, in which case the node error is passed on. An "error"
70
- * event may also be fired when the connection can not map a response back to the
71
- * appropriate client (an internal error), generating a TApplicationException.
72
- * @classdesc WSConnection objects provide Thrift end point transport
73
- * semantics implemented using Websockets.
74
- * @see {@link createWSConnection}
75
- */
76
- function WSConnection(host, port, options) {
77
- //Initialize the emitter base object
78
- EventEmitter.call(this);
79
-
80
- //Set configuration
81
- this.options = options || {};
82
- this.host = host;
83
- this.port = port;
84
- this.secure = this.options.secure || false;
85
- this.transport = this.options.transport || TBufferedTransport;
86
- this.protocol = this.options.protocol || TJSONProtocol;
87
- this.path = this.options.path;
88
- this.send_pending = [];
89
-
90
- //The sequence map is used to map seqIDs back to the
91
- // calling client in multiplexed scenarios
92
- this.seqId2Service = {};
93
-
94
- //Prepare WebSocket options
95
- this.wsOptions = {
96
- host: this.host,
97
- port: this.port || 80,
98
- path: this.options.path || '/',
99
- headers: this.options.headers || {}
100
- };
101
- for (var attrname in this.options.wsOptions) {
102
- this.wsOptions[attrname] = this.options.wsOptions[attrname];
103
- }
104
- };
105
- util.inherits(WSConnection, EventEmitter);
106
-
107
- WSConnection.prototype.__reset = function() {
108
- this.socket = null; //The web socket
109
- this.send_pending = []; //Buffers/Callback pairs waiting to be sent
110
- };
111
-
112
- WSConnection.prototype.__onOpen = function() {
113
- this.emit("open");
114
- if (this.send_pending.length > 0) {
115
- //If the user made calls before the connection was fully
116
- //open, send them now
117
- this.send_pending.forEach(function(data) {
118
- this.socket.send(data);
119
- }, this);
120
- this.send_pending = [];
121
- }
122
- };
123
-
124
- WSConnection.prototype.__onClose = function(evt) {
125
- this.emit("close");
126
- this.__reset();
127
- };
128
-
129
- WSConnection.prototype.__decodeCallback = function(transport_with_data) {
130
- var proto = new this.protocol(transport_with_data);
131
- try {
132
- while (true) {
133
- var header = proto.readMessageBegin();
134
- var dummy_seqid = header.rseqid * -1;
135
- var client = this.client;
136
- //The Multiplexed Protocol stores a hash of seqid to service names
137
- // in seqId2Service. If the SeqId is found in the hash we need to
138
- // lookup the appropriate client for this call.
139
- // The client var is a single client object when not multiplexing,
140
- // when using multiplexing it is a service name keyed hash of client
141
- // objects.
142
- //NOTE: The 2 way interdependencies between protocols, transports,
143
- // connections and clients in the Node.js implementation are irregular
144
- // and make the implementation difficult to extend and maintain. We
145
- // should bring this stuff inline with typical thrift I/O stack
146
- // operation soon.
147
- // --ra
148
- var service_name = this.seqId2Service[header.rseqid];
149
- if (service_name) {
150
- client = this.client[service_name];
151
- delete this.seqId2Service[header.rseqid];
152
- }
153
- /*jshint -W083 */
154
- client._reqs[dummy_seqid] = function(err, success) {
155
- transport_with_data.commitPosition();
156
- var clientCallback = client._reqs[header.rseqid];
157
- delete client._reqs[header.rseqid];
158
- if (clientCallback) {
159
- clientCallback(err, success);
160
- }
161
- };
162
- /*jshint +W083 */
163
- if (client['recv_' + header.fname]) {
164
- client['recv_' + header.fname](proto, header.mtype, dummy_seqid);
165
- } else {
166
- delete client._reqs[dummy_seqid];
167
- this.emit("error",
168
- new thrift.TApplicationException(
169
- thrift.TApplicationExceptionType.WRONG_METHOD_NAME,
170
- "Received a response to an unknown RPC function"));
171
- }
172
- }
173
- } catch (e) {
174
- if (e instanceof InputBufferUnderrunError) {
175
- transport_with_data.rollbackPosition();
176
- } else {
177
- throw e;
178
- }
179
- }
180
- };
181
-
182
- WSConnection.prototype.__onData = function(data) {
183
- if (Object.prototype.toString.call(data) === "[object ArrayBuffer]") {
184
- data = new Uint8Array(data);
185
- }
186
- var buf = new Buffer(data);
187
- this.transport.receiver(this.__decodeCallback.bind(this))(buf);
188
-
189
- };
190
-
191
- WSConnection.prototype.__onMessage = function(evt) {
192
- this.__onData(evt.data);
193
- };
194
-
195
- WSConnection.prototype.__onError = function(evt) {
196
- this.emit("error", evt);
197
- this.socket.close();
198
- };
199
-
200
- /**
201
- * Returns true if the transport is open
202
- * @readonly
203
- * @returns {boolean}
204
- */
205
- WSConnection.prototype.isOpen = function() {
206
- return this.socket && this.socket.readyState === this.socket.OPEN;
207
- };
208
-
209
- /**
210
- * Opens the transport connection
211
- */
212
- WSConnection.prototype.open = function() {
213
- //If OPEN/CONNECTING/CLOSING ignore additional opens
214
- if (this.socket && this.socket.readyState !== this.socket.CLOSED) {
215
- return;
216
- }
217
- //If there is no socket or the socket is closed:
218
- if (jsEnv.isBrowser) {
219
- this.socket = new WebSocket(this.uri());
220
- } else {
221
- this.socket = new WebSocket(this.uri(), "", this.wsOptions);
222
- }
223
- this.socket.binaryType = 'arraybuffer';
224
- this.socket.onopen = this.__onOpen.bind(this);
225
- this.socket.onmessage = this.__onMessage.bind(this);
226
- this.socket.onerror = this.__onError.bind(this);
227
- this.socket.onclose = this.__onClose.bind(this);
228
- };
229
-
230
- /**
231
- * Closes the transport connection
232
- */
233
- WSConnection.prototype.close = function() {
234
- this.socket.close();
235
- };
236
-
237
- /**
238
- * Return URI for the connection
239
- * @returns {string} URI
240
- */
241
- WSConnection.prototype.uri = function() {
242
- var schema = this.secure ? 'wss' : 'ws';
243
- var port = '';
244
- var path = this.path || '/';
245
- var host = this.host;
246
-
247
- // avoid port if default for schema
248
- if (this.port && (('wss' === schema && this.port !== 443) ||
249
- ('ws' === schema && this.port !== 80))) {
250
- port = ':' + this.port;
251
- }
252
-
253
- return schema + '://' + host + port + path;
254
- };
255
-
256
- /**
257
- * Writes Thrift message data to the connection
258
- * @param {Buffer} data - A Node.js Buffer containing the data to write
259
- * @returns {void} No return value.
260
- * @event {error} the "error" event is raised upon request failure passing the
261
- * Node.js error object to the listener.
262
- */
263
- WSConnection.prototype.write = function(data) {
264
- if (this.isOpen()) {
265
- //Send data and register a callback to invoke the client callback
266
- this.socket.send(data);
267
- } else {
268
- //Queue the send to go out __onOpen
269
- this.send_pending.push(data);
270
- }
271
- };
272
-
273
- /**
274
- * Creates a new WSConnection object, used by Thrift clients to connect
275
- * to Thrift HTTP based servers.
276
- * @param {string} host - The host name or IP to connect to.
277
- * @param {number} port - The TCP port to connect to.
278
- * @param {WSConnectOptions} options - The configuration options to use.
279
- * @returns {WSConnection} The connection object.
280
- * @see {@link WSConnectOptions}
281
- */
282
- exports.createWSConnection = function(host, port, options) {
283
- return new WSConnection(host, port, options);
284
- };
285
-
286
- exports.createWSClient = createClient;
@@ -1,206 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
- var log = require('./log');
21
-
22
- module.exports = TWebSocketTransport;
23
-
24
- /**
25
- * Constructor Function for the WebSocket transport.
26
- * @constructor
27
- * @param {string} [url] - The URL to connect to.
28
- * @classdesc The Apache Thrift Transport layer performs byte level I/O
29
- * between RPC clients and servers. The JavaScript TWebSocketTransport object
30
- * uses the WebSocket protocol. Target servers must implement WebSocket.
31
- * (see: node.js example server_http.js).
32
- * @example
33
- * var transport = new Thrift.TWebSocketTransport("http://localhost:8585");
34
- */
35
- function TWebSocketTransport(url) {
36
- this.__reset(url);
37
- };
38
-
39
-
40
- TWebSocketTransport.prototype.__reset = function(url) {
41
- this.url = url; //Where to connect
42
- this.socket = null; //The web socket
43
- this.callbacks = []; //Pending callbacks
44
- this.send_pending = []; //Buffers/Callback pairs waiting to be sent
45
- this.send_buf = ''; //Outbound data, immutable until sent
46
- this.recv_buf = ''; //Inbound data
47
- this.rb_wpos = 0; //Network write position in receive buffer
48
- this.rb_rpos = 0; //Client read position in receive buffer
49
- };
50
-
51
- /**
52
- * Sends the current WS request and registers callback. The async
53
- * parameter is ignored (WS flush is always async) and the callback
54
- * function parameter is required.
55
- * @param {object} async - Ignored.
56
- * @param {object} callback - The client completion callback.
57
- * @returns {undefined|string} Nothing (undefined)
58
- */
59
- TWebSocketTransport.prototype.flush = function(async, callback) {
60
- var self = this;
61
- if (this.isOpen()) {
62
- //Send data and register a callback to invoke the client callback
63
- this.socket.send(this.send_buf);
64
- this.callbacks.push((function() {
65
- var clientCallback = callback;
66
- return function(msg) {
67
- self.setRecvBuffer(msg);
68
- clientCallback();
69
- };
70
- }()));
71
- } else {
72
- //Queue the send to go out __onOpen
73
- this.send_pending.push({
74
- buf: this.send_buf,
75
- cb: callback
76
- });
77
- }
78
- };
79
-
80
- TWebSocketTransport.prototype.__onOpen = function() {
81
- var self = this;
82
- if (this.send_pending.length > 0) {
83
- //If the user made calls before the connection was fully
84
- //open, send them now
85
- this.send_pending.forEach(function(elem) {
86
- self.socket.send(elem.buf);
87
- self.callbacks.push((function() {
88
- var clientCallback = elem.cb;
89
- return function(msg) {
90
- self.setRecvBuffer(msg);
91
- clientCallback();
92
- };
93
- }()));
94
- });
95
- this.send_pending = [];
96
- }
97
- };
98
-
99
- TWebSocketTransport.prototype.__onClose = function(evt) {
100
- this.__reset(this.url);
101
- };
102
-
103
- TWebSocketTransport.prototype.__onMessage = function(evt) {
104
- if (this.callbacks.length) {
105
- this.callbacks.shift()(evt.data);
106
- }
107
- };
108
-
109
- TWebSocketTransport.prototype.__onError = function(evt) {
110
- log.error('websocket: ' + evt.toString());
111
- this.socket.close();
112
- };
113
-
114
- /**
115
- * Sets the buffer to use when receiving server responses.
116
- * @param {string} buf - The buffer to receive server responses.
117
- */
118
- TWebSocketTransport.prototype.setRecvBuffer = function(buf) {
119
- this.recv_buf = buf;
120
- this.recv_buf_sz = this.recv_buf.length;
121
- this.wpos = this.recv_buf.length;
122
- this.rpos = 0;
123
- };
124
-
125
- /**
126
- * Returns true if the transport is open
127
- * @readonly
128
- * @returns {boolean}
129
- */
130
- TWebSocketTransport.prototype.isOpen = function() {
131
- return this.socket && this.socket.readyState == this.socket.OPEN;
132
- };
133
-
134
- /**
135
- * Opens the transport connection
136
- */
137
- TWebSocketTransport.prototype.open = function() {
138
- //If OPEN/CONNECTING/CLOSING ignore additional opens
139
- if (this.socket && this.socket.readyState != this.socket.CLOSED) {
140
- return;
141
- }
142
- //If there is no socket or the socket is closed:
143
- this.socket = new WebSocket(this.url);
144
- this.socket.onopen = this.__onOpen.bind(this);
145
- this.socket.onmessage = this.__onMessage.bind(this);
146
- this.socket.onerror = this.__onError.bind(this);
147
- this.socket.onclose = this.__onClose.bind(this);
148
- };
149
-
150
- /**
151
- * Closes the transport connection
152
- */
153
- TWebSocketTransport.prototype.close = function() {
154
- this.socket.close();
155
- };
156
-
157
- /**
158
- * Returns the specified number of characters from the response
159
- * buffer.
160
- * @param {number} len - The number of characters to return.
161
- * @returns {string} Characters sent by the server.
162
- */
163
- TWebSocketTransport.prototype.read = function(len) {
164
- var avail = this.wpos - this.rpos;
165
-
166
- if (avail === 0) {
167
- return '';
168
- }
169
-
170
- var give = len;
171
-
172
- if (avail < len) {
173
- give = avail;
174
- }
175
-
176
- var ret = this.read_buf.substr(this.rpos, give);
177
- this.rpos += give;
178
-
179
- //clear buf when complete?
180
- return ret;
181
- };
182
-
183
- /**
184
- * Returns the entire response buffer.
185
- * @returns {string} Characters sent by the server.
186
- */
187
- TWebSocketTransport.prototype.readAll = function() {
188
- return this.recv_buf;
189
- };
190
-
191
- /**
192
- * Sets the send buffer to buf.
193
- * @param {string} buf - The buffer to send.
194
- */
195
- TWebSocketTransport.prototype.write = function(buf) {
196
- this.send_buf = buf;
197
- };
198
-
199
- /**
200
- * Returns the send buffer.
201
- * @readonly
202
- * @returns {string} The send buffer.
203
- */
204
- TWebSocketTransport.prototype.getSendBuffer = function() {
205
- return this.send_buf;
206
- };