Skip to content

Commit

Permalink
VBLOCKS-1155 Make sure publisher host is inited if home region exists (
Browse files Browse the repository at this point in the history
…twilio#122)

* VBLOCKS-1155 Making sure publisher host is inited if home region is available

* Changelog and tests
  • Loading branch information
charliesantos authored Oct 25, 2022
1 parent 69a8063 commit 5cca360
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 66 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.1.2 (In Progress)
=========================

Bug Fixes
---------

- Fixed an issue where insights data stops getting published after calling `device.updateOptions`.

2.1.1 (February 18, 2022)
=========================

Expand Down
7 changes: 6 additions & 1 deletion lib/twilio/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,9 @@ class Device extends EventEmitter {
const region = getRegionShortcode(payload.region);
this._edge = payload.edge || regionToEdge[region as Region] || payload.region;
this._region = region || payload.region;
this._home = payload.home;
this._publisher?.setHost(createEventGatewayURI(payload.home));

if (payload.token) {
this._identity = payload.token.identity;
if (
Expand All @@ -1105,7 +1107,6 @@ class Device extends EventEmitter {
}, timeoutMs);
}
}
this._home = payload.home;

const preferredURIs = getChunderURIs(
this._edge as Edge,
Expand Down Expand Up @@ -1347,6 +1348,10 @@ class Device extends EventEmitter {
publisherOptions.host = this._options.eventgw;
}

if (this._home) {
publisherOptions.host = createEventGatewayURI(this._home);
}

this._publisher = new (this._options.Publisher || Publisher)(PUBLISHER_PRODUCT_NAME, this.token, publisherOptions);

if (this._options.publishEvents === false) {
Expand Down
65 changes: 0 additions & 65 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/unit/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ describe('Device', function() {
assert.equal(device['_options'].appName, 'baz');
});

it('should re-initialize publisher with the correct host', () => {
pstream.emit('connected', { home: 'foo'});
device.updateOptions({ appName: 'bar' });
assert.equal(Publisher.args[1][2].host, 'eventgw.foo.twilio.com');
});

it('should set up an audio helper', () => {
const spy = device['_setupAudioHelper'] = sinon.spy(device['_setupAudioHelper']);
device.updateOptions({});
Expand Down

0 comments on commit 5cca360

Please sign in to comment.