Skip to content

Commit dab99a8

Browse files
committed
feat(internal-plugin-llm): llmrefactor - renamed disconnectLLM in channel (#5083)
1 parent 863a448 commit dab99a8

5 files changed

Lines changed: 37 additions & 38 deletions

File tree

packages/@webex/internal-plugin-llm/src/llm-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class LLMPlugin extends (WebexPlugin as any) {
8787
return Promise.resolve(false);
8888
}
8989

90-
return channel.disconnectLLM(options).then(() => {
90+
return channel.disconnect(options).then(() => {
9191
this.sessions.delete(sessionId);
9292

9393
return true;
@@ -96,7 +96,7 @@ export class LLMPlugin extends (WebexPlugin as any) {
9696

9797
public disconnectAllLLM(options?: {code: number; reason: string}): Promise<void> {
9898
const promises = Array.from(this.sessions.entries()).map(([sessionId, channel]) =>
99-
channel.disconnectLLM(options).then(() => this.sessions.delete(sessionId))
99+
channel.disconnect(options).then(() => this.sessions.delete(sessionId))
100100
);
101101

102102
return Promise.all(promises).then(() => undefined);

packages/@webex/internal-plugin-llm/src/llm.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,20 @@ export default class LLMChannel extends (Mercury as any) implements ILLMChannel
231231

232232
/**
233233
* Disconnects the WebSocket and clears all connection state.
234+
* Overrides Mercury's disconnect to also clear LLM-specific state.
234235
* @param {object} [options]
235236
* @returns {Promise<void>}
236237
*/
237-
public disconnectLLM = (options?: {code: number; reason: string}): Promise<void> => {
238-
return this.disconnect(options).then(() => {
239-
this.webSocketUrl = undefined;
240-
this.binding = undefined;
241-
this.locusUrl = undefined;
242-
this.datachannelUrl = undefined;
243-
this.datachannelToken = undefined;
244-
this.refreshHandler = undefined;
245-
this.ownerMeetingId = undefined;
246-
});
247-
};
238+
public async disconnect(options?: {code: number; reason: string}): Promise<void> {
239+
await super.disconnect(options);
240+
this.webSocketUrl = undefined;
241+
this.binding = undefined;
242+
this.locusUrl = undefined;
243+
this.datachannelUrl = undefined;
244+
this.datachannelToken = undefined;
245+
this.refreshHandler = undefined;
246+
this.ownerMeetingId = undefined;
247+
}
248248

249249
/**
250250
* Matches a request URL to a stored datachannel registration URL.

packages/@webex/internal-plugin-llm/src/llm.types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ interface ILLMChannel {
1616
getBinding: () => string | undefined;
1717
getLocusUrl: () => string | undefined;
1818
getDatachannelUrl: () => string | undefined;
19-
disconnectLLM: (
20-
options: {code: number; reason: string},
21-
sessionId?: string,
22-
ownerMeetingId?: string
23-
) => Promise<boolean>;
19+
disconnect: (options?: {code: number; reason: string}) => Promise<void>;
2420
disconnectAllLLM: (options?: {code: number; reason: string}) => Promise<void>;
2521
setOwnerMeetingId: (ownerMeetingId: string | undefined, sessionId?: string) => void;
2622
getOwnerMeetingId: (sessionId?: string) => string | undefined;

packages/@webex/internal-plugin-llm/test/unit/spec/llm-plugin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('plugin-llm', () => {
1313

1414
const createMockChannel = () => ({
1515
registerAndConnect: sinon.stub().resolves(),
16-
disconnectLLM: sinon.stub().resolves(),
16+
disconnect: sinon.stub().resolves(),
1717
isConnected: sinon.stub().returns(false),
1818
getBinding: sinon.stub().returns('binding'),
1919
getLocusUrl: sinon.stub().returns('locusUrl'),
@@ -58,7 +58,7 @@ describe('plugin-llm', () => {
5858
'meeting-1'
5959
);
6060

61-
sinon.assert.calledOnceWithExactly(mockChannel.disconnectLLM, {code: 3000, reason: 'bye'});
61+
sinon.assert.calledOnceWithExactly(mockChannel.disconnect, {code: 3000, reason: 'bye'});
6262
assert.equal(plugin.sessions.has(LLM_DEFAULT_SESSION), false);
6363
assert.equal(result, true);
6464
});
@@ -82,7 +82,7 @@ describe('plugin-llm', () => {
8282
'meeting-2'
8383
);
8484

85-
sinon.assert.notCalled(mockChannel.disconnectLLM);
85+
sinon.assert.notCalled(mockChannel.disconnect);
8686
assert.equal(plugin.sessions.has(LLM_DEFAULT_SESSION), true);
8787
assert.equal(result, false);
8888
});
@@ -97,7 +97,7 @@ describe('plugin-llm', () => {
9797
'meeting-1'
9898
);
9999

100-
sinon.assert.calledOnce(mockChannel.disconnectLLM);
100+
sinon.assert.calledOnce(mockChannel.disconnect);
101101
assert.equal(plugin.sessions.has(LLM_DEFAULT_SESSION), false);
102102
assert.equal(result, true);
103103
});
@@ -112,7 +112,7 @@ describe('plugin-llm', () => {
112112
'meeting-1'
113113
);
114114

115-
sinon.assert.calledOnce(mockChannel.disconnectLLM);
115+
sinon.assert.calledOnce(mockChannel.disconnect);
116116
assert.equal(result, true);
117117
});
118118

@@ -121,7 +121,7 @@ describe('plugin-llm', () => {
121121

122122
await plugin.disconnectLLM({code: 1000, reason: 'test'});
123123

124-
sinon.assert.calledOnce(mockChannel.disconnectLLM);
124+
sinon.assert.calledOnce(mockChannel.disconnect);
125125
assert.equal(plugin.sessions.has(LLM_DEFAULT_SESSION), false);
126126
});
127127

@@ -130,7 +130,7 @@ describe('plugin-llm', () => {
130130

131131
await plugin.disconnectLLM({code: 1000, reason: 'test'}, 'custom-session');
132132

133-
sinon.assert.calledOnceWithExactly(mockChannel.disconnectLLM, {code: 1000, reason: 'test'});
133+
sinon.assert.calledOnceWithExactly(mockChannel.disconnect, {code: 1000, reason: 'test'});
134134
assert.equal(plugin.sessions.has('custom-session'), false);
135135
});
136136
});
@@ -145,8 +145,8 @@ describe('plugin-llm', () => {
145145

146146
await plugin.disconnectAllLLM({code: 1000, reason: 'cleanup'});
147147

148-
sinon.assert.calledOnceWithExactly(channel1.disconnectLLM, {code: 1000, reason: 'cleanup'});
149-
sinon.assert.calledOnceWithExactly(channel2.disconnectLLM, {code: 1000, reason: 'cleanup'});
148+
sinon.assert.calledOnceWithExactly(channel1.disconnect, {code: 1000, reason: 'cleanup'});
149+
sinon.assert.calledOnceWithExactly(channel2.disconnect, {code: 1000, reason: 'cleanup'});
150150
assert.equal(plugin.sessions.size, 0);
151151
});
152152

packages/@webex/internal-plugin-llm/test/unit/spec/llm.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ describe('plugin-llm', () => {
2525
};
2626

2727
llmChannel = webex.internal.llm;
28-
llmChannel.disconnect = sinon.stub().resolves();
28+
// Stub Mercury's prototype disconnect so super.disconnect() works in tests
29+
sinon.stub(Object.getPrototypeOf(Object.getPrototypeOf(llmChannel)), 'disconnect').resolves();
2930
llmChannel.request = sinon.stub().resolves({
3031
headers: {},
3132
body: {
@@ -207,8 +208,8 @@ describe('plugin-llm', () => {
207208
});
208209
});
209210

210-
describe('#disconnectLLM', () => {
211-
it('calls disconnect and clears all connection state', async () => {
211+
describe('#disconnect', () => {
212+
it('calls super.disconnect and clears all connection state', async () => {
212213
await llmChannel.registerAndConnect(locusUrl, datachannelUrl);
213214
llmChannel.setDatachannelToken('token123');
214215
llmChannel.ownerMeetingId = 'meeting-1';
@@ -220,9 +221,8 @@ describe('plugin-llm', () => {
220221
assert.equal(llmChannel.getDatachannelToken(), 'token123');
221222
assert.equal(llmChannel.ownerMeetingId, 'meeting-1');
222223

223-
await llmChannel.disconnectLLM({code: 1000, reason: 'test'});
224+
await llmChannel.disconnect({code: 1000, reason: 'test'});
224225

225-
sinon.assert.calledOnceWithExactly(llmChannel.disconnect, {code: 1000, reason: 'test'});
226226
assert.equal(llmChannel.getLocusUrl(), undefined);
227227
assert.equal(llmChannel.getDatachannelUrl(), undefined);
228228
assert.equal(llmChannel.getBinding(), undefined);
@@ -233,17 +233,20 @@ describe('plugin-llm', () => {
233233
it('works without options', async () => {
234234
await llmChannel.registerAndConnect(locusUrl, datachannelUrl);
235235

236-
await llmChannel.disconnectLLM();
236+
await llmChannel.disconnect();
237237

238-
sinon.assert.calledOnceWithExactly(llmChannel.disconnect, undefined);
238+
assert.equal(llmChannel.getLocusUrl(), undefined);
239239
});
240240

241241
it('propagates disconnect errors', async () => {
242242
await llmChannel.registerAndConnect(locusUrl, datachannelUrl);
243-
llmChannel.disconnect = sinon.stub().rejects(new Error('disconnect failed'));
243+
// Change the existing stub to reject
244+
Object.getPrototypeOf(Object.getPrototypeOf(llmChannel)).disconnect.rejects(
245+
new Error('disconnect failed')
246+
);
244247

245248
try {
246-
await llmChannel.disconnectLLM({code: 1000, reason: 'test'});
249+
await llmChannel.disconnect({code: 1000, reason: 'test'});
247250
assert.fail('should have thrown');
248251
} catch (error) {
249252
assert.equal(error.message, 'disconnect failed');
@@ -357,12 +360,12 @@ describe('plugin-llm', () => {
357360
assert.equal(llmChannel.ownerMeetingId, undefined);
358361
});
359362

360-
it('is cleared by disconnectLLM', async () => {
363+
it('is cleared by disconnect', async () => {
361364
await llmChannel.registerAndConnect(locusUrl, datachannelUrl);
362365
llmChannel.ownerMeetingId = 'meeting-1';
363366
assert.equal(llmChannel.ownerMeetingId, 'meeting-1');
364367

365-
await llmChannel.disconnectLLM({code: 1000, reason: 'test'});
368+
await llmChannel.disconnect({code: 1000, reason: 'test'});
366369

367370
assert.equal(llmChannel.ownerMeetingId, undefined);
368371
});

0 commit comments

Comments
 (0)