Skip to content

Commit

Permalink
manageBroadcast -> manageChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Jan 2, 2025
1 parent bcd1364 commit 446c8f2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 75 deletions.
80 changes: 40 additions & 40 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ module.exports = function (dependencies) {
});
}
}, this.config.heartBeat).unref();
this.manageBroadcastHealthCheckInterval = setInterval(() => {
this.manageChannelsHealthCheckInterval = setInterval(() => {
if (

Check warning on line 54 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L54

Added line #L54 was not covered by tests
this.manageBroadcastSession &&
!this.manageBroadcastSession.closed &&
!this.manageBroadcastSession.destroyed &&
this.manageChannelsSession &&
!this.manageChannelsSession.closed &&
!this.manageChannelsSession.destroyed &&
!this.isDestroyed
) {
this.manageBroadcastSession.ping((error, duration) => {
this.manageChannelsSession.ping((error, duration) => {
if (error) {
this.errorLogger(

Check warning on line 62 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L60-L62

Added lines #L60 - L62 were not covered by tests
'ManageBroadcastSession No Ping response after ' +
Expand Down Expand Up @@ -94,11 +94,11 @@ module.exports = function (dependencies) {
// Session should be passed except when destroying the client
Client.prototype.destroyManageBroadcastSession = function (session, callback) {
if (!session) {
session = this.manageBroadcastSession;
session = this.manageChannelsSession;

Check warning on line 97 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L96-L97

Added lines #L96 - L97 were not covered by tests
}
if (session) {
if (this.manageBroadcastSession === session) {
this.manageBroadcastSession = null;
if (this.manageChannelsSession === session) {
this.manageChannelsSession = null;

Check warning on line 101 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L99-L101

Added lines #L99 - L101 were not covered by tests
}
if (!session.destroyed) {
session.destroy();

Check warning on line 104 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L103-L104

Added lines #L103 - L104 were not covered by tests
Expand Down Expand Up @@ -131,11 +131,11 @@ module.exports = function (dependencies) {
// Session should be passed except when destroying the client
Client.prototype.closeAndDestroyManageBroadcastSession = function (session, callback) {
if (!session) {
session = this.manageBroadcastSession;
session = this.manageChannelsSession;
}
if (session) {
if (this.manageBroadcastSession === session) {
this.manageBroadcastSession = null;
if (this.manageChannelsSession === session) {
this.manageChannelsSession = null;

Check warning on line 138 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L137-L138

Added lines #L137 - L138 were not covered by tests
}
if (!session.closed) {
session.close(() => this.destroyManageBroadcastSession(session, callback));

Check warning on line 141 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L140-L141

Added lines #L140 - L141 were not covered by tests
Expand Down Expand Up @@ -226,14 +226,14 @@ module.exports = function (dependencies) {
}

if (path.includes('/4/broadcasts')) {
// Connect manageBroadcastSession
// Connect manageChannelsSession
if (

Check warning on line 230 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L230

Added line #L230 was not covered by tests
!this.manageBroadcastSession ||
this.manageBroadcastSession.closed ||
this.manageBroadcastSession.destroyed
!this.manageChannelsSession ||
this.manageChannelsSession.closed ||
this.manageChannelsSession.destroyed
) {
try {
await await this.manageBroadcastConnect();
await await this.manageChannelsConnect();

Check warning on line 236 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L235-L236

Added lines #L235 - L236 were not covered by tests
} catch (error) {
if (this.errorLogger.enabled) {

Check warning on line 238 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L238

Added line #L238 was not covered by tests
// Proxy server that returned error doesn't have access to logger.
Expand All @@ -246,8 +246,8 @@ module.exports = function (dependencies) {

try {
const sentRequest = await this.request(

Check warning on line 248 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L247-L248

Added lines #L247 - L248 were not covered by tests
this.manageBroadcastSession,
this.config.manageBroadcastAddress,
this.manageChannelsSession,
this.config.manageChannelsAddress,
notification,
path,
httpMethod
Expand Down Expand Up @@ -429,25 +429,25 @@ module.exports = function (dependencies) {
return this.sessionPromise;
};

Client.prototype.manageBroadcastConnect = async function manageBroadcastConnect() {
if (this.manageBroadcastSessionPromise) return this.manageBroadcastSessionPromise;
Client.prototype.manageChannelsConnect = async function manageChannelsConnect() {
if (this.manageChannelsSessionPromise) return this.manageChannelsSessionPromise;

Check warning on line 433 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L433

Added line #L433 was not covered by tests

const proxySocketPromise = this.config.manageBroadcastProxy
? createProxySocket(this.config.manageBroadcastProxy, {
host: this.config.manageBroadcastAddress,
port: this.config.manageBroadcastPort,
const proxySocketPromise = this.config.manageChannelsProxy

Check warning on line 435 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L435

Added line #L435 was not covered by tests
? createProxySocket(this.config.manageChannelsProxy, {
host: this.config.manageChannelsAddress,
port: this.config.manageChannelsPort,
})
: Promise.resolve();

this.manageBroadcastSessionPromise = proxySocketPromise.then(socket => {
this.manageBroadcastSessionPromise = null;
this.manageChannelsSessionPromise = proxySocketPromise.then(socket => {
this.manageChannelsSessionPromise = null;

Check warning on line 443 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L442-L443

Added lines #L442 - L443 were not covered by tests

if (socket) {
this.config.createManageBroadcastConnection = authority =>
authority.protocol === 'http:'

Check warning on line 447 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L445-L447

Added lines #L445 - L447 were not covered by tests
? socket
: authority.protocol === 'https:'
? tls.connect(+authority.port || this.config.manageBroadcastPort, authority.hostname, {
? tls.connect(+authority.port || this.config.manageChannelsPort, authority.hostname, {
socket,
servername: authority.hostname,
ALPNProtocols: ['h2'],
Expand All @@ -456,35 +456,35 @@ module.exports = function (dependencies) {
}

const config = { ...this.config }; // Only need a shallow copy.
config.port = config.manageBroadcastPort; // http2 will use this port.
config.port = config.manageChannelsPort; // http2 will use this port.

Check warning on line 459 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L458-L459

Added lines #L458 - L459 were not covered by tests

const session = (this.manageBroadcastSession = http2.connect(
this._mockOverrideUrl || `https://${this.config.manageBroadcastAddress}`,
const session = (this.manageChannelsSession = http2.connect(

Check warning on line 461 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L461

Added line #L461 was not covered by tests
this._mockOverrideUrl || `https://${this.config.manageChannelsAddress}`,
config
));

this.manageBroadcastSession.on('close', () => {
this.manageChannelsSession.on('close', () => {
if (this.errorLogger.enabled) {
this.errorLogger('ManageBroadcastSession closed');

Check warning on line 468 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L466-L468

Added lines #L466 - L468 were not covered by tests
}
this.destroyManageBroadcastSession(session);

Check warning on line 470 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L470

Added line #L470 was not covered by tests
});

this.manageBroadcastSession.on('socketError', error => {
this.manageChannelsSession.on('socketError', error => {
if (this.errorLogger.enabled) {
this.errorLogger(`ManageBroadcastSession Socket error: ${error}`);

Check warning on line 475 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L473-L475

Added lines #L473 - L475 were not covered by tests
}
this.closeAndDestroyManageBroadcastSession(session);

Check warning on line 477 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L477

Added line #L477 was not covered by tests
});

this.manageBroadcastSession.on('error', error => {
this.manageChannelsSession.on('error', error => {
if (this.errorLogger.enabled) {
this.errorLogger(`ManageBroadcastSession error: ${error}`);

Check warning on line 482 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L480-L482

Added lines #L480 - L482 were not covered by tests
}
this.closeAndDestroyManageBroadcastSession(session);

Check warning on line 484 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L484

Added line #L484 was not covered by tests
});

this.manageBroadcastSession.on('goaway', (errorCode, lastStreamId, opaqueData) => {
this.manageChannelsSession.on('goaway', (errorCode, lastStreamId, opaqueData) => {
if (this.errorLogger.enabled) {
this.errorLogger(

Check warning on line 489 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L487-L489

Added lines #L487 - L489 were not covered by tests
`ManageBroadcastSession GOAWAY received: (errorCode ${errorCode}, lastStreamId: ${lastStreamId}, opaqueData: ${opaqueData})`
Expand All @@ -494,12 +494,12 @@ module.exports = function (dependencies) {
});

if (this.logger.enabled) {
this.manageBroadcastSession.on('connect', () => {
this.manageChannelsSession.on('connect', () => {
this.logger('ManageBroadcastSession connected');

Check warning on line 498 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L496-L498

Added lines #L496 - L498 were not covered by tests
});
}

this.manageBroadcastSession.on('frameError', (frameType, errorCode, streamId) => {
this.manageChannelsSession.on('frameError', (frameType, errorCode, streamId) => {

Check warning on line 502 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L502

Added line #L502 was not covered by tests
// This is a frame error not associate with any request(stream).
if (this.errorLogger.enabled) {
this.errorLogger(

Check warning on line 505 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L504-L505

Added lines #L504 - L505 were not covered by tests
Expand All @@ -510,7 +510,7 @@ module.exports = function (dependencies) {
});
});

return this.manageBroadcastSessionPromise;
return this.manageChannelsSessionPromise;

Check warning on line 513 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L513

Added line #L513 was not covered by tests
};

Client.prototype.request = async function request(
Expand Down Expand Up @@ -675,9 +675,9 @@ module.exports = function (dependencies) {
clearInterval(this.healthCheckInterval);
this.healthCheckInterval = null;
}
if (this.manageBroadcastHealthCheckInterval) {
clearInterval(this.manageBroadcastHealthCheckInterval);
this.manageBroadcastHealthCheckInterval = null;
if (this.manageChannelsHealthCheckInterval) {
clearInterval(this.manageChannelsHealthCheckInterval);
this.manageChannelsHealthCheckInterval = null;
}
this.closeAndDestroySession(
undefined,
Expand Down
30 changes: 15 additions & 15 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const EndpointAddress = {
development: 'api.sandbox.push.apple.com',
};

const ManageBroadcastEndpointAddress = {
const ManageChannelsEndpointAddress = {
production: 'api-manage-broadcast.push.apple.com',
development: 'api-manage-broadcast.sandbox.push.apple.com',
};
Expand All @@ -27,10 +27,10 @@ module.exports = function (dependencies) {
production: process.env.NODE_ENV === 'production',
address: null,
port: 443,
manageBroadcastAddress: null,
manageBroadcastPort: 2195,
manageChannelsAddress: null,
manageChannelsPort: 2195,
proxy: null,
manageBroadcastProxy: null,
manageChannelsProxy: null,
rejectUnauthorized: true,
connectionRetryLimit: 2,
heartBeat: 60000,
Expand All @@ -41,7 +41,7 @@ module.exports = function (dependencies) {

extend(config, options);
configureAddress(config);
configureManageBroadcastAddress(config);
configureManageChannelsAddress(config);

if (config.token) {
delete config.cert;
Expand Down Expand Up @@ -115,24 +115,24 @@ function configureAddress(options) {
}
}

function configureManageBroadcastAddress(options) {
if (!options.manageBroadcastAddress) {
function configureManageChannelsAddress(options) {
if (!options.manageChannelsAddress) {
if (options.production) {
options.manageBroadcastAddress = ManageBroadcastEndpointAddress.production;
options.manageChannelsAddress = ManageChannelsEndpointAddress.production;
} else {
options.manageBroadcastAddress = ManageBroadcastEndpointAddress.development;
options.manageChannelsAddress = ManageChannelsEndpointAddress.development;
}
configureManageBroadcastPort(options);
configureManageChannelsPort(options);
}
if (!options.manageBroadcastPort) {
configureManageBroadcastPort(options);
if (!options.manageChannelsPort) {
configureManageChannelsPort(options);

Check warning on line 128 in lib/config.js

View check run for this annotation

Codecov / codecov/patch

lib/config.js#L128

Added line #L128 was not covered by tests
}
}

function configureManageBroadcastPort(options) {
function configureManageChannelsPort(options) {
if (options.production) {
options.manageBroadcastPort = 2196;
options.manageChannelsPort = 2196;
} else {
options.manageBroadcastPort = 2195;
options.manageChannelsPort = 2195;
}
}
2 changes: 1 addition & 1 deletion test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ describe('Client', () => {
});
});

describe('ManageBroadcastClient', () => {
describe('ManageChannelsClient', () => {
let server;
let client;
const MOCK_BODY = '{"mock-key":"mock-value"}';
Expand Down
38 changes: 19 additions & 19 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe('config', function () {
production: false,
address: 'api.sandbox.push.apple.com',
port: 443,
manageBroadcastAddress: 'api-manage-broadcast.sandbox.push.apple.com',
manageBroadcastPort: 2195,
manageChannelsAddress: 'api-manage-broadcast.sandbox.push.apple.com',
manageChannelsPort: 2195,
proxy: null,
manageBroadcastProxy: null,
manageChannelsProxy: null,
rejectUnauthorized: true,
connectionRetryLimit: 2,
heartBeat: 60000,
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('config', function () {
});
});

describe('manageBroadcastAddress configuration', function () {
describe('manageChannelsAddress configuration', function () {
let originalEnv;

before(function () {
Expand All @@ -109,58 +109,58 @@ describe('config', function () {
it('should use api-manage-broadcast.sandbox.push.apple.com as the default connection address', function () {
const testConfig = config();
expect(testConfig).to.have.property(
'manageBroadcastAddress',
'manageChannelsAddress',
'api-manage-broadcast.sandbox.push.apple.com'
);
expect(testConfig).to.have.property('manageBroadcastPort', 2195);
expect(testConfig).to.have.property('manageChannelsPort', 2195);
});

it('should use api-manage-broadcast.push.apple.com when NODE_ENV=production', function () {
process.env.NODE_ENV = 'production';
const testConfig = config();
expect(testConfig).to.have.property(
'manageBroadcastAddress',
'manageChannelsAddress',
'api-manage-broadcast.push.apple.com'
);
expect(testConfig).to.have.property('manageBroadcastPort', 2196);
expect(testConfig).to.have.property('manageChannelsPort', 2196);
});

it('should give precedence to production flag over NODE_ENV=production', function () {
process.env.NODE_ENV = 'production';
const testConfig = config({ production: false });
expect(testConfig).to.have.property(
'manageBroadcastAddress',
'manageChannelsAddress',
'api-manage-broadcast.sandbox.push.apple.com'
);
expect(testConfig).to.have.property('manageBroadcastPort', 2195);
expect(testConfig).to.have.property('manageChannelsPort', 2195);
});

it('should use api-manage-broadcast.push.apple.com when production:true', function () {
const testConfig = config({ production: true });
expect(testConfig).to.have.property(
'manageBroadcastAddress',
'manageChannelsAddress',
'api-manage-broadcast.push.apple.com'
);
expect(testConfig).to.have.property('manageBroadcastPort', 2196);
expect(testConfig).to.have.property('manageChannelsPort', 2196);
});

it('should use a custom address and default port when passed', function () {
const testAddress = 'testaddress';
const testPort = 2195;
const testConfig = config({ manageBroadcastAddress: testAddress });
expect(testConfig).to.have.property('manageBroadcastAddress', testAddress);
expect(testConfig).to.have.property('manageBroadcastPort', testPort);
const testConfig = config({ manageChannelsAddress: testAddress });
expect(testConfig).to.have.property('manageChannelsAddress', testAddress);
expect(testConfig).to.have.property('manageChannelsPort', testPort);
});

it('should use a custom address and port when passed', function () {
const testAddress = 'testaddress';
const testPort = 445;
const testConfig = config({
manageBroadcastAddress: testAddress,
manageBroadcastPort: testPort,
manageChannelsAddress: testAddress,
manageChannelsPort: testPort,
});
expect(testConfig).to.have.property('manageBroadcastAddress', testAddress);
expect(testConfig).to.have.property('manageBroadcastPort', testPort);
expect(testConfig).to.have.property('manageChannelsAddress', testAddress);
expect(testConfig).to.have.property('manageChannelsPort', testPort);
});
});

Expand Down

0 comments on commit 446c8f2

Please sign in to comment.