50 lines
No EOL
1.6 KiB
JavaScript
50 lines
No EOL
1.6 KiB
JavaScript
"use strict";
|
|
/**
|
|
* @module botframework-streaming
|
|
*/
|
|
/**
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getServerFactory = exports.createNodeServer = void 0;
|
|
/**
|
|
* Create a Node 'net' server
|
|
*
|
|
* @param callback Optional connection listener
|
|
* @returns a Node 'net' server instance
|
|
*/
|
|
function createNodeServer(callback) {
|
|
if (callback && typeof callback !== 'function') {
|
|
throw new TypeError("Invalid callback; callback parameter must be a function to create Node 'net' Server.");
|
|
}
|
|
const server = getServerFactory()(callback);
|
|
if (!isNetServer(server)) {
|
|
throw new Error("Unable to create Node 'net' server");
|
|
}
|
|
return server;
|
|
}
|
|
exports.createNodeServer = createNodeServer;
|
|
/**
|
|
* Get a function that creates a Node 'net' server instance
|
|
*
|
|
* @returns a server factory function
|
|
*/
|
|
function getServerFactory() {
|
|
if (typeof require !== 'undefined') {
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
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.");
|
|
}
|
|
exports.getServerFactory = getServerFactory;
|
|
function isNetServer(o) {
|
|
return hasCloseMethod(o) && hasListenMethod(o);
|
|
}
|
|
function hasCloseMethod(o) {
|
|
return o.close && typeof o.close === 'function';
|
|
}
|
|
function hasListenMethod(o) {
|
|
return o.listen && typeof o.listen === 'function';
|
|
}
|
|
//# sourceMappingURL=createNodeServer.js.map
|