// Virtual address / IP pressure system. // Lets a connection claim a human-friendly alias (short code, number, IP-style address). export class IPPressure { constructor(mwse) { this.mwse = mwse; this.APNumber = undefined; this.APShortCode = undefined; this.APIPAddress = undefined; } async allocAPIPAddress() { const { status, ip } = await this.mwse.EventPooling.request({ type: 'alloc/APIPAddress' }); if (status === 'success') { this.APIPAddress = ip; return ip; } throw new Error('Error allocating virtual IP address'); } async allocAPNumber() { const { status, number } = await this.mwse.EventPooling.request({ type: 'alloc/APNumber' }); if (status === 'success') { this.APNumber = number; return number; } throw new Error('Error allocating virtual number'); } async allocAPShortCode() { const { status, code } = await this.mwse.EventPooling.request({ type: 'alloc/APShortCode' }); if (status === 'success') { this.APShortCode = code; return code; } throw new Error('Error allocating virtual short code'); } async reallocAPIPAddress() { const { status, ip } = await this.mwse.EventPooling.request({ type: 'realloc/APIPAddress' }); if (status === 'success') { this.APIPAddress = ip; return ip; } throw new Error('Error reallocating virtual IP address'); } async reallocAPNumber() { const { status, number } = await this.mwse.EventPooling.request({ type: 'realloc/APNumber' }); if (status === 'success') { this.APNumber = number; return number; } throw new Error('Error reallocating virtual number'); } async reallocAPShortCode() { const { status, code } = await this.mwse.EventPooling.request({ type: 'realloc/APShortCode' }); if (status === 'success') { this.APShortCode = code; return code; } throw new Error('Error reallocating virtual short code'); } async releaseAPIPAddress() { const { status } = await this.mwse.EventPooling.request({ type: 'release/APIPAddress' }); if (status === 'success') { this.APIPAddress = undefined; return; } throw new Error('Error releasing virtual IP address'); } async releaseAPNumber() { const { status } = await this.mwse.EventPooling.request({ type: 'release/APNumber' }); if (status === 'success') { this.APNumber = undefined; return; } throw new Error('Error releasing virtual number'); } async releaseAPShortCode() { const { status } = await this.mwse.EventPooling.request({ type: 'release/APShortCode' }); if (status === 'success') { this.APShortCode = undefined; return; } throw new Error('Error releasing virtual short code'); } async queryAPIPAddress(ip) { const { status, socket } = await this.mwse.EventPooling.request({ type: 'whois/APIPAddress', whois: ip }); return status === 'success' ? socket : null; } async queryAPNumber(number) { const { status, socket } = await this.mwse.EventPooling.request({ type: 'whois/APNumber', whois: number }); return status === 'success' ? socket : null; } async queryAPShortCode(code) { const { status, socket } = await this.mwse.EventPooling.request({ type: 'whois/APShortCode', whois: code }); return status === 'success' ? socket : null; } }