|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | import CCPInitiationStrategyInterface from "./CCPInitiationStrategyInterface";
|
6 |
| -import {hitch} from "../utils"; |
7 | 6 | import {FailedState} from "../rtc_session";
|
8 | 7 | import {RTC_ERRORS} from "../rtc_const";
|
9 |
| -import "@citrix/ucsdk/CitrixWebRTC"; |
10 | 8 |
|
11 | 9 | export default class CitrixVDIStrategy extends CCPInitiationStrategyInterface {
|
12 | 10 |
|
13 |
| - constructor() { |
| 11 | + constructor(useRealCitrix = true) { |
14 | 12 | 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"); |
28 | 15 | }
|
| 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() { |
29 | 40 | window.CitrixWebRTC.initLog(global.connect.getLog());
|
30 |
| - console.log("CitrixVDIStrategy initialized"); |
31 | 41 | }
|
32 | 42 |
|
33 | 43 | // the following functions are rtc_peer_connection_factory related functions
|
@@ -86,18 +96,20 @@ export default class CitrixVDIStrategy extends CCPInitiationStrategyInterface {
|
86 | 96 | return new window.CitrixWebRTC.CitrixPeerConnection(configuration, optionalConfiguration);
|
87 | 97 | }
|
88 | 98 |
|
89 |
| - connect(self) { |
90 |
| - self._pc.onaddstream = hitch(self, self._ontrack); |
91 |
| - } |
92 |
| - |
93 | 99 | _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]; |
100 | 111 | }
|
| 112 | + self._remoteAudioElement.play(); |
101 | 113 | }
|
102 | 114 |
|
103 | 115 | _buildMediaConstraints(self, mediaConstraints) {
|
|
0 commit comments