Skip to content

Commit 8766128

Browse files
yiming-amznYiming Wang
and
Yiming Wang
authored
upgrade UCSDK version (#109)
Co-authored-by: Yiming Wang <yimwang@amazon.com>
1 parent 8b0315c commit 8766128

7 files changed

+101
-81
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"version": "grunt build && grunt copyForPublish && git add package.json release/* ",
2424
"postversion": "export GITTAG=\"echo $(git describe --abbrev=0 --tags | sed 's/^v//')\" && git push --force --set-upstream origin bumpVersion --follow-tags && git checkout gh-pages && git pull && cp out/connect-rtc-debug.js ./connect-rtc-debug-`$GITTAG`.js && cp out/connect-rtc.min.js ./connect-rtc-`$GITTAG`.min.js && ln -fs connect-rtc-debug-`$GITTAG`.js connect-rtc-debug-latest.js && ln -fs connect-rtc-`$GITTAG`.min.js connect-rtc-latest.min.js && git add connect-rtc*.js && git commit -m `$GITTAG` && git push --set-upstream origin gh-pages && git checkout master",
2525
"prepublish": "grunt build",
26-
"test": "grunt && nyc --reporter=html mocha --compilers js:babel-core/register test/unit"
26+
"test": "grunt && nyc --reporter=html mocha --compilers js:babel-core/register test/unit/**/*.js test/unit/*.js"
2727
},
2828
"_ucsdk_upgrade_note": "Please follow the instruction here(https://tiny.amazon.com/18mszf5px/quipaTMFStep) to upgrade @citrix/ucsdk",
2929
"dependencies": {
30-
"@citrix/ucsdk": "2.0.5",
30+
"@citrix/ucsdk": "3.1.0",
3131
"uuid": "^3.0.1",
3232
"webrtc-adapter": "^6.4.0"
3333
},

src/js/rtc_session.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ export default class RtcSession {
880880
RTC_PEER_CONNECTION_CONFIG.iceServers = self._iceServers;
881881
self._pc = self._createPeerConnection(RTC_PEER_CONNECTION_CONFIG, RTC_PEER_CONNECTION_OPTIONAL_CONFIG);
882882
}
883-
self._strategy.connect(self);
883+
self._pc.ontrack = hitch(self, self._ontrack);
884884
self._pc.onicecandidate = hitch(self, self._onIceCandidate);
885885
self._pc.onconnectionstatechange = hitch(self, self._onPeerConnectionStateChange);
886886
self._pc.oniceconnectionstatechange = hitch(self, self._onIceStateChange);

src/js/strategies/CitrixVDIStrategy.js

+39-27
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,41 @@
33
*/
44

55
import CCPInitiationStrategyInterface from "./CCPInitiationStrategyInterface";
6-
import {hitch} from "../utils";
76
import {FailedState} from "../rtc_session";
87
import {RTC_ERRORS} from "../rtc_const";
9-
import "@citrix/ucsdk/CitrixWebRTC";
108

119
export default class CitrixVDIStrategy extends CCPInitiationStrategyInterface {
1210

13-
constructor() {
11+
constructor(useRealCitrix = true) {
1412
super();
15-
if (!window.CitrixWebRTC.isFeatureOn("webrtc1.0")) {
16-
throw new Error('Citrix WebRTC redirection feature is NOT supported!');
17-
}
18-
window.getCitrixWebrtcRedir = function () {
19-
const registryValue = Promise.resolve(1);
20-
return new Promise(function (resolve, reject) {
21-
//retrieve registry value internally
22-
registryValue.then((v) => {
23-
resolve(v);
24-
}).catch(() => {
25-
reject();
26-
})
27-
})
13+
if(useRealCitrix){
14+
require("@citrix/ucsdk/CitrixWebRTC");
2815
}
16+
console.log("CitrixVDIStrategy initializing");
17+
this.initCitrixWebRTC();
18+
this.initGetCitrixWebrtcRedir();
19+
this.initLog();
20+
}
21+
22+
initCitrixWebRTC() {
23+
window.CitrixWebRTC.setVMEventCallback((event) => {
24+
if (event.event === 'vdiClientConnected') {
25+
if (!window.CitrixWebRTC.isFeatureOn("webrtc1.0")) {
26+
throw new Error('Citrix WebRTC redirection feature is NOT supported!');
27+
}
28+
console.log("CitrixVDIStrategy initialized");
29+
} else if (event.event === 'vdiClientDisconnected') {
30+
console.log("vdiClientDisconnected");
31+
}
32+
});
33+
window.CitrixWebRTC.initUCSDK("AmazonConnect");
34+
}
35+
initGetCitrixWebrtcRedir() {
36+
window.getCitrixWebrtcRedir = () => Promise.resolve(1);
37+
}
38+
39+
initLog() {
2940
window.CitrixWebRTC.initLog(global.connect.getLog());
30-
console.log("CitrixVDIStrategy initialized");
3141
}
3242

3343
// the following functions are rtc_peer_connection_factory related functions
@@ -86,18 +96,20 @@ export default class CitrixVDIStrategy extends CCPInitiationStrategyInterface {
8696
return new window.CitrixWebRTC.CitrixPeerConnection(configuration, optionalConfiguration);
8797
}
8898

89-
connect(self) {
90-
self._pc.onaddstream = hitch(self, self._ontrack);
91-
}
92-
9399
_ontrack(self, evt) {
94-
const remoteStream = evt.stream.clone();
95-
96-
const audioTracks = evt.stream.getAudioTracks();
97-
if (audioTracks !== undefined && audioTracks.length > 0) {
98-
self._remoteAudioStream = remoteStream;
99-
self._remoteAudioElement.srcObject = remoteStream;
100+
window.CitrixWebRTC.mapAudioElement(self._remoteAudioElement);
101+
if (evt.streams.length > 1) {
102+
self._logger.warn('Found more than 1 streams for ' + evt.track.kind + ' track ' + evt.track.id + ' : ' +
103+
evt.streams.map(stream => stream.id).join(','));
104+
}
105+
if (evt.track.kind === 'video' && self._remoteVideoElement) {
106+
self._remoteVideoElement.srcObject = evt.streams[0];
107+
self._remoteVideoStream = evt.streams[0];
108+
} else if (evt.track.kind === 'audio' && self._remoteAudioElement) {
109+
self._remoteAudioElement.srcObject = evt.streams[0];
110+
self._remoteAudioStream = evt.streams[0];
100111
}
112+
self._remoteAudioElement.play();
101113
}
102114

103115
_buildMediaConstraints(self, mediaConstraints) {

src/js/strategies/StandardStrategy.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import CCPInitiationStrategyInterface from "./CCPInitiationStrategyInterface";
22
import {CHROME_SUPPORTED_VERSION, RTC_ERRORS} from "../rtc_const";
3-
import {getChromeBrowserVersion, hitch, isChromeBrowser} from "../utils";
3+
import {getChromeBrowserVersion, isChromeBrowser} from "../utils";
44
import {FailedState} from "../rtc_session";
55

66
export default class StandardStrategy extends CCPInitiationStrategyInterface {
@@ -69,10 +69,6 @@ export default class StandardStrategy extends CCPInitiationStrategyInterface {
6969
return new RTCPeerConnection(configuration, optionalConfiguration);
7070
}
7171

72-
connect(self) {
73-
self._pc.ontrack = hitch(self, self._ontrack);
74-
}
75-
7672
_ontrack(self, evt) {
7773
if (evt.streams.length > 1) {
7874
self._logger.warn('Found more than 1 streams for ' + evt.track.kind + ' track ' + evt.track.id + ' : ' +

test/unit/rtc_peer_connection_factory.js

+1-24
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import './test-setup';
88
import RtcPeerConnectionFactory from '../../src/js/rtc_peer_connection_factory';
99
import chai from 'chai';
10-
import sinon, {sandbox} from 'sinon';
10+
import sinon from 'sinon';
1111
import {RTC_PEER_CONNECTION_IDLE_TIMEOUT_MS} from "../../src/js/rtc_const";
1212
import StandardStrategy from "../../src/js/strategies/StandardStrategy";
13-
import CitrixVDIStrategy from "../../src/js/strategies/CitrixVDIStrategy";
1413

1514
describe('RTC Peer Connection Factory', () => {
1615

@@ -74,26 +73,4 @@ describe('RTC Peer Connection Factory', () => {
7473
chai.assert.isNull(pcFactory._idleRtcPeerConnectionTimerId);
7574
});
7675
});
77-
78-
describe('CitrixStrategy', () => {
79-
80-
afterEach(() => {
81-
sandbox.restore();
82-
});
83-
84-
it('uses CitrixVDIStrategy', async () => {
85-
sandbox.stub(window.CitrixWebRTC, 'isFeatureOn').returns(true);
86-
global.connect.getLog = sandbox.stub();
87-
new RtcPeerConnectionFactory(console, null, null, requestAccessStub, sandbox.stub(), new CitrixVDIStrategy());
88-
chai.assert(console.log.calledWith('CitrixVDIStrategy initialized'));
89-
});
90-
91-
it('throws error when isCitrixWebRTCSupported returns false', async () => {
92-
sandbox.stub(window.CitrixWebRTC, 'isFeatureOn').returns(false);
93-
chai.expect(() => {
94-
new RtcPeerConnectionFactory(console, null, null, requestAccessStub, sandbox.stub(), new CitrixVDIStrategy());
95-
}).to.throw('Citrix WebRTC redirection feature is NOT supported!');
96-
});
97-
98-
});
9976
});

test/unit/rtc_session.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import { RTCSessionState, GrabLocalMediaState, CreateOfferState, SetLocalSession
1010
import { RTC_ERRORS } from '../../src/js/rtc_const';
1111
import { BusyException, CallNotFoundException } from '../../src/js/exceptions';
1212
import chai from 'chai';
13-
import sinon, {sandbox} from 'sinon';
13+
import sinon from 'sinon';
1414
import StandardStrategy from "../../src/js/strategies/StandardStrategy";
15-
import CitrixVDIStrategy from "../../src/js/strategies/CitrixVDIStrategy";
1615

1716
describe('RTC session', () => {
1817
describe('session object', () => {
@@ -32,26 +31,6 @@ describe('RTC session', () => {
3231
chai.expect(session.callId).to.match(/^[-A-Fa-f0-9]{36}$/);
3332
});
3433
});
35-
36-
describe('CitrixVDIStrategy', () => {
37-
afterEach(() => {
38-
sandbox.restore();
39-
});
40-
41-
it('uses CitrixVDIStrategy', async () => {
42-
sandbox.stub(window.CitrixWebRTC, 'isFeatureOn').returns(true);
43-
global.connect.getLog = sandbox.stub();
44-
new RtcSession('wss://amazon-connect-rtc-server.amazonaws.com/', [], 'contactToken', console, null, null, null, new CitrixVDIStrategy());
45-
chai.assert(console.log.calledWith('CitrixVDIStrategy initialized'));
46-
});
47-
48-
it('throws error when isCitrixWebRTCSupported returns false', async () => {
49-
sandbox.stub(window.CitrixWebRTC, 'isFeatureOn').returns(false);
50-
chai.expect(() => {
51-
new RtcSession('wss://amazon-connect-rtc-server.amazonaws.com/', [], 'contactToken', console, null, null, null, new CitrixVDIStrategy());
52-
}).to.throw('Citrix WebRTC redirection feature is NOT supported!');
53-
});
54-
})
5534
});
5635

5736
describe('RTCSessionState', () => {
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import sinon, { sandbox } from 'sinon';
2+
import chai from 'chai';
3+
import CitrixVDIStrategy from '../../../src/js/strategies/CitrixVDIStrategy.js';
4+
5+
describe('CitrixVDIStrategy', () => {
6+
beforeEach(() => {
7+
global.window = {
8+
CitrixWebRTC: {
9+
setVMEventCallback: sandbox.stub(),
10+
isFeatureOn: sandbox.stub(),
11+
initUCSDK: sandbox.stub(),
12+
initLog: sandbox.stub(),
13+
},
14+
getCitrixWebrtcRedir: null,
15+
};
16+
global.connect = { getLog: sandbox.stub() };
17+
});
18+
19+
afterEach(() => {
20+
sandbox.restore();
21+
delete global.window;
22+
delete global.connect;
23+
});
24+
25+
it('should initialize CitrixWebRTC, getCitrixWebrtcRedir, and logging successfully', () => {
26+
const instance = new CitrixVDIStrategy(false);
27+
global.window.CitrixWebRTC.isFeatureOn= sandbox.stub().returns(true);
28+
chai.expect(global.window.CitrixWebRTC.setVMEventCallback).to.have.been.calledOnce;
29+
chai.expect(global.window.getCitrixWebrtcRedir).to.be.a('function');
30+
chai.expect(global.window.CitrixWebRTC.initLog).to.have.been.calledOnce;
31+
32+
const callback = global.window.CitrixWebRTC.setVMEventCallback.getCall(0).args[0];
33+
callback({ event: 'vdiClientConnected' });
34+
chai.assert(console.log.calledWith('CitrixVDIStrategy initialized'));
35+
36+
callback({ event: 'vdiClientDisconnected' });
37+
chai.assert(console.log.calledWith('vdiClientDisconnected'));
38+
39+
chai.expect(global.window.getCitrixWebrtcRedir).to.be.a('function');
40+
global.window.getCitrixWebrtcRedir().then((result) => {
41+
chai.expect(result).to.equal(1);
42+
});
43+
44+
chai.assert(global.window.CitrixWebRTC.initLog.calledWith(global.connect.getLog()));
45+
});
46+
47+
it('should throw an error if WebRTC redirection feature is not supported', () => {
48+
const instance = new CitrixVDIStrategy(false);
49+
global.window.CitrixWebRTC.isFeatureOn= sandbox.stub().returns(false);
50+
const callback = global.window.CitrixWebRTC.setVMEventCallback.getCall(0).args[0];
51+
chai.expect(() => callback({ event: 'vdiClientConnected' })).to.throw(
52+
'Citrix WebRTC redirection feature is NOT supported!'
53+
);
54+
});
55+
56+
});

0 commit comments

Comments
 (0)