in src/client.ts [424:446]
static fromConnectionString(connStr: string, transportCtor?: Client.TransportCtor): Client {
/*Codes_SRS_NODE_IOTHUB_CLIENT_05_002: [The fromConnectionString method shall throw ReferenceError if the connStr argument is falsy.]*/
if (!connStr) throw new ReferenceError('connStr is \'' + connStr + '\'');
/*Codes_SRS_NODE_IOTHUB_CLIENT_16_016: [The `fromConnectionString` method shall use the `Transport` constructor passed as argument to instantiate a transport object if it's not falsy.]*/
/*Codes_SRS_NODE_IOTHUB_CLIENT_16_017: [The `fromConnectionString` method shall use the default Transport (Amqp) if the `Transport` optional argument is falsy.]*/
if (!transportCtor) {
transportCtor = Amqp;
}
/*Codes_SRS_NODE_IOTHUB_CLIENT_16_015: [The `fromConnectionString` method shall create a new transport instance and pass it a config object formed from the connection string given as argument.]*/
const cn = ConnectionString.parse(connStr);
const config: Client.TransportConfigOptions = {
host: cn.HostName,
keyName: cn.SharedAccessKeyName,
sharedAccessSignature: SharedAccessSignature.create(cn.HostName, cn.SharedAccessKeyName, cn.SharedAccessKey, anHourFromNow()),
tokenCredential: undefined
};
/*Codes_SRS_NODE_IOTHUB_CLIENT_05_004: [The fromConnectionString method shall return a new instance of the Client object, as by a call to new Client(transport).]*/
return new Client(new transportCtor(config), new RestApiClient(config, packageJson.name + '/' + packageJson.version));
}