botframework-streaming
Advanced tools
Comparing version 4.11.0-dev.20200929.ca9de94 to 4.11.0-dev.20201019.3446d04
@@ -53,3 +53,3 @@ "use strict"; | ||
function PayloadAssembler(streamManager, params) { | ||
this._byteOrderMark = 0xFEFF; | ||
this._byteOrderMark = 0xfeff; | ||
this._utf = 'utf8'; | ||
@@ -80,5 +80,3 @@ if (params.header) { | ||
if (header.payloadType === payloads_1.PayloadTypes.response || header.payloadType === payloads_1.PayloadTypes.request) { | ||
this.process(stream) | ||
.then() | ||
.catch(); | ||
this.process(stream).then().catch(); | ||
} | ||
@@ -96,6 +94,6 @@ else if (header.end) { | ||
PayloadAssembler.prototype.payloadFromJson = function (json) { | ||
return JSON.parse((json.charCodeAt(0) === this._byteOrderMark) ? json.slice(1) : json); | ||
return JSON.parse(json.charCodeAt(0) === this._byteOrderMark ? json.slice(1) : json); | ||
}; | ||
PayloadAssembler.prototype.stripBOM = function (input) { | ||
return (input.charCodeAt(0) === this._byteOrderMark) ? input.slice(1) : input; | ||
return input.charCodeAt(0) === this._byteOrderMark ? input.slice(1) : input; | ||
}; | ||
@@ -102,0 +100,0 @@ PayloadAssembler.prototype.process = function (stream) { |
@@ -72,3 +72,8 @@ "use strict"; | ||
return __generator(this, function (_a) { | ||
header = { payloadType: this.payloadType, payloadLength: this.streamLength, id: this.id, end: true }; | ||
header = { | ||
payloadType: this.payloadType, | ||
payloadLength: this.streamLength, | ||
id: this.id, | ||
end: true, | ||
}; | ||
this.sender.sendPayload(header, this.stream); | ||
@@ -75,0 +80,0 @@ return [2 /*return*/]; |
@@ -8,3 +8,7 @@ "use strict"; | ||
this.content = content; | ||
this.description = { id: this.id, type: (this.content.headers) ? this.content.headers.type : 'unknown', length: (this.content.headers) ? this.content.headers.contentLength : 0 }; | ||
this.description = { | ||
id: this.id, | ||
type: this.content.headers ? this.content.headers.type : 'unknown', | ||
length: this.content.headers ? this.content.headers.contentLength : 0, | ||
}; | ||
} | ||
@@ -11,0 +15,0 @@ return HttpContentStream; |
@@ -9,4 +9,4 @@ /** | ||
/** | ||
* Streaming payload header definition. | ||
*/ | ||
* Streaming payload header definition. | ||
*/ | ||
export interface IHeader { | ||
@@ -13,0 +13,0 @@ payloadType: string; |
@@ -9,3 +9,3 @@ /** | ||
export declare type ValidBuffer = string | Uint8Array | INodeBuffer; | ||
export declare type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; | ||
export declare type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex'; | ||
/** | ||
@@ -12,0 +12,0 @@ * Represents a Buffer from the `net` module in Node.js. |
@@ -53,13 +53,13 @@ /** | ||
}): T; | ||
addListener(event: "close", listener: () => void): this; | ||
addListener(event: "data", listener: (chunk: any) => void): this; | ||
addListener(event: "end", listener: () => void): this; | ||
addListener(event: "readable", listener: () => void): this; | ||
addListener(event: "error", listener: (err: Error) => void): this; | ||
addListener(event: 'close', listener: () => void): this; | ||
addListener(event: 'data', listener: (chunk: any) => void): this; | ||
addListener(event: 'end', listener: () => void): this; | ||
addListener(event: 'readable', listener: () => void): this; | ||
addListener(event: 'error', listener: (err: Error) => void): this; | ||
addListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
emit(event: "close"): boolean; | ||
emit(event: "data", chunk: any): boolean; | ||
emit(event: "end"): boolean; | ||
emit(event: "readable"): boolean; | ||
emit(event: "error", err: Error): boolean; | ||
emit(event: 'close'): boolean; | ||
emit(event: 'data', chunk: any): boolean; | ||
emit(event: 'end'): boolean; | ||
emit(event: 'readable'): boolean; | ||
emit(event: 'error', err: Error): boolean; | ||
emit(event: string | symbol, ...args: any[]): boolean; | ||
@@ -72,24 +72,24 @@ eventNames(): Array<string | symbol>; | ||
on(event: string, listener: (...args: any[]) => void): this; | ||
on(event: "close", listener: (had_error: boolean) => void): this; | ||
on(event: "connect", listener: () => void): this; | ||
on(event: "data", listener: (data: INodeBuffer) => void): this; | ||
on(event: "end", listener: () => void): this; | ||
on(event: "error", listener: (err: Error) => void): this; | ||
once(event: "close", listener: () => void): this; | ||
once(event: "data", listener: (chunk: any) => void): this; | ||
once(event: "end", listener: () => void): this; | ||
once(event: "readable", listener: () => void): this; | ||
once(event: "error", listener: (err: Error) => void): this; | ||
on(event: 'close', listener: (had_error: boolean) => void): this; | ||
on(event: 'connect', listener: () => void): this; | ||
on(event: 'data', listener: (data: INodeBuffer) => void): this; | ||
on(event: 'end', listener: () => void): this; | ||
on(event: 'error', listener: (err: Error) => void): this; | ||
once(event: 'close', listener: () => void): this; | ||
once(event: 'data', listener: (chunk: any) => void): this; | ||
once(event: 'end', listener: () => void): this; | ||
once(event: 'readable', listener: () => void): this; | ||
once(event: 'error', listener: (err: Error) => void): this; | ||
once(event: string | symbol, listener: (...args: any[]) => void): this; | ||
prependListener(event: "close", listener: () => void): this; | ||
prependListener(event: "data", listener: (chunk: any) => void): this; | ||
prependListener(event: "end", listener: () => void): this; | ||
prependListener(event: "readable", listener: () => void): this; | ||
prependListener(event: "error", listener: (err: Error) => void): this; | ||
prependListener(event: 'close', listener: () => void): this; | ||
prependListener(event: 'data', listener: (chunk: any) => void): this; | ||
prependListener(event: 'end', listener: () => void): this; | ||
prependListener(event: 'readable', listener: () => void): this; | ||
prependListener(event: 'error', listener: (err: Error) => void): this; | ||
prependListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
prependOnceListener(event: "close", listener: () => void): this; | ||
prependOnceListener(event: "data", listener: (chunk: any) => void): this; | ||
prependOnceListener(event: "end", listener: () => void): this; | ||
prependOnceListener(event: "readable", listener: () => void): this; | ||
prependOnceListener(event: "error", listener: (err: Error) => void): this; | ||
prependOnceListener(event: 'close', listener: () => void): this; | ||
prependOnceListener(event: 'data', listener: (chunk: any) => void): this; | ||
prependOnceListener(event: 'end', listener: () => void): this; | ||
prependOnceListener(event: 'readable', listener: () => void): this; | ||
prependOnceListener(event: 'error', listener: (err: Error) => void): this; | ||
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
@@ -96,0 +96,0 @@ rawListeners(event: string | symbol): Function[]; |
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
import { INodeBuffer } from "./INodeBuffer"; | ||
import { INodeBuffer } from './INodeBuffer'; | ||
export interface ISocket { | ||
@@ -15,0 +15,0 @@ isConnected: boolean; |
@@ -9,4 +9,4 @@ /** | ||
/** | ||
* Abstraction for a generic transport definition. | ||
*/ | ||
* Abstraction for a generic transport definition. | ||
*/ | ||
export interface ITransport { | ||
@@ -13,0 +13,0 @@ isConnected: boolean; |
@@ -42,3 +42,4 @@ "use strict"; | ||
var header = { end: end, payloadLength: payloadLength, payloadType: payloadType, id: id }; | ||
if (!(header.payloadLength <= payloadConstants_1.PayloadConstants.MaxPayloadLength && header.payloadLength >= payloadConstants_1.PayloadConstants.MinLength)) { | ||
if (!(header.payloadLength <= payloadConstants_1.PayloadConstants.MaxPayloadLength && | ||
header.payloadLength >= payloadConstants_1.PayloadConstants.MinLength)) { | ||
throw Error("Header length of " + header.payloadLength + " is missing or malformed"); | ||
@@ -49,3 +50,5 @@ } | ||
} | ||
if (!header.id || !header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) || header.id.length !== this.IdLength) { | ||
if (!header.id || | ||
!header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) || | ||
header.id.length !== this.IdLength) { | ||
throw Error("Header ID '" + header.id + "' is missing or malformed."); | ||
@@ -59,4 +62,3 @@ } | ||
HeaderSerializer.headerLengthPadder = function (lengthValue, totalLength, padChar) { | ||
var result = Array(totalLength + 1) | ||
.join(padChar); | ||
var result = Array(totalLength + 1).join(padChar); | ||
var lengthString = lengthValue.toString(); | ||
@@ -63,0 +65,0 @@ return (result + lengthString).slice(lengthString.length); |
@@ -99,4 +99,3 @@ "use strict"; | ||
PayloadReceiver.prototype.runReceive = function () { | ||
this.receivePackets() | ||
.catch(); | ||
this.receivePackets().catch(); | ||
}; | ||
@@ -133,3 +132,4 @@ PayloadReceiver.prototype.receivePackets = function () { | ||
case 5: | ||
if (!(bytesActuallyRead < header.payloadLength && bytesActuallyRead < payloadConstants_1.PayloadConstants.MaxPayloadLength)) return [3 /*break*/, 7]; | ||
if (!(bytesActuallyRead < header.payloadLength && | ||
bytesActuallyRead < payloadConstants_1.PayloadConstants.MaxPayloadLength)) return [3 /*break*/, 7]; | ||
count = Math.min(header.payloadLength - bytesActuallyRead, payloadConstants_1.PayloadConstants.MaxPayloadLength); | ||
@@ -136,0 +136,0 @@ _b = this; |
@@ -59,3 +59,5 @@ "use strict"; | ||
this.assemblerManager = new payloadAssemblerManager_1.PayloadAssemblerManager(this.streamManager, function (id, response) { return _this.onReceiveResponse(id, response); }, function (id, request) { return _this.onReceiveRequest(id, request); }); | ||
this.payloadReceiver.subscribe(function (header) { return _this.assemblerManager.getPayloadStream(header); }, function (header, contentStream, contentLength) { return _this.assemblerManager.onReceive(header, contentStream, contentLength); }); | ||
this.payloadReceiver.subscribe(function (header) { return _this.assemblerManager.getPayloadStream(header); }, function (header, contentStream, contentLength) { | ||
return _this.assemblerManager.onReceive(header, contentStream, contentLength); | ||
}); | ||
} | ||
@@ -132,4 +134,3 @@ /// <summary> | ||
ProtocolAdapter.prototype.onCancelStream = function (contentStreamAssembler) { | ||
this.sendOperations.sendCancelStream(contentStreamAssembler.id) | ||
.catch(); | ||
this.sendOperations.sendCancelStream(contentStreamAssembler.id).catch(); | ||
}; | ||
@@ -136,0 +137,0 @@ return ProtocolAdapter; |
@@ -58,3 +58,3 @@ "use strict"; | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length | ||
contentLength: stream.length, | ||
}, stream)); | ||
@@ -61,0 +61,0 @@ } |
@@ -49,3 +49,3 @@ "use strict"; | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length | ||
contentLength: stream.length, | ||
}, stream)); | ||
@@ -52,0 +52,0 @@ }; |
@@ -31,10 +31,10 @@ "use strict"; | ||
function isNetServer(o) { | ||
return (hasCloseMethod && hasListenMethod) ? true : false; | ||
return hasCloseMethod && hasListenMethod ? true : false; | ||
} | ||
function hasCloseMethod(o) { | ||
return (o.close && typeof o.close === 'function') ? true : false; | ||
return o.close && typeof o.close === 'function' ? true : false; | ||
} | ||
function hasListenMethod(o) { | ||
return (o.listen && typeof o.listen === 'function') ? true : false; | ||
return o.listen && typeof o.listen === 'function' ? true : false; | ||
} | ||
//# sourceMappingURL=createNodeServer.js.map |
@@ -125,5 +125,7 @@ "use strict"; | ||
BrowserWebSocket.prototype.setOnErrorHandler = function (handler) { | ||
this.webSocket.onerror = function (error) { if (error) { | ||
handler(error); | ||
} }; | ||
this.webSocket.onerror = function (error) { | ||
if (error) { | ||
handler(error); | ||
} | ||
}; | ||
}; | ||
@@ -130,0 +132,0 @@ /** |
@@ -72,3 +72,5 @@ "use strict"; | ||
this._protocolAdapter = new protocolAdapter_1.ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._closedSignal = function (x) { return x; }; | ||
this._closedSignal = function (x) { | ||
return x; | ||
}; | ||
} | ||
@@ -75,0 +77,0 @@ Object.defineProperty(WebSocketServer.prototype, "isConnected", { |
@@ -26,3 +26,3 @@ "use strict"; | ||
constructor(streamManager, params) { | ||
this._byteOrderMark = 0xFEFF; | ||
this._byteOrderMark = 0xfeff; | ||
this._utf = 'utf8'; | ||
@@ -53,5 +53,3 @@ if (params.header) { | ||
if (header.payloadType === payloads_1.PayloadTypes.response || header.payloadType === payloads_1.PayloadTypes.request) { | ||
this.process(stream) | ||
.then() | ||
.catch(); | ||
this.process(stream).then().catch(); | ||
} | ||
@@ -69,14 +67,14 @@ else if (header.end) { | ||
payloadFromJson(json) { | ||
return JSON.parse((json.charCodeAt(0) === this._byteOrderMark) ? json.slice(1) : json); | ||
return JSON.parse(json.charCodeAt(0) === this._byteOrderMark ? json.slice(1) : json); | ||
} | ||
stripBOM(input) { | ||
return (input.charCodeAt(0) === this._byteOrderMark) ? input.slice(1) : input; | ||
return input.charCodeAt(0) === this._byteOrderMark ? input.slice(1) : input; | ||
} | ||
process(stream) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let streamData = stream.read(stream.length); | ||
const streamData = stream.read(stream.length); | ||
if (!streamData) { | ||
return; | ||
} | ||
let streamDataAsString = streamData.toString(this._utf); | ||
const streamDataAsString = streamData.toString(this._utf); | ||
if (this.payloadType === payloads_1.PayloadTypes.request) { | ||
@@ -92,4 +90,4 @@ yield this.processRequest(streamDataAsString); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let responsePayload = this.payloadFromJson(this.stripBOM(streamDataAsString)); | ||
let receiveResponse = { streams: [], statusCode: responsePayload.statusCode }; | ||
const responsePayload = this.payloadFromJson(this.stripBOM(streamDataAsString)); | ||
const receiveResponse = { streams: [], statusCode: responsePayload.statusCode }; | ||
yield this.processStreams(responsePayload, receiveResponse); | ||
@@ -100,4 +98,4 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let requestPayload = this.payloadFromJson(streamDataAsString); | ||
let receiveRequest = { streams: [], path: requestPayload.path, verb: requestPayload.verb }; | ||
const requestPayload = this.payloadFromJson(streamDataAsString); | ||
const receiveRequest = { streams: [], path: requestPayload.path, verb: requestPayload.verb }; | ||
yield this.processStreams(requestPayload, receiveRequest); | ||
@@ -110,3 +108,3 @@ }); | ||
responsePayload.streams.forEach((responseStream) => { | ||
let contentAssembler = this._streamManager.getPayloadAssembler(responseStream.id); | ||
const contentAssembler = this._streamManager.getPayloadAssembler(responseStream.id); | ||
contentAssembler.payloadType = responseStream.contentType; | ||
@@ -113,0 +111,0 @@ contentAssembler.contentLength = responseStream.length; |
@@ -37,3 +37,3 @@ "use strict"; | ||
const { bufferArray } = yield this.readAll(); | ||
return (bufferArray || []).map(result => result.toString('utf8')).join(''); | ||
return (bufferArray || []).map((result) => result.toString('utf8')).join(''); | ||
}); | ||
@@ -43,3 +43,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let stringToParse = yield this.readAsString(); | ||
const stringToParse = yield this.readAsString(); | ||
try { | ||
@@ -56,8 +56,8 @@ return JSON.parse(stringToParse); | ||
// do a read-all | ||
let allData = []; | ||
const allData = []; | ||
let count = 0; | ||
let stream = this.getStream(); | ||
const stream = this.getStream(); | ||
// populate the array with any existing buffers | ||
while (count < stream.length) { | ||
let chunk = stream.read(stream.length); | ||
const chunk = stream.read(stream.length); | ||
allData.push(chunk); | ||
@@ -67,4 +67,4 @@ count += chunk.length; | ||
if (count < this.length) { | ||
let readToEnd = new Promise((resolve) => { | ||
let callback = (cs) => (chunk) => { | ||
const readToEnd = new Promise((resolve) => { | ||
const callback = (cs) => (chunk) => { | ||
allData.push(chunk); | ||
@@ -71,0 +71,0 @@ count += chunk.length; |
@@ -24,3 +24,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let stream = this.contentStream.content.getStream(); | ||
const stream = this.contentStream.content.getStream(); | ||
return { stream, streamLength: stream.length }; | ||
@@ -27,0 +27,0 @@ }); |
@@ -21,3 +21,3 @@ "use strict"; | ||
static serialize(item) { | ||
let stream = new subscribableStream_1.SubscribableStream(); | ||
const stream = new subscribableStream_1.SubscribableStream(); | ||
stream.write(JSON.stringify(item)); | ||
@@ -29,3 +29,3 @@ stream.end(); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let { stream, streamLength } = yield this.getStream(); | ||
const { stream, streamLength } = yield this.getStream(); | ||
this.stream = stream; | ||
@@ -38,3 +38,8 @@ this.streamLength = streamLength; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let header = { payloadType: this.payloadType, payloadLength: this.streamLength, id: this.id, end: true }; | ||
const header = { | ||
payloadType: this.payloadType, | ||
payloadLength: this.streamLength, | ||
id: this.id, | ||
end: true, | ||
}; | ||
this.sender.sendPayload(header, this.stream); | ||
@@ -41,0 +46,0 @@ }); |
@@ -31,3 +31,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let payload = { verb: this.request.verb, path: this.request.path, streams: [] }; | ||
const payload = { verb: this.request.verb, path: this.request.path, streams: [] }; | ||
if (this.request.streams) { | ||
@@ -34,0 +34,0 @@ this.request.streams.forEach(function (stream) { |
@@ -31,3 +31,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let payload = { statusCode: this.response.statusCode, streams: [] }; | ||
const payload = { statusCode: this.response.statusCode, streams: [] }; | ||
if (this.response.streams) { | ||
@@ -34,0 +34,0 @@ this.response.streams.forEach(function (stream) { |
@@ -8,3 +8,7 @@ "use strict"; | ||
this.content = content; | ||
this.description = { id: this.id, type: (this.content.headers) ? this.content.headers.type : 'unknown', length: (this.content.headers) ? this.content.headers.contentLength : 0 }; | ||
this.description = { | ||
id: this.id, | ||
type: this.content.headers ? this.content.headers.type : 'unknown', | ||
length: this.content.headers ? this.content.headers.contentLength : 0, | ||
}; | ||
} | ||
@@ -11,0 +15,0 @@ } |
@@ -16,3 +16,3 @@ /** | ||
export { SubscribableStream } from './subscribableStream'; | ||
export { NodeWebSocket, NodeWebSocketFactory, NodeWebSocketFactoryBase, WebSocketClient, WebSocketServer } from './webSocket'; | ||
export { NodeWebSocket, NodeWebSocketFactory, NodeWebSocketFactoryBase, WebSocketClient, WebSocketServer, } from './webSocket'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -9,4 +9,4 @@ /** | ||
/** | ||
* Streaming payload header definition. | ||
*/ | ||
* Streaming payload header definition. | ||
*/ | ||
export interface IHeader { | ||
@@ -13,0 +13,0 @@ payloadType: string; |
@@ -9,3 +9,3 @@ /** | ||
export declare type ValidBuffer = string | Uint8Array | INodeBuffer; | ||
export declare type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; | ||
export declare type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex'; | ||
/** | ||
@@ -12,0 +12,0 @@ * Represents a Buffer from the `net` module in Node.js. |
@@ -53,13 +53,13 @@ /** | ||
}): T; | ||
addListener(event: "close", listener: () => void): this; | ||
addListener(event: "data", listener: (chunk: any) => void): this; | ||
addListener(event: "end", listener: () => void): this; | ||
addListener(event: "readable", listener: () => void): this; | ||
addListener(event: "error", listener: (err: Error) => void): this; | ||
addListener(event: 'close', listener: () => void): this; | ||
addListener(event: 'data', listener: (chunk: any) => void): this; | ||
addListener(event: 'end', listener: () => void): this; | ||
addListener(event: 'readable', listener: () => void): this; | ||
addListener(event: 'error', listener: (err: Error) => void): this; | ||
addListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
emit(event: "close"): boolean; | ||
emit(event: "data", chunk: any): boolean; | ||
emit(event: "end"): boolean; | ||
emit(event: "readable"): boolean; | ||
emit(event: "error", err: Error): boolean; | ||
emit(event: 'close'): boolean; | ||
emit(event: 'data', chunk: any): boolean; | ||
emit(event: 'end'): boolean; | ||
emit(event: 'readable'): boolean; | ||
emit(event: 'error', err: Error): boolean; | ||
emit(event: string | symbol, ...args: any[]): boolean; | ||
@@ -72,24 +72,24 @@ eventNames(): Array<string | symbol>; | ||
on(event: string, listener: (...args: any[]) => void): this; | ||
on(event: "close", listener: (had_error: boolean) => void): this; | ||
on(event: "connect", listener: () => void): this; | ||
on(event: "data", listener: (data: INodeBuffer) => void): this; | ||
on(event: "end", listener: () => void): this; | ||
on(event: "error", listener: (err: Error) => void): this; | ||
once(event: "close", listener: () => void): this; | ||
once(event: "data", listener: (chunk: any) => void): this; | ||
once(event: "end", listener: () => void): this; | ||
once(event: "readable", listener: () => void): this; | ||
once(event: "error", listener: (err: Error) => void): this; | ||
on(event: 'close', listener: (had_error: boolean) => void): this; | ||
on(event: 'connect', listener: () => void): this; | ||
on(event: 'data', listener: (data: INodeBuffer) => void): this; | ||
on(event: 'end', listener: () => void): this; | ||
on(event: 'error', listener: (err: Error) => void): this; | ||
once(event: 'close', listener: () => void): this; | ||
once(event: 'data', listener: (chunk: any) => void): this; | ||
once(event: 'end', listener: () => void): this; | ||
once(event: 'readable', listener: () => void): this; | ||
once(event: 'error', listener: (err: Error) => void): this; | ||
once(event: string | symbol, listener: (...args: any[]) => void): this; | ||
prependListener(event: "close", listener: () => void): this; | ||
prependListener(event: "data", listener: (chunk: any) => void): this; | ||
prependListener(event: "end", listener: () => void): this; | ||
prependListener(event: "readable", listener: () => void): this; | ||
prependListener(event: "error", listener: (err: Error) => void): this; | ||
prependListener(event: 'close', listener: () => void): this; | ||
prependListener(event: 'data', listener: (chunk: any) => void): this; | ||
prependListener(event: 'end', listener: () => void): this; | ||
prependListener(event: 'readable', listener: () => void): this; | ||
prependListener(event: 'error', listener: (err: Error) => void): this; | ||
prependListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
prependOnceListener(event: "close", listener: () => void): this; | ||
prependOnceListener(event: "data", listener: (chunk: any) => void): this; | ||
prependOnceListener(event: "end", listener: () => void): this; | ||
prependOnceListener(event: "readable", listener: () => void): this; | ||
prependOnceListener(event: "error", listener: (err: Error) => void): this; | ||
prependOnceListener(event: 'close', listener: () => void): this; | ||
prependOnceListener(event: 'data', listener: (chunk: any) => void): this; | ||
prependOnceListener(event: 'end', listener: () => void): this; | ||
prependOnceListener(event: 'readable', listener: () => void): this; | ||
prependOnceListener(event: 'error', listener: (err: Error) => void): this; | ||
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
@@ -96,0 +96,0 @@ rawListeners(event: string | symbol): Function[]; |
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
import { INodeBuffer } from "./INodeBuffer"; | ||
import { INodeBuffer } from './INodeBuffer'; | ||
export interface ISocket { | ||
@@ -15,0 +15,0 @@ isConnected: boolean; |
@@ -9,4 +9,4 @@ /** | ||
/** | ||
* Abstraction for a generic transport definition. | ||
*/ | ||
* Abstraction for a generic transport definition. | ||
*/ | ||
export interface ITransport { | ||
@@ -13,0 +13,0 @@ isConnected: boolean; |
@@ -50,6 +50,6 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let outgoingPipeName = namedPipeTransport_1.NamedPipeTransport.PipePath + this._baseName + namedPipeTransport_1.NamedPipeTransport.ServerIncomingPath; | ||
let outgoing = net_1.connect(outgoingPipeName); | ||
let incomingPipeName = namedPipeTransport_1.NamedPipeTransport.PipePath + this._baseName + namedPipeTransport_1.NamedPipeTransport.ServerOutgoingPath; | ||
let incoming = net_1.connect(incomingPipeName); | ||
const outgoingPipeName = namedPipeTransport_1.NamedPipeTransport.PipePath + this._baseName + namedPipeTransport_1.NamedPipeTransport.ServerIncomingPath; | ||
const outgoing = net_1.connect(outgoingPipeName); | ||
const incomingPipeName = namedPipeTransport_1.NamedPipeTransport.PipePath + this._baseName + namedPipeTransport_1.NamedPipeTransport.ServerOutgoingPath; | ||
const incoming = net_1.connect(incomingPipeName); | ||
this._sender.connect(new namedPipeTransport_1.NamedPipeTransport(outgoing)); | ||
@@ -90,3 +90,5 @@ this._receiver.connect(new namedPipeTransport_1.NamedPipeTransport(incoming)); | ||
.then(() => { }) | ||
.catch((error) => { throw new Error(`Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. `); }); | ||
.catch((error) => { | ||
throw new Error(`Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. `); | ||
}); | ||
} | ||
@@ -93,0 +95,0 @@ } |
@@ -5,4 +5,4 @@ import { RequestHandler } from '../requestHandler'; | ||
/** | ||
* Streaming transport server implementation that uses named pipes for inter-process communication. | ||
*/ | ||
* Streaming transport server implementation that uses named pipes for inter-process communication. | ||
*/ | ||
export declare class NamedPipeServer implements IStreamingTransportServer { | ||
@@ -20,3 +20,3 @@ private _outgoingServer; | ||
/** | ||
* Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. | ||
* Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. | ||
* | ||
@@ -23,0 +23,0 @@ * @param baseName The named pipe to connect to. |
@@ -24,7 +24,7 @@ "use strict"; | ||
/** | ||
* Streaming transport server implementation that uses named pipes for inter-process communication. | ||
*/ | ||
* Streaming transport server implementation that uses named pipes for inter-process communication. | ||
*/ | ||
class NamedPipeServer { | ||
/** | ||
* Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. | ||
* Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. | ||
* | ||
@@ -65,3 +65,3 @@ * @param baseName The named pipe to connect to. | ||
} | ||
const incoming = new Promise(resolve => { | ||
const incoming = new Promise((resolve) => { | ||
this._incomingServer = createNodeServer_1.createNodeServer((socket) => { | ||
@@ -72,3 +72,3 @@ this._receiver.connect(new namedPipeTransport_1.NamedPipeTransport(socket)); | ||
}); | ||
const outgoing = new Promise(resolve => { | ||
const outgoing = new Promise((resolve) => { | ||
this._outgoingServer = createNodeServer_1.createNodeServer((socket) => { | ||
@@ -129,4 +129,5 @@ this._sender.connect(new namedPipeTransport_1.NamedPipeTransport(socket)); | ||
if (this._autoReconnect) { | ||
this.start() | ||
.catch((err) => { throw (new Error(`Unable to reconnect: ${err.message}`)); }); | ||
this.start().catch((err) => { | ||
throw new Error(`Unable to reconnect: ${err.message}`); | ||
}); | ||
} | ||
@@ -133,0 +134,0 @@ } |
@@ -64,3 +64,3 @@ "use strict"; | ||
this._activeReceiveCount = count; | ||
let promise = new Promise((resolve, reject) => { | ||
const promise = new Promise((resolve, reject) => { | ||
this._activeReceiveResolve = resolve; | ||
@@ -104,3 +104,3 @@ this._activeReceiveReject = reject; | ||
// can send the entire _active buffer | ||
let buffer = this._active; | ||
const buffer = this._active; | ||
this._active = null; | ||
@@ -111,4 +111,4 @@ this._activeReceiveResolve(buffer); | ||
// create a new buffer and copy some of the contents into it | ||
let available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
let buffer = Buffer.alloc(available); | ||
const available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
const buffer = Buffer.alloc(available); | ||
this._active.copy(buffer, 0, this._activeOffset, this._activeOffset + available); | ||
@@ -115,0 +115,0 @@ this._activeOffset += available; |
@@ -31,4 +31,4 @@ "use strict"; | ||
static deserialize(buffer) { | ||
let jsonBuffer = buffer.toString(this.Encoding); | ||
let headerArray = jsonBuffer.split(this.Delimiter); | ||
const jsonBuffer = buffer.toString(this.Encoding); | ||
const headerArray = jsonBuffer.split(this.Delimiter); | ||
if (headerArray.length !== 4) { | ||
@@ -41,3 +41,4 @@ throw Error(`Cannot parse header, header is malformed. Header: ${jsonBuffer}`); | ||
const header = { end, payloadLength, payloadType, id }; | ||
if (!(header.payloadLength <= payloadConstants_1.PayloadConstants.MaxPayloadLength && header.payloadLength >= payloadConstants_1.PayloadConstants.MinLength)) { | ||
if (!(header.payloadLength <= payloadConstants_1.PayloadConstants.MaxPayloadLength && | ||
header.payloadLength >= payloadConstants_1.PayloadConstants.MinLength)) { | ||
throw Error(`Header length of ${header.payloadLength} is missing or malformed`); | ||
@@ -48,3 +49,5 @@ } | ||
} | ||
if (!header.id || !header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) || header.id.length !== this.IdLength) { | ||
if (!header.id || | ||
!header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) || | ||
header.id.length !== this.IdLength) { | ||
throw Error(`Header ID '${header.id}' is missing or malformed.`); | ||
@@ -58,5 +61,4 @@ } | ||
static headerLengthPadder(lengthValue, totalLength, padChar) { | ||
let result = Array(totalLength + 1) | ||
.join(padChar); | ||
let lengthString = lengthValue.toString(); | ||
const result = Array(totalLength + 1).join(padChar); | ||
const lengthString = lengthValue.toString(); | ||
return (result + lengthString).slice(lengthString.length); | ||
@@ -63,0 +65,0 @@ } |
@@ -20,3 +20,3 @@ "use strict"; | ||
else if (!this.activeAssemblers[header.id]) { | ||
let assembler = this.createPayloadAssembler(header); | ||
const assembler = this.createPayloadAssembler(header); | ||
if (assembler) { | ||
@@ -34,3 +34,3 @@ this.activeAssemblers[header.id] = assembler; | ||
if (this.activeAssemblers && this.activeAssemblers[header.id]) { | ||
let assembler = this.activeAssemblers[header.id]; | ||
const assembler = this.activeAssemblers[header.id]; | ||
assembler.onReceive(header, contentStream, contentLength); | ||
@@ -37,0 +37,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let pendingRequest = this._pendingRequests[requestId]; | ||
const pendingRequest = this._pendingRequests[requestId]; | ||
if (pendingRequest) { | ||
@@ -45,3 +45,3 @@ pendingRequest.resolve(response); | ||
pendingRequest.requestId = requestId; | ||
let promise = new Promise((resolve, reject) => { | ||
const promise = new Promise((resolve, reject) => { | ||
pendingRequest.resolve = resolve; | ||
@@ -48,0 +48,0 @@ pendingRequest.reject = reject; |
@@ -25,3 +25,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let disassembler = new requestDisassembler_1.RequestDisassembler(this.payloadSender, id, request); | ||
const disassembler = new requestDisassembler_1.RequestDisassembler(this.payloadSender, id, request); | ||
yield disassembler.disassemble(); | ||
@@ -37,3 +37,3 @@ if (request.streams) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let disassembler = new responseDisassembler_1.ResponseDisassembler(this.payloadSender, id, response); | ||
const disassembler = new responseDisassembler_1.ResponseDisassembler(this.payloadSender, id, response); | ||
yield disassembler.disassemble(); | ||
@@ -49,3 +49,3 @@ if (response.streams) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let disassembler = new cancelDisassembler_1.CancelDisassembler(this.payloadSender, id, payloadTypes_1.PayloadTypes.cancelStream); | ||
const disassembler = new cancelDisassembler_1.CancelDisassembler(this.payloadSender, id, payloadTypes_1.PayloadTypes.cancelStream); | ||
disassembler.disassemble(); | ||
@@ -52,0 +52,0 @@ }); |
@@ -15,3 +15,3 @@ "use strict"; | ||
// A new id has come in, kick off the process of tracking it. | ||
let assembler = new payloadAssembler_1.PayloadAssembler(this, { id: id }); | ||
const assembler = new payloadAssembler_1.PayloadAssembler(this, { id: id }); | ||
this.activeAssemblers[id] = assembler; | ||
@@ -25,3 +25,3 @@ return assembler; | ||
getPayloadStream(header) { | ||
let assembler = this.getPayloadAssembler(header.id); | ||
const assembler = this.getPayloadAssembler(header.id); | ||
return assembler.getPayloadStream(); | ||
@@ -40,5 +40,5 @@ } | ||
else { | ||
let assembler = this.activeAssemblers[id]; | ||
const assembler = this.activeAssemblers[id]; | ||
this.activeAssemblers.splice(this.activeAssemblers.indexOf(id), 1); | ||
let targetStream = assembler.getPayloadStream(); | ||
const targetStream = assembler.getPayloadStream(); | ||
if ((assembler.contentLength && targetStream.length < assembler.contentLength) || !assembler.end) { | ||
@@ -45,0 +45,0 @@ this.onCancelStream(assembler); |
@@ -72,4 +72,3 @@ "use strict"; | ||
runReceive() { | ||
this.receivePackets() | ||
.catch(); | ||
this.receivePackets().catch(); | ||
} | ||
@@ -88,9 +87,10 @@ receivePackets() { | ||
} | ||
let header = headerSerializer_1.HeaderSerializer.deserialize(this._receiveHeaderBuffer); | ||
let isStream = header.payloadType === payloadTypes_1.PayloadTypes.stream; | ||
const header = headerSerializer_1.HeaderSerializer.deserialize(this._receiveHeaderBuffer); | ||
const isStream = header.payloadType === payloadTypes_1.PayloadTypes.stream; | ||
if (header.payloadLength > 0) { | ||
let bytesActuallyRead = 0; | ||
let contentStream = this._getStream(header); | ||
while (bytesActuallyRead < header.payloadLength && bytesActuallyRead < payloadConstants_1.PayloadConstants.MaxPayloadLength) { | ||
let count = Math.min(header.payloadLength - bytesActuallyRead, payloadConstants_1.PayloadConstants.MaxPayloadLength); | ||
const contentStream = this._getStream(header); | ||
while (bytesActuallyRead < header.payloadLength && | ||
bytesActuallyRead < payloadConstants_1.PayloadConstants.MaxPayloadLength) { | ||
const count = Math.min(header.payloadLength - bytesActuallyRead, payloadConstants_1.PayloadConstants.MaxPayloadLength); | ||
this._receivePayloadBuffer = yield this._receiver.receive(count); | ||
@@ -97,0 +97,0 @@ bytesActuallyRead += this._receivePayloadBuffer.byteLength; |
@@ -41,3 +41,3 @@ "use strict"; | ||
sendPayload(header, payload, sentCallback) { | ||
var packet = { header, payload, sentCallback }; | ||
const packet = { header, payload, sentCallback }; | ||
this.writePacket(packet); | ||
@@ -64,8 +64,8 @@ } | ||
while (leftOver > 0) { | ||
let count = leftOver <= payloadConstants_1.PayloadConstants.MaxPayloadLength ? leftOver : payloadConstants_1.PayloadConstants.MaxPayloadLength; | ||
let chunk = packet.payload.read(count); | ||
var header = packet.header; | ||
const count = leftOver <= payloadConstants_1.PayloadConstants.MaxPayloadLength ? leftOver : payloadConstants_1.PayloadConstants.MaxPayloadLength; | ||
const chunk = packet.payload.read(count); | ||
const header = packet.header; | ||
header.payloadLength = count; | ||
header.end = leftOver <= payloadConstants_1.PayloadConstants.MaxPayloadLength; | ||
let sendHeaderBuffer = Buffer.alloc(payloadConstants_1.PayloadConstants.MaxHeaderLength); | ||
const sendHeaderBuffer = Buffer.alloc(payloadConstants_1.PayloadConstants.MaxHeaderLength); | ||
headerSerializer_1.HeaderSerializer.serialize(header, sendHeaderBuffer); | ||
@@ -72,0 +72,0 @@ this.sender.send(sendHeaderBuffer); |
@@ -40,3 +40,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let requestId = protocol_base_1.generateGuid(); | ||
const requestId = protocol_base_1.generateGuid(); | ||
yield this.sendOperations.sendRequest(requestId, request); | ||
@@ -54,3 +54,3 @@ return this.requestManager.getResponse(requestId); | ||
if (this.requestHandler) { | ||
let response = yield this.requestHandler.processRequest(request); | ||
const response = yield this.requestHandler.processRequest(request); | ||
if (response) { | ||
@@ -80,4 +80,3 @@ yield this.sendOperations.sendResponse(id, response); | ||
onCancelStream(contentStreamAssembler) { | ||
this.sendOperations.sendCancelStream(contentStreamAssembler.id) | ||
.catch(); | ||
this.sendOperations.sendCancelStream(contentStreamAssembler.id).catch(); | ||
} | ||
@@ -84,0 +83,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
static create(method, path, body) { | ||
let request = new StreamingRequest(); | ||
const request = new StreamingRequest(); | ||
request.verb = method; | ||
@@ -55,7 +55,7 @@ request.path = path; | ||
if (typeof body === 'string') { | ||
let stream = new subscribableStream_1.SubscribableStream(); | ||
const stream = new subscribableStream_1.SubscribableStream(); | ||
stream.write(body, 'utf8'); | ||
this.addStream(new httpContentStream_1.HttpContent({ | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length | ||
contentLength: stream.length, | ||
}, stream)); | ||
@@ -62,0 +62,0 @@ } |
@@ -24,3 +24,3 @@ "use strict"; | ||
static create(statusCode, body) { | ||
let response = new StreamingResponse(); | ||
const response = new StreamingResponse(); | ||
response.statusCode = statusCode; | ||
@@ -46,7 +46,7 @@ if (body) { | ||
setBody(body) { | ||
let stream = new subscribableStream_1.SubscribableStream(); | ||
const stream = new subscribableStream_1.SubscribableStream(); | ||
stream.write(JSON.stringify(body), 'utf8'); | ||
this.addStream(new httpContentStream_1.HttpContent({ | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length | ||
contentLength: stream.length, | ||
}, stream)); | ||
@@ -53,0 +53,0 @@ } |
@@ -18,3 +18,3 @@ "use strict"; | ||
_write(chunk, encoding, callback) { | ||
let buffer = Buffer.from(chunk); | ||
const buffer = Buffer.from(chunk); | ||
this.bufferList.push(buffer); | ||
@@ -35,3 +35,3 @@ this.length += chunk.length; | ||
while (total < size && this.bufferList.length > 0) { | ||
let buffer = this.bufferList[0]; | ||
const buffer = this.bufferList[0]; | ||
this.push(buffer); | ||
@@ -38,0 +38,0 @@ this.bufferList.splice(0, 1); |
@@ -31,10 +31,10 @@ "use strict"; | ||
function isNetServer(o) { | ||
return (hasCloseMethod && hasListenMethod) ? true : false; | ||
return hasCloseMethod && hasListenMethod ? true : false; | ||
} | ||
function hasCloseMethod(o) { | ||
return (o.close && typeof o.close === 'function') ? true : false; | ||
return o.close && typeof o.close === 'function' ? true : false; | ||
} | ||
function hasListenMethod(o) { | ||
return (o.listen && typeof o.listen === 'function') ? true : false; | ||
return o.listen && typeof o.listen === 'function' ? true : false; | ||
} | ||
//# sourceMappingURL=createNodeServer.js.map |
@@ -84,4 +84,4 @@ "use strict"; | ||
'Sec-WebSocket-Key': wskey, | ||
'Sec-WebSocket-Version': '13' | ||
} | ||
'Sec-WebSocket-Version': '13', | ||
}, | ||
}; | ||
@@ -130,5 +130,7 @@ const req = http_1.request(options); | ||
setOnErrorHandler(handler) { | ||
this.wsSocket.on('error', (error) => { if (error) { | ||
handler(error); | ||
} }); | ||
this.wsSocket.on('error', (error) => { | ||
if (error) { | ||
handler(error); | ||
} | ||
}); | ||
} | ||
@@ -135,0 +137,0 @@ } |
@@ -45,3 +45,5 @@ "use strict"; | ||
this._protocolAdapter = new protocolAdapter_1.ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._closedSignal = (x) => { return x; }; | ||
this._closedSignal = (x) => { | ||
return x; | ||
}; | ||
} | ||
@@ -48,0 +50,0 @@ /** |
@@ -73,3 +73,3 @@ "use strict"; | ||
this._activeReceiveCount = count; | ||
let promise = new Promise((resolve, reject) => { | ||
const promise = new Promise((resolve, reject) => { | ||
this._activeReceiveResolve = resolve; | ||
@@ -119,3 +119,3 @@ this._activeReceiveReject = reject; | ||
// can send the entire _active buffer | ||
let buffer = this._active; | ||
const buffer = this._active; | ||
this._active = null; | ||
@@ -126,4 +126,4 @@ this._activeReceiveResolve(buffer); | ||
// create a Buffer.from and copy some of the contents into it | ||
let available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
let buffer = Buffer.alloc(available); | ||
const available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
const buffer = Buffer.alloc(available); | ||
this._active.copy(buffer, 0, this._activeOffset, this._activeOffset + available); | ||
@@ -130,0 +130,0 @@ this._activeOffset += available; |
@@ -5,3 +5,3 @@ { | ||
"description": "Streaming library for the Microsoft Bot Framework", | ||
"version": "4.11.0-dev.20200929.ca9de94", | ||
"version": "4.11.0-dev.20201019.3446d04", | ||
"license": "MIT", | ||
@@ -35,7 +35,3 @@ "keywords": [ | ||
"@types/node": "^10.17.27", | ||
"@typescript-eslint/eslint-plugin": "^3.9.1", | ||
"@typescript-eslint/parser": "^3.9.1", | ||
"chai": "^4.2.0", | ||
"eslint": "^7.7.0", | ||
"eslint-plugin-only-warn": "^1.0.2", | ||
"mocha": "^6.2.3", | ||
@@ -51,5 +47,3 @@ "nyc": "^15.1.0", | ||
"clean": "rmdir /q /s lib browser", | ||
"eslint": "eslint ./src/*.ts ./src/**/*.ts", | ||
"eslint-fix": "eslint ./src/*.ts ./src/**/*.ts --fix", | ||
"set-version": "npm version --allow-same-version 4.11.0-dev.20200929.ca9de94", | ||
"set-version": "npm version --allow-same-version 4.11.0-dev.20201019.3446d04", | ||
"test": "npm run build && nyc mocha tests/", | ||
@@ -59,6 +53,6 @@ "test:compat": "api-extractor run --verbose" | ||
"files": [ | ||
"/lib", | ||
"/src", | ||
"/browser" | ||
"lib", | ||
"src", | ||
"browser" | ||
] | ||
} |
@@ -28,7 +28,7 @@ /** | ||
private readonly _streamManager: StreamManager; | ||
private readonly _byteOrderMark = 0xFEFF; | ||
private readonly _byteOrderMark = 0xfeff; | ||
private readonly _utf: string = 'utf8'; | ||
public constructor(streamManager: StreamManager, params: IAssemblerParams) { | ||
if(params.header){ | ||
if (params.header) { | ||
this.id = params.header.id; | ||
@@ -42,3 +42,3 @@ this.payloadType = params.header.payloadType; | ||
if(!this.id){ | ||
if (!this.id) { | ||
throw Error('An ID must be supplied when creating an assembler.'); | ||
@@ -63,5 +63,3 @@ } | ||
if (header.payloadType === PayloadTypes.response || header.payloadType === PayloadTypes.request) { | ||
this.process(stream) | ||
.then() | ||
.catch(); | ||
this.process(stream).then().catch(); | ||
} else if (header.end) { | ||
@@ -81,11 +79,11 @@ stream.end(); | ||
private payloadFromJson<T>(json: string): T { | ||
return JSON.parse((json.charCodeAt(0) === this._byteOrderMark) ? json.slice(1) : json) as T; | ||
return JSON.parse(json.charCodeAt(0) === this._byteOrderMark ? json.slice(1) : json) as T; | ||
} | ||
private stripBOM(input: string): string { | ||
return (input.charCodeAt(0) === this._byteOrderMark) ? input.slice(1) : input; | ||
return input.charCodeAt(0) === this._byteOrderMark ? input.slice(1) : input; | ||
} | ||
private async process(stream: SubscribableStream): Promise<void> { | ||
let streamData: Buffer = stream.read(stream.length) as Buffer; | ||
const streamData: Buffer = stream.read(stream.length) as Buffer; | ||
if (!streamData) { | ||
@@ -95,7 +93,7 @@ return; | ||
let streamDataAsString = streamData.toString(this._utf); | ||
const streamDataAsString = streamData.toString(this._utf); | ||
if(this.payloadType === PayloadTypes.request){ | ||
if (this.payloadType === PayloadTypes.request) { | ||
await this.processRequest(streamDataAsString); | ||
} else if(this.payloadType === PayloadTypes.response){ | ||
} else if (this.payloadType === PayloadTypes.response) { | ||
await this.processResponse(streamDataAsString); | ||
@@ -106,6 +104,5 @@ } | ||
private async processResponse(streamDataAsString: string): Promise<void> { | ||
const responsePayload: IResponsePayload = this.payloadFromJson(this.stripBOM(streamDataAsString)); | ||
const receiveResponse: IReceiveResponse = { streams: [], statusCode: responsePayload.statusCode }; | ||
let responsePayload: IResponsePayload = this.payloadFromJson(this.stripBOM(streamDataAsString)); | ||
let receiveResponse: IReceiveResponse = { streams: [], statusCode: responsePayload.statusCode }; | ||
await this.processStreams(responsePayload, receiveResponse); | ||
@@ -115,6 +112,5 @@ } | ||
private async processRequest(streamDataAsString: string): Promise<void> { | ||
const requestPayload: IRequestPayload = this.payloadFromJson(streamDataAsString); | ||
const receiveRequest: IReceiveRequest = { streams: [], path: requestPayload.path, verb: requestPayload.verb }; | ||
let requestPayload: IRequestPayload = this.payloadFromJson(streamDataAsString); | ||
let receiveRequest: IReceiveRequest = { streams: [], path: requestPayload.path, verb: requestPayload.verb }; | ||
await this.processStreams(requestPayload, receiveRequest); | ||
@@ -126,3 +122,3 @@ } | ||
responsePayload.streams.forEach((responseStream): void => { | ||
let contentAssembler: PayloadAssembler = this._streamManager.getPayloadAssembler(responseStream.id); | ||
const contentAssembler: PayloadAssembler = this._streamManager.getPayloadAssembler(responseStream.id); | ||
contentAssembler.payloadType = responseStream.contentType; | ||
@@ -129,0 +125,0 @@ contentAssembler.contentLength = responseStream.length; |
@@ -47,7 +47,7 @@ /** | ||
const { bufferArray } = await this.readAll(); | ||
return (bufferArray || []).map(result => result.toString('utf8')).join(''); | ||
return (bufferArray || []).map((result) => result.toString('utf8')).join(''); | ||
} | ||
public async readAsJson<T>(): Promise<T> { | ||
let stringToParse = await this.readAsString(); | ||
const stringToParse = await this.readAsString(); | ||
try { | ||
@@ -61,10 +61,10 @@ return <T>JSON.parse(stringToParse); | ||
private async readAll(): Promise<Record<string, any>> { | ||
// do a read-all | ||
let allData: INodeBuffer[] = []; | ||
// do a read-all | ||
const allData: INodeBuffer[] = []; | ||
let count = 0; | ||
let stream = this.getStream(); | ||
const stream = this.getStream(); | ||
// populate the array with any existing buffers | ||
while (count < stream.length) { | ||
let chunk = stream.read(stream.length); | ||
const chunk = stream.read(stream.length); | ||
allData.push(chunk); | ||
@@ -75,4 +75,4 @@ count += (chunk as INodeBuffer).length; | ||
if (count < this.length) { | ||
let readToEnd = new Promise<boolean>((resolve): void => { | ||
let callback = (cs: ContentStream) => (chunk: any): void => { | ||
const readToEnd = new Promise<boolean>((resolve): void => { | ||
const callback = (cs: ContentStream) => (chunk: any): void => { | ||
allData.push(chunk); | ||
@@ -91,5 +91,4 @@ count += (chunk as INodeBuffer).length; | ||
return {bufferArray: allData, size: count}; | ||
return { bufferArray: allData, size: count }; | ||
} | ||
} |
@@ -24,5 +24,5 @@ /** | ||
public disassemble(): void { | ||
const header: IHeader = {payloadType: this.payloadType, payloadLength: 0, id: this.id, end: true}; | ||
const header: IHeader = { payloadType: this.payloadType, payloadLength: 0, id: this.id, end: true }; | ||
this.sender.sendPayload(header); | ||
} | ||
} |
@@ -28,6 +28,6 @@ /** | ||
public async getStream(): Promise<IStreamWrapper> { | ||
let stream: SubscribableStream = this.contentStream.content.getStream(); | ||
const stream: SubscribableStream = this.contentStream.content.getStream(); | ||
return {stream, streamLength: stream.length}; | ||
return { stream, streamLength: stream.length }; | ||
} | ||
} |
@@ -30,3 +30,3 @@ /** | ||
protected static serialize<T>(item: T): IStreamWrapper { | ||
let stream: SubscribableStream = new SubscribableStream(); | ||
const stream: SubscribableStream = new SubscribableStream(); | ||
@@ -36,3 +36,3 @@ stream.write(JSON.stringify(item)); | ||
return {stream, streamLength: stream.length}; | ||
return { stream, streamLength: stream.length }; | ||
} | ||
@@ -43,3 +43,3 @@ | ||
public async disassemble(): Promise<void> { | ||
let { stream, streamLength }: IStreamWrapper = await this.getStream(); | ||
const { stream, streamLength }: IStreamWrapper = await this.getStream(); | ||
@@ -53,5 +53,10 @@ this.stream = stream; | ||
private async send(): Promise<void> { | ||
let header: IHeader = {payloadType: this.payloadType, payloadLength: this.streamLength, id: this.id, end: true}; | ||
const header: IHeader = { | ||
payloadType: this.payloadType, | ||
payloadLength: this.streamLength, | ||
id: this.id, | ||
end: true, | ||
}; | ||
this.sender.sendPayload(header, this.stream); | ||
} | ||
} |
@@ -28,5 +28,5 @@ /** | ||
public async getStream(): Promise<IStreamWrapper> { | ||
let payload: IRequestPayload = {verb: this.request.verb, path: this.request.path, streams: []}; | ||
const payload: IRequestPayload = { verb: this.request.verb, path: this.request.path, streams: [] }; | ||
if (this.request.streams) { | ||
this.request.streams.forEach(function(stream){ | ||
this.request.streams.forEach(function (stream) { | ||
payload.streams.push(stream.description); | ||
@@ -33,0 +33,0 @@ }); |
@@ -28,5 +28,5 @@ /** | ||
public async getStream(): Promise<IStreamWrapper> { | ||
let payload: IResponsePayload = {statusCode: this.response.statusCode, streams: []}; | ||
const payload: IResponsePayload = { statusCode: this.response.statusCode, streams: [] }; | ||
if (this.response.streams) { | ||
this.response.streams.forEach(function(stream){ | ||
this.response.streams.forEach(function (stream) { | ||
payload.streams.push(stream.description); | ||
@@ -33,0 +33,0 @@ }); |
@@ -15,3 +15,3 @@ /** | ||
public readonly content: HttpContent; | ||
public description: { id: string; type: string; length: number; }; | ||
public description: { id: string; type: string; length: number }; | ||
@@ -21,3 +21,7 @@ public constructor(content: HttpContent) { | ||
this.content = content; | ||
this.description = {id: this.id, type: (this.content.headers) ? this.content.headers.type : 'unknown', length: (this.content.headers) ? this.content.headers.contentLength : 0}; | ||
this.description = { | ||
id: this.id, | ||
type: this.content.headers ? this.content.headers.type : 'unknown', | ||
length: this.content.headers ? this.content.headers.contentLength : 0, | ||
}; | ||
} | ||
@@ -24,0 +28,0 @@ } |
@@ -25,5 +25,2 @@ /** | ||
export { SubscribableStream } from './subscribableStream'; | ||
export { | ||
BrowserWebSocket, | ||
WebSocketClient | ||
} from './webSocket/index-browser'; | ||
export { BrowserWebSocket, WebSocketClient } from './webSocket/index-browser'; |
@@ -31,3 +31,3 @@ /** | ||
WebSocketClient, | ||
WebSocketServer | ||
WebSocketServer, | ||
} from './webSocket'; |
@@ -12,3 +12,3 @@ /** | ||
* For more information, see https://w3c.github.io/FileAPI/#APIASynch. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -15,0 +15,0 @@ */ |
@@ -12,3 +12,3 @@ /** | ||
* For more information, see https://html.spec.whatwg.org/multipage/web-sockets.html. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -15,0 +15,0 @@ */ |
@@ -11,3 +11,3 @@ /** | ||
* Represents a EventEmitter from the `net` module in Node.js. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -32,2 +32,2 @@ */ | ||
eventNames(): Array<string | symbol>; | ||
} | ||
} |
@@ -9,3 +9,3 @@ /** | ||
/** | ||
/** | ||
* Streaming payload header definition. | ||
@@ -12,0 +12,0 @@ */ |
@@ -15,2 +15,2 @@ /** | ||
contentLength?: number; | ||
} | ||
} |
@@ -11,7 +11,17 @@ /** | ||
export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; | ||
export type BufferEncoding = | ||
| 'ascii' | ||
| 'utf8' | ||
| 'utf-8' | ||
| 'utf16le' | ||
| 'ucs2' | ||
| 'ucs-2' | ||
| 'base64' | ||
| 'latin1' | ||
| 'binary' | ||
| 'hex'; | ||
/** | ||
* Represents a Buffer from the `net` module in Node.js. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -23,5 +33,11 @@ */ | ||
toString(encoding?: string, start?: number, end?: number): string; | ||
toJSON(): { type: 'Buffer', data: any[] }; | ||
toJSON(): { type: 'Buffer'; data: any[] }; | ||
equals(otherBuffer: Uint8Array): boolean; | ||
compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number; | ||
compare( | ||
otherBuffer: Uint8Array, | ||
targetStart?: number, | ||
targetEnd?: number, | ||
sourceStart?: number, | ||
sourceEnd?: number | ||
): number; | ||
copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; | ||
@@ -60,3 +76,3 @@ slice(start?: number, end?: number): this; | ||
swap64(): this; | ||
writeUInt8(value: number, offset: number, noAssert?: boolean): number; | ||
@@ -87,2 +103,2 @@ writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; | ||
values(): IterableIterator<number>; | ||
} | ||
} |
@@ -11,3 +11,3 @@ /** | ||
* Represents a IncomingMessage from the `http` module in Node.js. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -14,0 +14,0 @@ */ |
@@ -13,3 +13,3 @@ /** | ||
* Represents a Server from the `net` module in Node.js. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -16,0 +16,0 @@ */ |
@@ -14,3 +14,3 @@ /** | ||
* Represents a Socket from the `net` module in Node.js. | ||
* | ||
* | ||
* This interface supports the framework and is not intended to be called directly for your code. | ||
@@ -44,6 +44,6 @@ */ | ||
end(cb?: () => void): void; | ||
end(chunk: any, cb?: () => void): void; | ||
end(cb?: () => void): void; | ||
end(chunk: any, cb?: () => void): void; | ||
end(chunk: any, encoding?: string, cb?: () => void): void; | ||
_destroy(error: Error | null, callback: (error: Error | null) => void): void; | ||
@@ -60,16 +60,16 @@ destroy(error?: Error): void; | ||
pipe<T extends WritableStream>(destination: T, options?: { end?: boolean; }): T; | ||
pipe<T extends WritableStream>(destination: T, options?: { end?: boolean }): T; | ||
addListener(event: "close", listener: () => void): this; | ||
addListener(event: "data", listener: (chunk: any) => void): this; | ||
addListener(event: "end", listener: () => void): this; | ||
addListener(event: "readable", listener: () => void): this; | ||
addListener(event: "error", listener: (err: Error) => void): this; | ||
addListener(event: 'close', listener: () => void): this; | ||
addListener(event: 'data', listener: (chunk: any) => void): this; | ||
addListener(event: 'end', listener: () => void): this; | ||
addListener(event: 'readable', listener: () => void): this; | ||
addListener(event: 'error', listener: (err: Error) => void): this; | ||
addListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
emit(event: "close"): boolean; | ||
emit(event: "data", chunk: any): boolean; | ||
emit(event: "end"): boolean; | ||
emit(event: "readable"): boolean; | ||
emit(event: "error", err: Error): boolean; | ||
emit(event: 'close'): boolean; | ||
emit(event: 'data', chunk: any): boolean; | ||
emit(event: 'end'): boolean; | ||
emit(event: 'readable'): boolean; | ||
emit(event: 'error', err: Error): boolean; | ||
emit(event: string | symbol, ...args: any[]): boolean; | ||
@@ -83,29 +83,29 @@ | ||
off(event: string | symbol, listener: (...args: any[]) => void): this; | ||
on(event: string, listener: (...args: any[]) => void): this; | ||
on(event: "close", listener: (had_error: boolean) => void): this; | ||
on(event: "connect", listener: () => void): this; | ||
on(event: "data", listener: (data: INodeBuffer) => void): this; | ||
on(event: "end", listener: () => void): this; | ||
on(event: "error", listener: (err: Error) => void): this; | ||
on(event: 'close', listener: (had_error: boolean) => void): this; | ||
on(event: 'connect', listener: () => void): this; | ||
on(event: 'data', listener: (data: INodeBuffer) => void): this; | ||
on(event: 'end', listener: () => void): this; | ||
on(event: 'error', listener: (err: Error) => void): this; | ||
once(event: "close", listener: () => void): this; | ||
once(event: "data", listener: (chunk: any) => void): this; | ||
once(event: "end", listener: () => void): this; | ||
once(event: "readable", listener: () => void): this; | ||
once(event: "error", listener: (err: Error) => void): this; | ||
once(event: 'close', listener: () => void): this; | ||
once(event: 'data', listener: (chunk: any) => void): this; | ||
once(event: 'end', listener: () => void): this; | ||
once(event: 'readable', listener: () => void): this; | ||
once(event: 'error', listener: (err: Error) => void): this; | ||
once(event: string | symbol, listener: (...args: any[]) => void): this; | ||
prependListener(event: "close", listener: () => void): this; | ||
prependListener(event: "data", listener: (chunk: any) => void): this; | ||
prependListener(event: "end", listener: () => void): this; | ||
prependListener(event: "readable", listener: () => void): this; | ||
prependListener(event: "error", listener: (err: Error) => void): this; | ||
prependListener(event: 'close', listener: () => void): this; | ||
prependListener(event: 'data', listener: (chunk: any) => void): this; | ||
prependListener(event: 'end', listener: () => void): this; | ||
prependListener(event: 'readable', listener: () => void): this; | ||
prependListener(event: 'error', listener: (err: Error) => void): this; | ||
prependListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
prependOnceListener(event: "close", listener: () => void): this; | ||
prependOnceListener(event: "data", listener: (chunk: any) => void): this; | ||
prependOnceListener(event: "end", listener: () => void): this; | ||
prependOnceListener(event: "readable", listener: () => void): this; | ||
prependOnceListener(event: "error", listener: (err: Error) => void): this; | ||
prependOnceListener(event: 'close', listener: () => void): this; | ||
prependOnceListener(event: 'data', listener: (chunk: any) => void): this; | ||
prependOnceListener(event: 'end', listener: () => void): this; | ||
prependOnceListener(event: 'readable', listener: () => void): this; | ||
prependOnceListener(event: 'error', listener: (err: Error) => void): this; | ||
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
@@ -119,3 +119,3 @@ | ||
[Symbol.asyncIterator](): AsyncIterableIterator<any>; | ||
_read(size: number): void; | ||
@@ -131,12 +131,12 @@ read(size?: number): any; | ||
setNoDelay(noDelay?: boolean): this; | ||
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void; | ||
_writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void; | ||
_writev?(chunks: Array<{ chunk: any; encoding: string }>, callback: (error?: Error | null) => void): void; | ||
write(buffer: ValidBuffer, cb?: (err?: Error) => void): boolean; | ||
write(str: string, encoding?: string, cb?: Function): boolean; | ||
write(buffer: ValidBuffer): boolean; | ||
write(str: string, cb?: Function): boolean; | ||
write(str: string, encoding?: string, fd?: string): boolean; | ||
write(data: any, encoding?: string, callback?: Function): void; | ||
write(buffer: ValidBuffer, cb?: (err?: Error) => void): boolean; | ||
write(str: string, encoding?: string, cb?: Function): boolean; | ||
write(buffer: ValidBuffer): boolean; | ||
write(str: string, cb?: Function): boolean; | ||
write(str: string, encoding?: string, fd?: string): boolean; | ||
write(data: any, encoding?: string, callback?: Function): void; | ||
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean; | ||
@@ -163,2 +163,2 @@ write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean; | ||
end(str: string, encoding?: string, cb?: Function): void; | ||
} | ||
} |
@@ -14,3 +14,3 @@ /** | ||
import { INodeBuffer } from "./INodeBuffer"; | ||
import { INodeBuffer } from './INodeBuffer'; | ||
@@ -17,0 +17,0 @@ export interface ISocket { |
@@ -12,3 +12,3 @@ /** | ||
/** | ||
* Abstraction to define the characteristics of a streaming transport client. | ||
* Abstraction to define the characteristics of a streaming transport client. | ||
* Example possible implementations include WebSocket transport client or NamedPipe transport client. | ||
@@ -15,0 +15,0 @@ */ |
@@ -12,3 +12,3 @@ /** | ||
/** | ||
* Abstraction to define the characteristics of a streaming transport server. | ||
* Abstraction to define the characteristics of a streaming transport server. | ||
* Example possible implementations include WebSocket transport server or NamedPipe transport server. | ||
@@ -15,0 +15,0 @@ */ |
@@ -9,3 +9,3 @@ /** | ||
/** | ||
/** | ||
* Abstraction for a generic transport definition. | ||
@@ -12,0 +12,0 @@ */ |
@@ -13,6 +13,3 @@ /** | ||
import { RequestManager } from '../payloads'; | ||
import { | ||
PayloadReceiver, | ||
PayloadSender | ||
} from '../payloadTransport'; | ||
import { PayloadReceiver, PayloadSender } from '../payloadTransport'; | ||
import { NamedPipeTransport } from './namedPipeTransport'; | ||
@@ -33,3 +30,3 @@ import { IStreamingTransportClient, IReceiveResponse } from '../interfaces'; | ||
private _isDisconnecting: boolean; | ||
/** | ||
@@ -42,3 +39,3 @@ * Creates a new instance of the [NamedPipeClient](xref:botframework-streaming.NamedPipeClient) class. | ||
*/ | ||
public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect: boolean = true) { | ||
public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect = true) { | ||
this._baseName = baseName; | ||
@@ -52,3 +49,8 @@ this._requestHandler = requestHandler; | ||
this._receiver.disconnected = this.onConnectionDisconnected.bind(this); | ||
this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._protocolAdapter = new ProtocolAdapter( | ||
this._requestHandler, | ||
this._requestManager, | ||
this._sender, | ||
this._receiver | ||
); | ||
} | ||
@@ -60,6 +62,8 @@ | ||
public async connect(): Promise<void> { | ||
let outgoingPipeName: string = NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerIncomingPath; | ||
let outgoing = connect(outgoingPipeName); | ||
let incomingPipeName: string = NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerOutgoingPath; | ||
let incoming = connect(incomingPipeName); | ||
const outgoingPipeName: string = | ||
NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerIncomingPath; | ||
const outgoing = connect(outgoingPipeName); | ||
const incomingPipeName: string = | ||
NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerOutgoingPath; | ||
const incoming = connect(incomingPipeName); | ||
this._sender.connect(new NamedPipeTransport(outgoing)); | ||
@@ -101,7 +105,10 @@ this._receiver.connect(new NamedPipeTransport(incoming)); | ||
this.connect() | ||
.then((): void => { }) | ||
.catch((error): void => { throw new Error(`Failed to reconnect. Reason: ${ error.message } Sender: ${ sender } Args: ${ args }. `); }); | ||
.then((): void => {}) | ||
.catch((error): void => { | ||
throw new Error( | ||
`Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. ` | ||
); | ||
}); | ||
} | ||
} | ||
finally { | ||
} finally { | ||
this._isDisconnecting = false; | ||
@@ -108,0 +115,0 @@ } |
@@ -12,6 +12,3 @@ /** | ||
import { RequestManager } from '../payloads'; | ||
import { | ||
PayloadReceiver, | ||
PayloadSender | ||
} from '../payloadTransport'; | ||
import { PayloadReceiver, PayloadSender } from '../payloadTransport'; | ||
import { NamedPipeTransport } from './namedPipeTransport'; | ||
@@ -22,4 +19,4 @@ import { INodeServer, INodeSocket, IStreamingTransportServer, IReceiveResponse } from '../interfaces'; | ||
/** | ||
* Streaming transport server implementation that uses named pipes for inter-process communication. | ||
*/ | ||
* Streaming transport server implementation that uses named pipes for inter-process communication. | ||
*/ | ||
export class NamedPipeServer implements IStreamingTransportServer { | ||
@@ -38,3 +35,3 @@ private _outgoingServer: INodeServer; | ||
/** | ||
* Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. | ||
* Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. | ||
* | ||
@@ -45,3 +42,3 @@ * @param baseName The named pipe to connect to. | ||
*/ | ||
public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect: boolean = true) { | ||
public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect = true) { | ||
if (!baseName) { | ||
@@ -57,3 +54,8 @@ throw new TypeError('NamedPipeServer: Missing baseName parameter'); | ||
this._receiver = new PayloadReceiver(); | ||
this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._protocolAdapter = new ProtocolAdapter( | ||
this._requestHandler, | ||
this._requestManager, | ||
this._sender, | ||
this._receiver | ||
); | ||
this._sender.disconnected = this.onConnectionDisconnected.bind(this); | ||
@@ -80,11 +82,10 @@ this._receiver.disconnected = this.onConnectionDisconnected.bind(this); | ||
const incoming = new Promise(resolve => { | ||
this._incomingServer = createNodeServer((socket: INodeSocket): void => { | ||
this._receiver.connect(new NamedPipeTransport(socket)); | ||
resolve(); | ||
}); | ||
const incoming = new Promise((resolve) => { | ||
this._incomingServer = createNodeServer((socket: INodeSocket): void => { | ||
this._receiver.connect(new NamedPipeTransport(socket)); | ||
resolve(); | ||
}); | ||
}); | ||
const outgoing = new Promise(resolve => { | ||
const outgoing = new Promise((resolve) => { | ||
this._outgoingServer = createNodeServer((socket: INodeSocket): void => { | ||
@@ -129,3 +130,3 @@ this._sender.connect(new NamedPipeTransport(socket)); | ||
} | ||
/** | ||
@@ -154,7 +155,7 @@ * Task used to send data over this client connection. | ||
if (this._autoReconnect) { | ||
this.start() | ||
.catch((err): void => { throw(new Error(`Unable to reconnect: ${ err.message }`)); }); | ||
this.start().catch((err): void => { | ||
throw new Error(`Unable to reconnect: ${err.message}`); | ||
}); | ||
} | ||
} | ||
finally { | ||
} finally { | ||
this._isDisconnecting = false; | ||
@@ -161,0 +162,0 @@ } |
@@ -94,3 +94,3 @@ /** | ||
let promise = new Promise<INodeBuffer>((resolve, reject): void => { | ||
const promise = new Promise<INodeBuffer>((resolve, reject): void => { | ||
this._activeReceiveResolve = resolve; | ||
@@ -142,3 +142,3 @@ this._activeReceiveReject = reject; | ||
// can send the entire _active buffer | ||
let buffer = this._active; | ||
const buffer = this._active; | ||
this._active = null; | ||
@@ -149,4 +149,4 @@ | ||
// create a new buffer and copy some of the contents into it | ||
let available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
let buffer = Buffer.alloc(available); | ||
const available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
const buffer = Buffer.alloc(available); | ||
this._active.copy(buffer, 0, this._activeOffset, this._activeOffset + available); | ||
@@ -153,0 +153,0 @@ this._activeOffset += available; |
@@ -39,5 +39,10 @@ /** | ||
public static serialize(header: IHeader, buffer: INodeBuffer): void { | ||
buffer.write(header.payloadType, this.TypeOffset, 1, this.Encoding); | ||
buffer.write(header.payloadType, this.TypeOffset, 1, this.Encoding); | ||
buffer.write(this.Delimiter, this.TypeDelimiterOffset, 1, this.Encoding); | ||
buffer.write(this.headerLengthPadder(header.payloadLength, this.LengthLength, '0'), this.LengthOffset, this.LengthLength, this.Encoding); | ||
buffer.write( | ||
this.headerLengthPadder(header.payloadLength, this.LengthLength, '0'), | ||
this.LengthOffset, | ||
this.LengthLength, | ||
this.Encoding | ||
); | ||
buffer.write(this.Delimiter, this.LengthDelimeterOffset, 1, this.Encoding); | ||
@@ -57,7 +62,7 @@ buffer.write(header.id, this.IdOffset); | ||
public static deserialize(buffer: INodeBuffer): IHeader { | ||
let jsonBuffer = buffer.toString(this.Encoding); | ||
let headerArray = jsonBuffer.split(this.Delimiter); | ||
const jsonBuffer = buffer.toString(this.Encoding); | ||
const headerArray = jsonBuffer.split(this.Delimiter); | ||
if (headerArray.length !== 4) { | ||
throw Error(`Cannot parse header, header is malformed. Header: ${ jsonBuffer }`); | ||
throw Error(`Cannot parse header, header is malformed. Header: ${jsonBuffer}`); | ||
} | ||
@@ -69,19 +74,28 @@ | ||
const payloadLength = Number(length); | ||
const header: IHeader = { end, payloadLength, payloadType, id }; | ||
if (!(header.payloadLength <= PayloadConstants.MaxPayloadLength && header.payloadLength >= PayloadConstants.MinLength)) { | ||
throw Error(`Header length of ${ header.payloadLength } is missing or malformed`); | ||
if ( | ||
!( | ||
header.payloadLength <= PayloadConstants.MaxPayloadLength && | ||
header.payloadLength >= PayloadConstants.MinLength | ||
) | ||
) { | ||
throw Error(`Header length of ${header.payloadLength} is missing or malformed`); | ||
} | ||
if (header.payloadType.length !== this.TypeDelimiterOffset) { | ||
throw Error(`Header type '${ header.payloadType.length }' is missing or malformed.`); | ||
throw Error(`Header type '${header.payloadType.length}' is missing or malformed.`); | ||
} | ||
if (!header.id || !header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) || header.id.length !== this.IdLength) { | ||
throw Error(`Header ID '${ header.id }' is missing or malformed.`); | ||
if ( | ||
!header.id || | ||
!header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) || | ||
header.id.length !== this.IdLength | ||
) { | ||
throw Error(`Header ID '${header.id}' is missing or malformed.`); | ||
} | ||
if (!(headerEnd === '0\n' || headerEnd === '1\n')) { | ||
throw Error(`Header End is missing or not a valid value. Header end: '${ headerEnd }'`); | ||
throw Error(`Header End is missing or not a valid value. Header end: '${headerEnd}'`); | ||
} | ||
@@ -93,6 +107,5 @@ | ||
public static headerLengthPadder(lengthValue: number, totalLength: number, padChar: string): string { | ||
let result = Array(totalLength + 1) | ||
.join(padChar); | ||
const result = Array(totalLength + 1).join(padChar); | ||
let lengthString = lengthValue.toString(); | ||
const lengthString = lengthValue.toString(); | ||
@@ -99,0 +112,0 @@ return (result + lengthString).slice(lengthString.length); |
@@ -33,3 +33,3 @@ /** | ||
} else if (!this.activeAssemblers[header.id]) { | ||
let assembler = this.createPayloadAssembler(header); | ||
const assembler = this.createPayloadAssembler(header); | ||
@@ -48,3 +48,3 @@ if (assembler) { | ||
if (this.activeAssemblers && this.activeAssemblers[header.id]) { | ||
let assembler = this.activeAssemblers[header.id]; | ||
const assembler = this.activeAssemblers[header.id]; | ||
assembler.onReceive(header, contentStream, contentLength); | ||
@@ -60,7 +60,7 @@ } | ||
if (header.payloadType === PayloadTypes.request) { | ||
return new PayloadAssembler(this.streamManager, {header: header, onCompleted: this.onReceiveRequest}); | ||
return new PayloadAssembler(this.streamManager, { header: header, onCompleted: this.onReceiveRequest }); | ||
} else if (header.payloadType === PayloadTypes.response) { | ||
return new PayloadAssembler(this.streamManager, {header: header, onCompleted: this.onReceiveResponse}); | ||
return new PayloadAssembler(this.streamManager, { header: header, onCompleted: this.onReceiveResponse }); | ||
} | ||
} | ||
} |
@@ -17,3 +17,3 @@ /** | ||
cancelAll = 'X', | ||
cancelStream = 'C' | ||
cancelStream = 'C', | ||
} |
@@ -30,3 +30,3 @@ /** | ||
public async signalResponse(requestId: string, response: IReceiveResponse): Promise<boolean> { | ||
let pendingRequest = this._pendingRequests[requestId]; | ||
const pendingRequest = this._pendingRequests[requestId]; | ||
@@ -47,3 +47,3 @@ if (pendingRequest) { | ||
if (pendingRequest) { | ||
return Promise.reject(`requestId '${ requestId }' already exists in RequestManager`); | ||
return Promise.reject(`requestId '${requestId}' already exists in RequestManager`); | ||
} | ||
@@ -54,3 +54,3 @@ | ||
let promise = new Promise<IReceiveResponse>((resolve, reject): void => { | ||
const promise = new Promise<IReceiveResponse>((resolve, reject): void => { | ||
pendingRequest.resolve = resolve; | ||
@@ -57,0 +57,0 @@ pendingRequest.reject = reject; |
@@ -28,3 +28,3 @@ /** | ||
public async sendRequest(id: string, request: StreamingRequest): Promise<void> { | ||
let disassembler = new RequestDisassembler(this.payloadSender, id, request); | ||
const disassembler = new RequestDisassembler(this.payloadSender, id, request); | ||
@@ -34,5 +34,7 @@ await disassembler.disassemble(); | ||
if (request.streams) { | ||
request.streams.forEach(async (contentStream): Promise<void> => { | ||
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); | ||
}); | ||
request.streams.forEach( | ||
async (contentStream): Promise<void> => { | ||
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); | ||
} | ||
); | ||
} | ||
@@ -42,3 +44,3 @@ } | ||
public async sendResponse(id: string, response: StreamingResponse): Promise<void> { | ||
let disassembler = new ResponseDisassembler(this.payloadSender, id, response); | ||
const disassembler = new ResponseDisassembler(this.payloadSender, id, response); | ||
@@ -48,5 +50,7 @@ await disassembler.disassemble(); | ||
if (response.streams) { | ||
response.streams.forEach(async (contentStream): Promise<void> => { | ||
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); | ||
}); | ||
response.streams.forEach( | ||
async (contentStream): Promise<void> => { | ||
await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); | ||
} | ||
); | ||
} | ||
@@ -56,5 +60,5 @@ } | ||
public async sendCancelStream(id: string): Promise<void> { | ||
let disassembler = new CancelDisassembler(this.payloadSender, id, PayloadTypes.cancelStream); | ||
const disassembler = new CancelDisassembler(this.payloadSender, id, PayloadTypes.cancelStream); | ||
disassembler.disassemble(); | ||
} | ||
} |
@@ -26,3 +26,3 @@ /** | ||
// A new id has come in, kick off the process of tracking it. | ||
let assembler = new PayloadAssembler(this, {id: id}); | ||
const assembler = new PayloadAssembler(this, { id: id }); | ||
this.activeAssemblers[id] = assembler; | ||
@@ -32,3 +32,2 @@ | ||
} else { | ||
return this.activeAssemblers[id]; | ||
@@ -39,3 +38,3 @@ } | ||
public getPayloadStream(header: IHeader): SubscribableStream { | ||
let assembler = this.getPayloadAssembler(header.id); | ||
const assembler = this.getPayloadAssembler(header.id); | ||
@@ -56,5 +55,5 @@ return assembler.getPayloadStream(); | ||
} else { | ||
let assembler: PayloadAssembler = this.activeAssemblers[id]; | ||
const assembler: PayloadAssembler = this.activeAssemblers[id]; | ||
this.activeAssemblers.splice(this.activeAssemblers.indexOf(id), 1); | ||
let targetStream = assembler.getPayloadStream(); | ||
const targetStream = assembler.getPayloadStream(); | ||
if ((assembler.contentLength && targetStream.length < assembler.contentLength) || !assembler.end) { | ||
@@ -61,0 +60,0 @@ this.onCancelStream(assembler); |
@@ -23,3 +23,3 @@ /** | ||
public isConnected: boolean; | ||
public disconnected: TransportDisconnectedEventHandler = function(sender, events){}; | ||
public disconnected: TransportDisconnectedEventHandler = function (sender, events) {}; | ||
private _receiver: ITransportReceiver; | ||
@@ -52,3 +52,6 @@ private _receiveHeaderBuffer: INodeBuffer; | ||
*/ | ||
public subscribe(getStream: (header: IHeader) => SubscribableStream, receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void): void { | ||
public subscribe( | ||
getStream: (header: IHeader) => SubscribableStream, | ||
receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void | ||
): void { | ||
this._getStream = getStream; | ||
@@ -84,4 +87,3 @@ this._receiveAction = receiveAction; | ||
private runReceive(): void { | ||
this.receivePackets() | ||
.catch(); | ||
this.receivePackets().catch(); | ||
} | ||
@@ -96,3 +98,5 @@ | ||
while (readSoFar < PayloadConstants.MaxHeaderLength) { | ||
this._receiveHeaderBuffer = await this._receiver.receive(PayloadConstants.MaxHeaderLength - readSoFar); | ||
this._receiveHeaderBuffer = await this._receiver.receive( | ||
PayloadConstants.MaxHeaderLength - readSoFar | ||
); | ||
@@ -104,4 +108,4 @@ if (this._receiveHeaderBuffer) { | ||
let header = HeaderSerializer.deserialize(this._receiveHeaderBuffer); | ||
let isStream = header.payloadType === PayloadTypes.stream; | ||
const header = HeaderSerializer.deserialize(this._receiveHeaderBuffer); | ||
const isStream = header.payloadType === PayloadTypes.stream; | ||
@@ -111,6 +115,12 @@ if (header.payloadLength > 0) { | ||
let contentStream = this._getStream(header); | ||
const contentStream = this._getStream(header); | ||
while (bytesActuallyRead < header.payloadLength && bytesActuallyRead < PayloadConstants.MaxPayloadLength) { | ||
let count = Math.min(header.payloadLength - bytesActuallyRead, PayloadConstants.MaxPayloadLength); | ||
while ( | ||
bytesActuallyRead < header.payloadLength && | ||
bytesActuallyRead < PayloadConstants.MaxPayloadLength | ||
) { | ||
const count = Math.min( | ||
header.payloadLength - bytesActuallyRead, | ||
PayloadConstants.MaxPayloadLength | ||
); | ||
this._receivePayloadBuffer = await this._receiver.receive(count); | ||
@@ -117,0 +127,0 @@ bytesActuallyRead += this._receivePayloadBuffer.byteLength; |
@@ -51,3 +51,3 @@ /** | ||
public sendPayload(header: IHeader, payload?: SubscribableStream, sentCallback?: () => Promise<void>): void { | ||
var packet: ISendPacket = {header, payload, sentCallback}; | ||
const packet: ISendPacket = { header, payload, sentCallback }; | ||
this.writePacket(packet); | ||
@@ -75,14 +75,14 @@ } | ||
if (packet.header.payloadLength > 0 && packet.payload) { | ||
let leftOver = packet.header.payloadLength; | ||
while (leftOver > 0) { | ||
let count = leftOver <= PayloadConstants.MaxPayloadLength ? leftOver : PayloadConstants.MaxPayloadLength; | ||
let chunk = packet.payload.read(count); | ||
while (leftOver > 0) { | ||
const count = | ||
leftOver <= PayloadConstants.MaxPayloadLength ? leftOver : PayloadConstants.MaxPayloadLength; | ||
const chunk = packet.payload.read(count); | ||
var header = packet.header; | ||
const header = packet.header; | ||
header.payloadLength = count; | ||
header.end = leftOver <= PayloadConstants.MaxPayloadLength; | ||
let sendHeaderBuffer: Buffer = Buffer.alloc(PayloadConstants.MaxHeaderLength); | ||
const sendHeaderBuffer: Buffer = Buffer.alloc(PayloadConstants.MaxHeaderLength); | ||
@@ -94,3 +94,3 @@ HeaderSerializer.serialize(header, sendHeaderBuffer); | ||
this.sender.send(chunk); | ||
leftOver-= chunk.length; | ||
leftOver -= chunk.length; | ||
} | ||
@@ -97,0 +97,0 @@ |
@@ -14,3 +14,3 @@ /** | ||
public static Empty: TransportDisconnectedEvent = new TransportDisconnectedEvent(); | ||
/** | ||
@@ -17,0 +17,0 @@ * The reason the disconnection event fired, in plain text. |
@@ -38,3 +38,8 @@ /** | ||
/// <param name="receiver">The receiver for use with incoming requests.</param> | ||
public constructor(requestHandler: RequestHandler, requestManager: RequestManager, sender: PayloadSender, receiver: PayloadReceiver) { | ||
public constructor( | ||
requestHandler: RequestHandler, | ||
requestManager: RequestManager, | ||
sender: PayloadSender, | ||
receiver: PayloadReceiver | ||
) { | ||
this.requestHandler = requestHandler; | ||
@@ -46,4 +51,12 @@ this.requestManager = requestManager; | ||
this.streamManager = new StreamManager(this.onCancelStream); | ||
this.assemblerManager = new PayloadAssemblerManager(this.streamManager, (id: string, response: IReceiveResponse): Promise<void> => this.onReceiveResponse(id, response),(id: string, request: IReceiveRequest): Promise<void> => this.onReceiveRequest(id, request)); | ||
this.payloadReceiver.subscribe((header: IHeader): SubscribableStream => this.assemblerManager.getPayloadStream(header),(header: IHeader, contentStream: SubscribableStream, contentLength: number): void => this.assemblerManager.onReceive(header, contentStream, contentLength)); | ||
this.assemblerManager = new PayloadAssemblerManager( | ||
this.streamManager, | ||
(id: string, response: IReceiveResponse): Promise<void> => this.onReceiveResponse(id, response), | ||
(id: string, request: IReceiveRequest): Promise<void> => this.onReceiveRequest(id, request) | ||
); | ||
this.payloadReceiver.subscribe( | ||
(header: IHeader): SubscribableStream => this.assemblerManager.getPayloadStream(header), | ||
(header: IHeader, contentStream: SubscribableStream, contentLength: number): void => | ||
this.assemblerManager.onReceive(header, contentStream, contentLength) | ||
); | ||
} | ||
@@ -57,3 +70,3 @@ | ||
public async sendRequest(request: StreamingRequest): Promise<IReceiveResponse> { | ||
let requestId: string = generateGuid(); | ||
const requestId: string = generateGuid(); | ||
await this.sendOperations.sendRequest(requestId, request); | ||
@@ -71,3 +84,3 @@ | ||
if (this.requestHandler) { | ||
let response = await this.requestHandler.processRequest(request); | ||
const response = await this.requestHandler.processRequest(request); | ||
@@ -97,5 +110,4 @@ if (response) { | ||
public onCancelStream(contentStreamAssembler: PayloadAssembler): void { | ||
this.sendOperations.sendCancelStream(contentStreamAssembler.id) | ||
.catch(); | ||
this.sendOperations.sendCancelStream(contentStreamAssembler.id).catch(); | ||
} | ||
} |
@@ -15,6 +15,5 @@ /** | ||
export abstract class RequestHandler { | ||
/** | ||
* The method that must be implemented in order to handle incoming requests. | ||
* | ||
* | ||
* @param request A receipt request for this handler to process. | ||
@@ -21,0 +20,0 @@ * @returns A promise that will produce a streaming response on successful completion. |
@@ -12,3 +12,2 @@ /** | ||
export class StreamingRequest { | ||
/** | ||
@@ -38,3 +37,3 @@ * Request verb, null on responses. | ||
public static create(method: string, path?: string, body?: HttpContent): StreamingRequest { | ||
let request = new StreamingRequest(); | ||
const request = new StreamingRequest(); | ||
request.verb = method; | ||
@@ -69,9 +68,13 @@ request.path = path; | ||
if (typeof body === 'string') { | ||
let stream = new SubscribableStream(); | ||
const stream = new SubscribableStream(); | ||
stream.write(body, 'utf8'); | ||
this.addStream(new HttpContent({ | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length | ||
}, | ||
stream)); | ||
this.addStream( | ||
new HttpContent( | ||
{ | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length, | ||
}, | ||
stream | ||
) | ||
); | ||
} else if (typeof body === 'object') { | ||
@@ -78,0 +81,0 @@ this.addStream(body); |
@@ -23,3 +23,3 @@ /** | ||
public static create(statusCode: number, body?: HttpContent): StreamingResponse { | ||
let response = new StreamingResponse(); | ||
const response = new StreamingResponse(); | ||
response.statusCode = statusCode; | ||
@@ -48,9 +48,14 @@ if (body) { | ||
public setBody(body: any): void { | ||
let stream = new SubscribableStream(); | ||
const stream = new SubscribableStream(); | ||
stream.write(JSON.stringify(body), 'utf8'); | ||
this.addStream(new HttpContent({ | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length | ||
}, stream)); | ||
this.addStream( | ||
new HttpContent( | ||
{ | ||
type: 'application/json; charset=utf-8', | ||
contentLength: stream.length, | ||
}, | ||
stream | ||
) | ||
); | ||
} | ||
} |
@@ -11,3 +11,3 @@ /** | ||
export class SubscribableStream extends Duplex { | ||
public length: number = 0; | ||
public length = 0; | ||
@@ -22,3 +22,3 @@ private readonly bufferList: Buffer[] = []; | ||
public _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void { | ||
let buffer = Buffer.from(chunk); | ||
const buffer = Buffer.from(chunk); | ||
this.bufferList.push(buffer); | ||
@@ -39,3 +39,3 @@ this.length += chunk.length; | ||
while (total < size && this.bufferList.length > 0) { | ||
let buffer = this.bufferList[0]; | ||
const buffer = this.bufferList[0]; | ||
this.push(buffer); | ||
@@ -42,0 +42,0 @@ this.bufferList.splice(0, 1); |
@@ -9,9 +9,9 @@ /** | ||
import { INodeServer, INodeSocket} from '../interfaces'; | ||
import { INodeServer, INodeSocket } from '../interfaces'; | ||
export const createNodeServer = function(callback?: (socket: INodeSocket) => void): INodeServer { | ||
export const createNodeServer = function (callback?: (socket: INodeSocket) => void): INodeServer { | ||
if (callback && typeof callback !== 'function') { | ||
throw new TypeError(`Invalid callback; callback parameter must be a function to create Node 'net' Server.`); | ||
} | ||
try { | ||
@@ -25,5 +25,5 @@ const server = getServerFactory()(callback); | ||
} | ||
} | ||
}; | ||
export const getServerFactory = function(): Function { | ||
export const getServerFactory = function (): Function { | ||
if (typeof require !== undefined) { | ||
@@ -33,15 +33,17 @@ return require('net').Server; | ||
throw TypeError(`require is undefined. Must be in a Node module to require 'net' dynamically in order to fetch Server factory.`) | ||
} | ||
throw TypeError( | ||
`require is undefined. Must be in a Node module to require 'net' dynamically in order to fetch Server factory.` | ||
); | ||
}; | ||
function isNetServer(o: any): o is INodeServer { | ||
return (hasCloseMethod && hasListenMethod) ? true : false; | ||
return hasCloseMethod && hasListenMethod ? true : false; | ||
} | ||
function hasCloseMethod(o: any): o is INodeServer { | ||
return (o.close && typeof o.close === 'function') ? true : false; | ||
return o.close && typeof o.close === 'function' ? true : false; | ||
} | ||
function hasListenMethod(o: any): o is INodeServer { | ||
return (o.listen && typeof o.listen === 'function') ? true : false; | ||
return o.listen && typeof o.listen === 'function' ? true : false; | ||
} |
@@ -49,3 +49,2 @@ /** | ||
}); | ||
} | ||
@@ -80,3 +79,3 @@ | ||
public setOnMessageHandler(handler: (x: any) => void): void { | ||
const bufferKey: string = 'buffer'; | ||
const bufferKey = 'buffer'; | ||
const packets = []; | ||
@@ -88,6 +87,6 @@ this.webSocket.onmessage = (evt): void => { | ||
fileReader.onload = (e): void => { | ||
const t = e.target as unknown as IBrowserFileReader; | ||
const t = (e.target as unknown) as IBrowserFileReader; | ||
queueEntry[bufferKey] = t.result; | ||
if (packets[0] === queueEntry) { | ||
while(0 < packets.length && packets[0][bufferKey]) { | ||
while (0 < packets.length && packets[0][bufferKey]) { | ||
handler(packets[0][bufferKey]); | ||
@@ -106,5 +105,9 @@ packets.splice(0, 1); | ||
public setOnErrorHandler(handler: (x: any) => void): void { | ||
this.webSocket.onerror = (error): void => { if (error) { handler(error); } }; | ||
this.webSocket.onerror = (error): void => { | ||
if (error) { | ||
handler(error); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -111,0 +114,0 @@ * Set the callback to call when encountering socket closures. |
@@ -13,7 +13,3 @@ /** | ||
import { RequestManager } from '../payloads'; | ||
import { | ||
PayloadReceiver, | ||
PayloadSender, | ||
TransportDisconnectedEvent | ||
} from '../payloadTransport'; | ||
import { PayloadReceiver, PayloadSender, TransportDisconnectedEvent } from '../payloadTransport'; | ||
import { BrowserWebSocket } from './browserWebSocket'; | ||
@@ -42,3 +38,3 @@ import { WebSocketTransport } from './webSocketTransport'; | ||
*/ | ||
public constructor({ url, requestHandler, disconnectionHandler = null}) { | ||
public constructor({ url, requestHandler, disconnectionHandler = null }) { | ||
this._url = url; | ||
@@ -55,3 +51,8 @@ this._requestHandler = requestHandler; | ||
this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._protocolAdapter = new ProtocolAdapter( | ||
this._requestHandler, | ||
this._requestManager, | ||
this._sender, | ||
this._receiver | ||
); | ||
} | ||
@@ -96,4 +97,8 @@ | ||
throw new Error(`Unable to re-connect client to transport for url ${ this._url }. Sender: '${ JSON.stringify(sender) }'. Args:' ${ JSON.stringify(args) }`); | ||
throw new Error( | ||
`Unable to re-connect client to transport for url ${this._url}. Sender: '${JSON.stringify( | ||
sender | ||
)}'. Args:' ${JSON.stringify(args)}` | ||
); | ||
} | ||
} |
@@ -26,8 +26,12 @@ /** | ||
*/ | ||
public async createWebSocket(req: INodeIncomingMessage, socket: INodeSocket, head: INodeBuffer): Promise<NodeWebSocket> { | ||
public async createWebSocket( | ||
req: INodeIncomingMessage, | ||
socket: INodeSocket, | ||
head: INodeBuffer | ||
): Promise<NodeWebSocket> { | ||
const s = new NodeWebSocket(); | ||
await s.create(req, socket, head); | ||
return s; | ||
} | ||
} |
@@ -12,3 +12,7 @@ /** | ||
export abstract class NodeWebSocketFactoryBase { | ||
public abstract createWebSocket(req: INodeIncomingMessage, socket: INodeSocket, head: INodeBuffer): Promise<ISocket>; | ||
public abstract createWebSocket( | ||
req: INodeIncomingMessage, | ||
socket: INodeSocket, | ||
head: INodeBuffer | ||
): Promise<ISocket>; | ||
} |
@@ -39,6 +39,11 @@ /** | ||
try { | ||
this.wsServer.handleUpgrade(req as IncomingMessage, socket as INodeSocket, head as INodeBuffer, (websocket) => { | ||
this.wsSocket = websocket; | ||
resolve(); | ||
}); | ||
this.wsServer.handleUpgrade( | ||
req as IncomingMessage, | ||
socket as INodeSocket, | ||
head as INodeBuffer, | ||
(websocket) => { | ||
this.wsSocket = websocket; | ||
resolve(); | ||
} | ||
); | ||
} catch (err) { | ||
@@ -82,4 +87,4 @@ reject(err); | ||
'Sec-WebSocket-Key': wskey, | ||
'Sec-WebSocket-Version': '13' | ||
} | ||
'Sec-WebSocket-Version': '13', | ||
}, | ||
}; | ||
@@ -132,4 +137,8 @@ const req = request(options); | ||
public setOnErrorHandler(handler: (x: any) => void): void { | ||
this.wsSocket.on('error', (error): void => { if (error) { handler(error); } }); | ||
this.wsSocket.on('error', (error): void => { | ||
if (error) { | ||
handler(error); | ||
} | ||
}); | ||
} | ||
} | ||
} |
@@ -13,7 +13,3 @@ /** | ||
import { RequestManager } from '../payloads'; | ||
import { | ||
PayloadReceiver, | ||
PayloadSender, | ||
TransportDisconnectedEvent | ||
} from '../payloadTransport'; | ||
import { PayloadReceiver, PayloadSender, TransportDisconnectedEvent } from '../payloadTransport'; | ||
import { NodeWebSocket } from './nodeWebSocket'; | ||
@@ -42,3 +38,3 @@ import { WebSocketTransport } from './webSocketTransport'; | ||
*/ | ||
public constructor({ url, requestHandler, disconnectionHandler = null}) { | ||
public constructor({ url, requestHandler, disconnectionHandler = null }) { | ||
this._url = url; | ||
@@ -55,3 +51,8 @@ this._requestHandler = requestHandler; | ||
this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._protocolAdapter = new ProtocolAdapter( | ||
this._requestHandler, | ||
this._requestManager, | ||
this._sender, | ||
this._receiver | ||
); | ||
} | ||
@@ -100,4 +101,8 @@ | ||
throw new Error(`Unable to re-connect client to Node transport for url ${ this._url }. Sender: '${ JSON.stringify(sender) }'. Args:' ${ JSON.stringify(args) }`); | ||
throw new Error( | ||
`Unable to re-connect client to Node transport for url ${this._url}. Sender: '${JSON.stringify( | ||
sender | ||
)}'. Args:' ${JSON.stringify(args)}` | ||
); | ||
} | ||
} |
@@ -12,7 +12,3 @@ /** | ||
import { RequestManager } from '../payloads'; | ||
import { | ||
PayloadReceiver, | ||
PayloadSender, | ||
TransportDisconnectedEvent | ||
} from '../payloadTransport'; | ||
import { PayloadReceiver, PayloadSender, TransportDisconnectedEvent } from '../payloadTransport'; | ||
import { ISocket } from '../interfaces/ISocket'; | ||
@@ -58,5 +54,12 @@ import { WebSocketTransport } from './webSocketTransport'; | ||
this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); | ||
this._protocolAdapter = new ProtocolAdapter( | ||
this._requestHandler, | ||
this._requestManager, | ||
this._sender, | ||
this._receiver | ||
); | ||
this._closedSignal = (x: string): string => { return x; }; | ||
this._closedSignal = (x: string): string => { | ||
return x; | ||
}; | ||
} | ||
@@ -63,0 +66,0 @@ |
@@ -90,3 +90,3 @@ /** | ||
let promise = new Promise<INodeBuffer>((resolve, reject): void => { | ||
const promise = new Promise<INodeBuffer>((resolve, reject): void => { | ||
this._activeReceiveResolve = resolve; | ||
@@ -143,3 +143,3 @@ this._activeReceiveReject = reject; | ||
// can send the entire _active buffer | ||
let buffer = this._active; | ||
const buffer = this._active; | ||
this._active = null; | ||
@@ -150,4 +150,4 @@ | ||
// create a Buffer.from and copy some of the contents into it | ||
let available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
let buffer = Buffer.alloc(available); | ||
const available = Math.min(this._activeReceiveCount, this._active.length - this._activeOffset); | ||
const buffer = Buffer.alloc(available); | ||
this._active.copy(buffer, 0, this._activeOffset, this._activeOffset + available); | ||
@@ -154,0 +154,0 @@ this._activeOffset += available; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
652291
9
11416