-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXPMobileSDK.js
2453 lines (2254 loc) · 121 KB
/
XPMobileSDK.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @namespace
* @property {object} XPMobileSDKSettings - The default values for settings.
* @property {string} XPMobileSDKSettings.fileName - Name of the main file
* @property {string} XPMobileSDKSettings.clientType - Client type
* @property {string} XPMobileSDKSettings.communicationChanel - URL path of communication channel
* @property {string} XPMobileSDKSettings.videoChanel - URL path of video channel
* @property {string} XPMobileSDKSettings.audioChannel - URL path of audio channel
* @property {string} XPMobileSDKSettings.MobileServerURL - URL of Mobile Server
* @property {string} XPMobileSDKSettings.defaultEncryptionPadding - default Encryption Padding
* @property {number} XPMobileSDKSettings.primeLength - prime length
* @property {number} XPMobileSDKSettings.videoConnectionTimeout - video connection timeout
* @property {number} XPMobileSDKSettings.resamplingFactor - resampling factor
* @property {number} XPMobileSDKSettings.liveMessageMinimumInterval - live message minimum interval
* @property {number} XPMobileSDKSettings.socketRestartMinimumInterval - socket restart minimum interval
* @property {number} XPMobileSDKSettings.videoStreamRestartMinimumInterval - video stream restart minimum interval
* @property {boolean} XPMobileSDKSettings.supportsMultiThreaded - Flag indicating whether Multi thread is enabled
* @property {boolean} XPMobileSDKSettings.supportsCarousels - Flag indicating whether Carousels is enabled
* @property {boolean} XPMobileSDKSettings.supportsCHAP - Flag indicating whether CHAP is enabled
* @property {boolean} XPMobileSDKSettings.DirectStreaming - Flag indicating whether Direct streaming is enabled
* @property {boolean} XPMobileSDKSettings.SupportsAudioIn - Flag indicating whether Audio In is enabled
* @property {boolean} XPMobileSDKSettings.SupportsAudioOut - Flag indicating whether Audio Out is enabled
* @property {number} XPMobileSDKSettings.AudioCompressionLevel - Audio Compression Level when using browsers build in audio player
* @property {number} XPMobileSDKSettings.AudioCompressionLevelAudioAPI - Audio Compression Level when using Web Audio API
* @property {number} XPMobileSDKSettings.NoVideoTimeout - No Video Timeout
* @property {boolean|string} XPMobileSDKSettings.EnableConsoleLog - possible values: true, false, "error", "warn", "info", "log". "log", "info" and true are basically the same. All other values will be interpreted as true.
* @property {boolean} XPMobileSDKSettings.SupportsAdaptiveStreaming - Flag indicating whether Adaptive Streaming is enabled
*/
var XPMobileSDKSettings = {
fileName: 'XPMobileSDK.js',
clientType: 'WebClient',
communicationChanel: '/XProtectMobile/Communication',
videoChanel: '/XProtectMobile/Video',
audioChannel: '/XProtectMobile/Audio',
MobileServerURL: '',
defaultEncryptionPadding: 'Iso10126',
primeLength: 2048,
videoConnectionTimeout: 20000,
resamplingFactor: 1 / 1000000,
liveMessageMinimumInterval: 1000,
socketRestartMinimumInterval: 1000,
videoStreamRestartMinimumInterval: 20000,
supportsMultiThreaded: false,
supportsCarousels: false,
supportsCHAP: true,
DirectStreaming: true,
DiagnosticsLayout: true,
SupportsAudioIn: true,
SupportsAudioOut: true,
AudioCompressionLevel: 99,
AudioCompressionLevelAudioAPI: 41,
NoVideoTimeout: 5000,
EnableConsoleLog: true,
SupportsAdaptiveStreaming: true,
enablePlaybackAudioSourceSelection: true,
includes: [
/* [MINIFY_JS] */
'Lib/tools/logger.js',
'Lib/tools/polyfills.js',
'Lib/tools/webStorage.js',
'Lib/security/BigInt.js',
'Lib/security/Base64.js',
'Lib/security/AES.js',
'Lib/security/SHA256.js',
'Lib/security/SHA512.js',
'Lib/security/SecureString.js',
'Lib/security/CHAP.js',
'Lib/security/Challenge.js',
'Lib/security/DiffieHellman.js',
'Lib/security/ISO10126.js',
'Lib/security/PKCECode.js',
'Lib/communication/Ajax.js',
'Lib/communication/Bytes.js',
'Lib/communication/NetworkConfig.js',
'Lib/communication/CommunicationStability.js',
'Lib/Connection.js',
'Lib/ConnectionRequest.js',
'Lib/ConnectionResponse.js',
'Lib/PullConnection.js',
'Lib/PushConnection.js',
'Lib/VideoConnection.js',
'Lib/VideoStream.js',
'Lib/ItemHeaderParser.js',
'Lib/VideoHeaderParser.js',
'Lib/AudioHeaderParser.js',
'Lib/VideoConnectionPool.js',
'Lib/VideoPushConnection.js',
'Lib/AudioPushConnection.js',
'Lib/AudioAvailability.js'
/* [/MINIFY_JS] */
]
};
var XPMobileSDK = new function () {
this.onLoad = function () { };
this.library = {};
this.interfaces = {};
this.features = {};
this.initialize = initializeConnection;
this.isLoaded = isLoaded;
this.addObserver = addObserver;
this.removeObserver = removeObserver;
this.cancelRequest = cancelRequest;
this.connect = connect;
this.Connect = Connect;
this.connectWithId = connectWithId;
this.login = login;
this.Login = Login;
this.externalLogin = externalLogin;
this.ExternalLogin = ExternalLogin;
this.requestCode = requestCode;
this.verifyCode = verifyCode;
this.disconnect = disconnect;
this.Disconnect = Disconnect;
this.LiveMessage = LiveMessage;
this.getAllViews = getAllViews;
this.getAllCameras = getAllCameras;
this.getViews = getViews;
this.requestStream = requestStream;
this.RequestStream = RequestStream;
this.RequestAudioStream = RequestAudioStream;
this.requestAudioStream = requestAudioStream;
this.requestPushStream = requestPushStream;
this.RequestAudioStreamIn = RequestAudioStreamIn;
this.requestAudioStreamIn = requestAudioStreamIn;
this.changeStream = changeStream;
this.ChangeStream = ChangeStream;
this.closeStream = closeStream;
this.closeAudioStream = closeAudioStream;
this.CloseStream = CloseStream;
this.createVideoPushConnection = createVideoPushConnection;
this.createAudioPushConnection = createAudioPushConnection;
this.motionDetection = motionDetection;
this.getPtzPresets = getPtzPresets;
this.ptzPreset = ptzPreset;
this.ptzMove = ptzMove;
this.ptzTapAndHold = ptzTapAndHold;
this.ptzSwipe = ptzSwipe;
this.playbackSpeed = playbackSpeed;
this.playbackSeek = playbackSeek;
this.playbackGoTo = playbackGoTo;
this.getThumbnail = getThumbnail;
this.getThumbnailByTime = getThumbnailByTime;
this.getDBStartTime = getDBStartTime;
this.getNextSequence = getNextSequence;
this.getPrevSequence = getPrevSequence;
this.getSequencesInInterval = getSequencesInInterval;
this.getSequencesForView = getSequencesForView;
this.getUserExports = getUserExports;
this.getAllExports = getAllExports;
this.getExport = getExport;
this.createExportDownloadLink = createExportDownloadLink;
this.getOutputsAndEvents = getOutputsAndEvents;
this.getServerStatus = getServerStatus;
this.triggerOutputOrEvent = triggerOutputOrEvent;
this.getCameraCapabilities = getCameraCapabilities;
this.requestChallenges = requestChallenges;
this.createPlaybackController = createPlaybackController;
this.changeMultipleStreams = changeMultipleStreams;
this.getAllInvestigations = getAllInvestigations;
this.getUserInvestigations = getUserInvestigations;
this.getInvestigation = getInvestigation;
this.createInvestigation = createInvestigation;
this.updateInvestigation = updateInvestigation;
this.updateInvestigationData = updateInvestigationData;
this.deleteInvestigation = deleteInvestigation;
this.cancelInvestigation = cancelInvestigation;
this.startInvestigationExport = startInvestigationExport;
this.deleteInvestigationExport = deleteInvestigationExport;
this.getAlarmList = getAlarmList;
this.getAlarm = getAlarm;
this.updateAlarm = updateAlarm;
this.getAlarmDataSettings = getAlarmDataSettings;
this.getAlarmUsers = getAlarmUsers;
this.acknowledgeAlarm = acknowledgeAlarm;
this.GetBookmarks = GetBookmarks;
this.getBookmarks = getBookmarks;
this.deleteBookmark = deleteBookmark;
this.prevCarouselCamera = prevCarouselCamera;
this.nextCarouselCamera = nextCarouselCamera;
this.pauseCarousel = pauseCarousel;
this.resumeCarousel = resumeCarousel;
this.registerForNotifications = registerForNotifications;
this.RegisterForNotifications = RegisterForNotifications;
this.CreateBookmark = CreateBookmark;
this.UpdateBookmark = UpdateBookmark;
this.RequestBookmarkCreation = RequestBookmarkCreation;
this.getResamplingFactor = getResamplingFactor;
this.toggleDirectStreaming = toggleDirectStreaming;
this.toggleDiagnosticsOverlay = toggleDiagnosticsOverlay;
this.toggleAnalytics = toggleAnalytics;
this.sendCommand = sendCommand;
this.destroy = destroy;
var onLoad = function () { this.onLoad(); }.bind(this);
var loaded = false;
var head, path;
initialize();
function initialize() {
var script = document.querySelector('script[src$="' + XPMobileSDKSettings.fileName + '"]');
path = script.src.replace(RegExp(XPMobileSDKSettings.fileName + '.*$'), '');
head = document.querySelector('head');
load(XPMobileSDKSettings.includes.slice());
}
/**
* Loads all scripts from a queue
*
* @method load
* @param {Array} queue - Array containing all script for loading
*/
function load(queue) {
var url = path + queue.shift();
var script = document.createElement('script');
script.addEventListener('load', function () {
if (queue.length) {
load(queue);
}
else {
loadComplete();
}
});
script.addEventListener('error', function () {
console.error('Script load error!');
});
script.src = url;
head.appendChild(script);
}
/**
* Called when all scripts are loaded
*
* @method loadComplete
*/
function loadComplete() {
XPMobileSDK.library.Connection = new Connection();
XPMobileSDK.library.CHAP.initialize();
XPMobileSDK.library.Connection.initialize(XPMobileSDK.localStorage);
loaded = true;
onLoad();
}
/**
* Initializes the Connection singleton. Must be called before using any of the other methods.
*
* @method initializeConnection
* @param {Object} [storage] - (optional) the storage used to store server features in,
* and to initialize them from
* (for example XPMobileSDK.localStorage, XPMobileSDK.sessionStorage,
* or any object implementing their methods).
* The server features are retrieved on login.
* The idea is to keep the connection state if you want to connectWithId,
* but it may be cleared on some cases (browser refresh for example).
*/
function initializeConnection(storage) {
XPMobileSDK.library.Connection.initialize(storage);
}
function isLoaded() {
return loaded;
}
/**
* Adds an observer to the Connection singleton.
*
* @method addObserver
* @param {Object} observer - an arbitrary object implementing the ConnectionObserverInterface interface
* @see ConnectionObserverInterface
*/
function addObserver(observer) {
XPMobileSDK.library.Connection.addObserver(observer);
}
/**
* Removes an existing observer from the Connection singleton.
*
* @method removeObserver
* @param {Object} observer - an arbitrary object implementing the ConnectionObserverInterface interface
* @see ConnectionObserverInterface
*/
function removeObserver(observer) {
XPMobileSDK.library.Connection.removeObserver(observer);
}
/**
* Cancels a request.
*
* @method cancelRequest
* @param {ConnectionRequest} request - the ConnectionRequest object, returned by the method used to create it
*/
function cancelRequest(request) {
XPMobileSDK.library.Connection.cancelRequest(request);
}
/**
* Sends a Connect connection command to establish a new connection with a server.
* The changes of the connect status are propagated to all listeners through the ConnectionObserver interface methods.
* Listeners implementing the ConnectionObserver interface methods are added with the addObserver method.
*
* @method connect
* @param {String} server - server name or IP address
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function connect(server) {
if (server) {
XPMobileSDK.library.Connection.server = server;
}
return new Connect(null);
}
/**
* Initiates connection to the Mobile Server. Two limitations are introduced:
* MaximumConnectionAllowed and ConnectionTimeout between Connect and Login.
* They are set from the GeneralSetting section in config file
*
* @method Connect
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} EncryptionPadding - (optional) Padding scheme that will be used
* when encrypting/decrypting shared key.
* Default is PKCS7. Currently supported values are PKCS7 and ISO10126.
* - {Number} PrimeLength - (optional) The length of the prime module in bits.
* Default is 1024. Currently supported values are 1024 and 2048
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages
* should be sent from server while processing the request. Default is Yes.
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function Connect(params, successCallback, failCallback) {
params = params || {};
params.PublicKey = XPMobileSDK.library.Connection.dh.createPublicKey();
if (XPMobileSDKSettings.primeLength) {
params.PrimeLength = XPMobileSDKSettings.primeLength;
}
if (XPMobileSDKSettings.defaultEncryptionPadding) {
params.EncryptionPadding = XPMobileSDKSettings.defaultEncryptionPadding.toUpperCase();
}
var connectionRequest = XPMobileSDK.library.Connection.Connect(params, successCallback, failCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Tries to reestablish an existing connection with a server by using an existing connection id.
* The changes of the connect status are propagated to all listeners through the ConnectionObserver interface methods.
* Listeners implementing the ConnectionObserver interface methods are added with the addObserver method.
*
* @method connectWithId
* @param {String} server - server name or IP address
* @param {String} connectionId - connection id
* @param {String} serverId - server id
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function connectWithId(server, connectionId, serverId) {
XPMobileSDK.library.Connection.connectWithId(server, connectionId, serverId);
}
/**
* Sends a LogIn connection command to log a user with valid usernam and password.
* The changes of the login status are propagated to all listeners through the ConnectionObserver interface methods.
* Listeners implementing the ConnectionObserver interface methods are added with the addObserver method.
*
* @method login
* @param {String} username - username
* @param {String} password - password
* @param {String} loginType - loginType
* @param {Object} parameters - other parameters. May contain:
* <pre>
*
* - {Number} NumChallenges - Number of challenges the MoS should return.
* Up to 100 can be requested at once.
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages
* should be sent from server while processing the request. Default is Yes.
* - {String} SupportsResampling - (optional) [Yes/No] When present and equal to
* "Yes", indicates that the client can handle
* downsized images. This instructs Quality of
* Service to reduce the size of the sent images
* as additional measure in cases of low bandwidth.
* - {String} SupportsExtendedResamplingFactor - (optional) [Yes/No] When present and equal to
* "Yes", indicates that client supports working
* with decimal resampling factor. Influence on
* the type of ResamplingTag received in Header
* Extension Flags of Video frame
*
* </pre>
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function login(username, password, loginType, parameters) {
parameters = parameters || {};
parameters.Username = username;
parameters.Password = password;
if (loginType) {
parameters.LoginType = loginType;
}
return new Login(parameters);
}
/**
* Sends a low level Login command to the server.
*
* @method Login
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} Username - Name of the connection user.
* - {String} Password - Password for the certain user.
* - {String} LoginType - Authentication login type.
* - {Number} NumChallenges - Number of challenges the MoS should return.
* Up to 100 can be requested at once.
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages
* should be sent from server while processing the request. Default is Yes.
* - {String} SupportsResampling - (optional) [Yes/No] When present and equal to
* "Yes", indicates that the client can handle
* downsized images. This instructs Quality of
* Service to reduce the size of the sent images
* as additional measure in cases of low bandwidth.
* - {String} SupportsExtendedResamplingFactor - (optional) [Yes/No] When present and equal to
* "Yes", indicates that client supports working
* with decimal resampling factor. Influence on
* the type of ResamplingTag received in Header
* Extension Flags of Video frame
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function Login(params, successCallback, failCallback) {
params = params || {};
if (XPMobileSDK.library.Connection.PublicKey) {
params.Username = XPMobileSDK.library.Connection.dh.encodeString(params.Username);
params.Password = XPMobileSDK.library.Connection.dh.encodeString(params.Password);
}
if (XPMobileSDKSettings.supportsCHAP && XPMobileSDK.library.Connection.CHAPSupported === 'Yes') {
// Take 100 challenges to start with
params.NumChallenges = params.NumChallenges || 100;
}
params.SupportsResampling = params.SupportsResampling || 'Yes';
params.SupportsExtendedResamplingFactor = params.SupportsExtendedResamplingFactor || 'Yes';
if (XPMobileSDKSettings.supportsCarousels) {
params.SupportsCarousel = params.SupportsCarousel || 'Yes';
}
if (XPMobileSDKSettings.clientType) {
params.ClientType = params.ClientType || XPMobileSDKSettings.clientType;
}
var connectionRequest = XPMobileSDK.library.Connection.Login(params, successCallback, failCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Sends a LogIn connection command to log a user with valid idpClientId, identityToken, accessToken and RefreshToken.
* The changes of the login status are propagated to all listeners through the ConnectionObserver interface methods.
* Listeners implementing the ConnectionObserver interface methods are added with the addObserver method.
*
* @method login
* @param {String} idpClientId - idpClientId
* @param {String} identityToken - identityToken
* @param {String} accessToken - accessToken
* @param {String} RefreshToken - RefreshToken
* @param {String} loginType - loginType
* @param {Object} parameters - other parameters. May contain:
* <pre>
*
* - {Number} NumChallenges - Number of challenges the MoS should return.
* Up to 100 can be requested at once.
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages
* should be sent from server while processing the request. Default is Yes.
* - {String} SupportsResampling - (optional) [Yes/No] When present and equal to
* "Yes", indicates that the client can handle
* downsized images. This instructs Quality of
* Service to reduce the size of the sent images
* as additional measure in cases of low bandwidth.
* - {String} SupportsExtendedResamplingFactor - (optional) [Yes/No] When present and equal to
* "Yes", indicates that client supports working
* with decimal resampling factor. Influence on
* the type of ResamplingTag received in Header
* Extension Flags of Video frame
*
* </pre>
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function externalLogin(idpClientId, identityToken, accessToken, refreshToken, loginType, parameters) {
parameters = parameters || {};
parameters.IdpClientId = idpClientId;
parameters.IdentityToken = identityToken;
parameters.AccessToken = accessToken;
parameters.RefreshToken = refreshToken;
parameters.LoginType = loginType;
return new ExternalLogin(parameters);
}
/**
* Sends a low level Login command to the server.
*
* @method ExternalLogin
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} IdpClientId - Name of the client IDP
* - {String} IdentityToken - Identity toke provider from 3rd party login
* - {String} AccessToken - Access token provider from 3rd party login
* - {String} RefreshToken - Refresh token provider from 3rd party login
* - {String} LoginType - Authentication login type.
* - {Number} NumChallenges - Number of challenges the MoS should return.
* Up to 100 can be requested at once.
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages
* should be sent from server while processing the request. Default is Yes.
* - {String} SupportsResampling - (optional) [Yes/No] When present and equal to
* "Yes", indicates that the client can handle
* downsized images. This instructs Quality of
* Service to reduce the size of the sent images
* as additional measure in cases of low bandwidth.
* - {String} SupportsExtendedResamplingFactor - (optional) [Yes/No] When present and equal to
* "Yes", indicates that client supports working
* with decimal resampling factor. Influence on
* the type of ResamplingTag received in Header
* Extension Flags of Video frame
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function ExternalLogin(params, successCallback, failCallback) {
if (XPMobileSDKSettings.supportsCHAP && XPMobileSDK.library.Connection.CHAPSupported === 'Yes') {
// Take 100 challenges to start with
params.NumChallenges = params.NumChallenges || 100;
}
params.SupportsResampling = params.SupportsResampling || 'Yes';
params.SupportsExtendedResamplingFactor = params.SupportsExtendedResamplingFactor || 'Yes';
if (XPMobileSDKSettings.supportsCarousels) {
params.SupportsCarousel = params.SupportsCarousel || 'Yes';
}
if (XPMobileSDKSettings.clientType) {
params.ClientType = params.ClientType || XPMobileSDKSettings.clientType;
}
var connectionRequest = XPMobileSDK.library.Connection.Login(params, successCallback, failCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Sends a RequestSecondStepAuthenticationPin connection command after successful login with a valid username and password.
* This method is used only if the server has called the connectionRequiresCode method of the ConnectionObserver interface.
*
* @method requestCode
* @param {Function} successCallback - function that is called when the command execution was successful.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function requestCode(successCallback, errorCallback) {
return XPMobileSDK.library.Connection.requestCode(successCallback, errorCallback);
}
/**
* Sends a RequestSecondStepAuthenticationPin connection command after successful login with a valid username and password.
* This method is used only if the server has called the connectionRequiresCode method of the ConnectionObserver interface.
*
* @method verifyCode
* @param {String} code - second step authentication pin code
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function verifyCode(code) {
return XPMobileSDK.library.Connection.verifyCode(code);
}
/**
* Sends a Disconnect connection command and logs out the current user.
*
* @method disconnect
*/
function disconnect() {
logger.error("disconnect");
XPMobileSDK.library.Connection.Disconnect();
}
/**
* Sends a Disconnect connection command and logs out the current user.
* (Stops all the open video communication channels, removes ConnectionId from the internal resolving mechanism)
*
* @method Disconnect
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} ConnectionId - Connection ID retrieved from Connect command
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing
* messages should be sent from server while
* processing the request. Default depends on the
* value in connect command.
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*/
function Disconnect(params, successCallback, failCallback) {
logger.error("Disconnect");
XPMobileSDK.library.Connection.Disconnect(params, successCallback, failCallback);
}
/**
* Sends a LiveMessage command to the server indicating that the client is up and running. Client needs to send that command at least once in the watch dog interval which is 30 seconds by default.
* Recomented interval is 80% of whach dog = 80*30/100 = 24
*
* @example setInterval(function(){XPMobileSDK.LiveMessage()}, 24000);
*
* @method LiveMessage
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} ConnectionId - Connection ID retrieved from Connect command
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing
* messages should be sent from server while
* processing the request. Default depends on the
* value in connect command.
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*/
function LiveMessage(params, successCallback, failCallback) {
XPMobileSDK.library.Connection.LiveMessage(params, successCallback, failCallback);
}
/**
* Sends a GetAllViewsAndCameras connection command to get the full tree of views starting from the root.
*
* @method getAllViews
* @param {Function} successCallback - function that is called when the command execution was successful and a views object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function getAllViews(successCallback, errorCallback) {
var connectionRequest = XPMobileSDK.library.Connection.getAllViews(successCallback, errorCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
*
* @method getAllCameras
* @param {Function} successCallback - function that is called when the command execution was successful and a camera object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function getAllCameras(successCallback, errorCallback) {
var connectionRequest = XPMobileSDK.library.Connection.getAllCameras(successCallback, errorCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Sends a GetViews connection command to get the sub-views of any view using its id.
*
* @method getViews
* @param {String} viewId - view id
* @param {Function} successCallback - function that is called when the command execution was successful and a view object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function getViews(viewId, successCallback, errorCallback) {
var connectionRequest = XPMobileSDK.library.Connection.getViews(viewId, successCallback, errorCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Sends a RequestStream connection command to get the live/playback video stream of a camera as a VideoConnection object from the server.
*
* @method requestStream
* @param {String} cameraId - unique GUID of the camera that should be started
* @param {VideoConnectionSize} size - output stream size
* @param {VideoConnectionOptions} options - optional, optional configuration. May contain:
* <pre>
* - {String} signal - Type of the requested signal - Live, Playback or Upload.
* - {String} streamType - Shows if this is a transcoded or a direct stream.
* Possible values - Native and Transcoded.
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and a VideoConnection object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function requestStream(cameraId, size, options, successCallback, errorCallback) {
var connectionRequest = XPMobileSDK.library.Connection.requestStream(cameraId, size, options, successCallback, errorCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Starts live, payback or push video session for a particular device.
*
* @method RequestStream
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} ConnectionId - Connection ID retrieved from Connect command
* - {String} StreamType - Shows if this is a transcoded or a direct stream.
* Possible values - Native and Transcoded. Missing
* of this will be interpreted as Transcoded. (backward compatibility)
* - {String} ByteOrder - LittleEndian/Network. Missing of this will be
* interpreted as LittleEndian for Transcoded,
* StreamType and Network for Native StreamType.
* - {String} CameraId - ID of the camera, which stream is requested (GUID)
* - {Number} DestWidth - Width of the requested video (in pixels)
* - {Number} DestHeight - Height of the requested video (in pixels)
* - {Number} Fps - Frame-rate of the requested video (frames per second)
* - {Number} ComprLevel - Compression level of the received JPEG images (1 - 100)
* - {String} SignalType - Type of the requested signal - Live, Playback or Upload.
* - {String} MethodType - Type of the method for retrieving video data - Push or Pull
* - {String} KeyFramesOnly - Yes/No (everything different than Yes is interpreted as No)
* - reduces stream quality by transcoding only Key (I) frames,
* if option is enabled in the Management Plug-in.
* - {String} TImeRestrictionStart - (optional) Start time stamp of restriction period given as milliseconds since Unix EPOCH
* - {String} TimeRestrictionEnd - (optional) End time stamp of restriction period given as milliseconds since Unix EPOCH
* - {String} MotionOverlay - (reserved) No/Yes
* - {String} RequestSize - (optional) [Yes/No] - If value of the field is Yes, Size header extension
* is sent with every frame. Otherwise it is sent only on size change.
* Missing of paramter is interpreted as No.
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing
* messages should be sent from server while
* processing the request. Default is Yes.
* - {String} SeekType - (optional) Makes seek of specific type: DbStart,
* DbEnd, PrevSeq, NextSeq, PrevFrame, NextFrame, Time, TimeOrBefore,
* TimeOrAfter, TimeAfter, TimeBefore.
* - {String} Time - (optional) Time of playback speed (in milliseconds
* since Unix epoch). Valid if SeekType == Time.
* - {String} UserInitiatedDownsampling - (optional) [Yes/No] When present and equal to
* "Yes", indicates that the client requires all sent images to
* be downsized at least by two (half the
* requested width and height). SupportsResampling
* must be set explicitly to "Yes".
* - {String} PlaybackControllerId - (optional) Id of the playback controller used for common playback control.
* Received from "CreatePlaybackController" command.
* When present and not equal to empty string, indicates
* that the client requires playback controller to be used,
* shared between few playback streams. Valid only if "SignalType" is set to Playback.
* If does not present - single playback stream is created. If set to
* id of the existing in the server controller - this playback stream is attached to it.
* If set to invalid id - error is returned (unknown item id - 21).
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*/
function RequestStream(params, successCallback, failCallback) {
XPMobileSDK.library.Connection.RequestStream(params, successCallback, failCallback);
}
/**
* Starts live, playback audio session for a particular device.
*
* @method RequestAudioStream
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} ConnectionId - Connection ID retrieved from Connect command
* - {String} StreamType - Shows if this is a transcoded or a direct stream.
* Possible values - Transcoded. Missing
* of this will be interpreted as Transcoded. (backward compatibility)
* - {String} ItemId - ID of the microphone, which stream is requested (GUID)
* - {Number} ComprLevel - Compression level of the received Audio (1 - 100)
* - {String} SignalType - Type of the requested signal - Live, Playback or Upload.
* - {String} MethodType - Type of the method for retrieving video data - Push or Pull
* - {String} StreamDataType - "Audio"
* - {String} AudioEncoding - Shows the encoding of the output. Possible values - Pcm, Mp3.
* - {String} CloseConnectionOnError - (optional) Yes/No - decide what to do with the connection channel on error.
* - {String} PlaybackControllerId - (optional) Id of the playback controller used for common playback control.
* Use an ID of a video stream with which the audio source is associated.
* When present and not equal to empty string, indicates that the client requires playback
* controller to be used, shared between the audio and video playback streams.
* Valid only if "SignalType" is set to Playback. If not present - no playback audio stream is created.
* If set to invalid id - error is returned (unknown item id - 21).
* - {String} ByteOrder - LittleEndian/Network. Missing of this will be interpreted as LittleEndian for Transcoded StreamType and Network for Native StreamType.
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*/
function RequestAudioStream(params, successCallback, failCallback) {
XPMobileSDK.library.Connection.RequestAudioStream(params, successCallback, failCallback);
}
/**
* Sends a RequestAudioStream connection command to get the live/playback video stream of a camera as a VideoConnection object from the server.
*
* @method requestAudioStream
* @param {String} cameraId - unique GUID of the microphone that should be started
* @param {AudioConnectionOptions} options - optional, optional configuration. May contain:
* <pre>
* - {String} signal - Type of the requested signal - Live, Playback.
* - {int} compressionLevel
* - {boolean} reuseConnection - if true, the API will reuse existing connections for the same microphone
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and a VideoConnection object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function requestAudioStream(microphoneId, options, successCallback, errorCallback) {
var connectionRequest = XPMobileSDK.library.Connection.requestAudioStream(microphoneId, options, successCallback, errorCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Sends a RequestStream connection command to get an upstream for video push to the server.
*
* @method requestPushStream
* @param {Function} successCallback - function that is called when the command execution was successful and a stream parameters object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function requestPushStream(successCallback, errorCallback) {
return XPMobileSDK.library.Connection.requestPushStream(successCallback, errorCallback);
}
/**
* Sends a RequestAudioStreamIn connection command to get an upstream for audio push to the server.
*
* @method RequestAudioStreamIn
* @param {AudioConnectionOptions} params - Configuration. Should contain:
* <pre>
* - {String} itemId - Id of the item (speaker), which stream is requested (GUID)
* - {String} AudioEncoding - Shows the encoding of the output. Possible values - Pcm, Mp3.
* - {Number} AudioSamplingRate - The audio sampling rate in Hz value
* - {Number} AudioBitsPerSample - 8/16 - Audio bits per sample
* - {Number} AudioChannelsNumber - 1/2 - Number of audio channels (mon or stereo)
* - {String} StreamDataType - Shows if this is video, audio or metadata. Possible values - Video, Audio, MetaData.
* - {String} SignalType - Type of the requested signal - Live, Playback
* - {String} MethodType - Type of the method for retrieving video data - Push or Pull
* - {String} StreamHeaders - Shows available stream headers. Possible values - AllPresent, NoHeaders.
* - {String} Challenge - (only if CHAPSupproted is true) GUID previously given by the server
* - {String} ChalAnswer - (only if CHAPSupproted is true) Challenge itself plus a SHA512 hash encoded as base64
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and a stream parameters object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function RequestAudioStreamIn(params, successCallback, errorCallback) {
return XPMobileSDK.library.Connection.RequestAudioStreamIn(params, successCallback, errorCallback);
}
/**
* Sends a RequestAudioStreamIn connection command to get an upstream for audio push to the server.
*
* @method requestAudioStreamIn
* @param {String} itemId - Id of the item (speaker), which stream is requested (GUID)
* @param {AudioConnectionOptions} options - optional, optional configuration. May contain:
* <pre>
* - {Number} AudioSamplingRate - The audio sampling rate in Hz value
* - {Number} AudioBitsPerSample - 8/16 - Audio bits per sample
* - {Number} AudioChannelsNumber - 1/2 - Number of audio channels (mon or stereo)
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and a stream parameters object is passed as a parameter.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function requestAudioStreamIn(itemId, options, successCallback, errorCallback) {
return XPMobileSDK.library.Connection.requestAudioStreamIn(itemId, options, successCallback, errorCallback);
}
/**
* Sends a ChangeStream connection command to change the parameters of an existing VideoConnection.
*
* @method changeStream
* @param {VideoConnection} videoConnection - existing VideoConnection object representing a camera stream
* @param {VideoConnectionCropping} cropping - rectangle to crop from the native camera video stream
* @param {VideoConnectionSize} size - output stream size for the resulting cropped native camera video stream
* @param {Function} successCallback - function that is called when the command execution was successful.
* @param {Function} errorCallback - function that is called when the command execution has failed and an error object is passed as a parameter.
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function changeStream(videoConnection, cropping, size, successCallback, errorCallback) {
var connectionRequest = XPMobileSDK.library.Connection.changeStream(videoConnection, cropping, size, successCallback, errorCallback);
return connectionRequest || XPMobileSDK.interfaces.ConnectionRequest;
}
/**
* Sends a ChangeStream connection command and logs out the current user.
*
* @method ChangeStream
* @param {Object} params - Parameters to sent to the server. May contain:
* <pre>
* - {String} ConnectionId - Connection ID retrieved from Connect command
* - {String} VideoId - ID of the video connection (GUID)
* - {Number} DestWidth - (optional) Width of the requested video (in pixels)
* - {Number} DestHeight - (optional) Height of the requested video (in pixels)
* - {Number} Fps - (optional) Frame-rate of the requested video (frames per second)
* - {Number} ComprLevel - (optional) Compression level of the received JPEG images (1 - 100)
* - {String} MethodType - Type of the method for retrieving video data - Push or Pull
* - {String} SeekType - (optional) Makes seek of specific type: DbStart,
* DbEnd, PrevSeq, NextSeq, PrevFrame, NextFrame, Time, TimeOrBefore,
* TimeOrAfter, TimeAfter, TimeBefore.
* - {String} Time - (optional) Time of playback speed (in milliseconds
* since Unix epoch). Valid if SeekType == Time.
*
* - {String} SignalType - Type of the requested signal - Live, Playback or Upload.
* - {Number} SrcLeft - (optional) Left coordinate (X) of the cropping rectangle.
* - {Number} SrcTop - (optional) Top coordinate (Y) of the cropping rectangle.
* - {Number} SrcRight - (optional) Right coordinate (X) of the cropping rectangle.
* - {Number} SrcBottom - (optional) Bottom coordinate (Y) of the cropping rectangle.
* - {Number} Speed - (optional) Speed of the playback (floating point). Sign determines the direction.
* - {Number} PtzPreset - (optional) Makes move of the PTZ to a user defined preset.
* - {String} RegionGrid - (reserved)
* - {String} MotionOverlayEnabled - (reserved) No/Yes
* - {Number} MotionAmount - (reserved ) 1-100
* - {Number} SensitivityAmount - (reserved) 1-100
* - {Number} CPUImpactAmont - (reserved) 1-4
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages should
* be sent from server while processing the request.
* Default depends on the value in connect command
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*/
function ChangeStream(params, successCallback, failCallback) {
XPMobileSDK.library.Connection.ChangeStream(params, successCallback, failCallback);
}
/**
* Sends a CloseStream connection command to close an existing VideoConnection by id.
*
* @method closeStream
* @param {String} videoId - id of an existing VideoConnection
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function closeStream(videoId) {
return XPMobileSDK.library.Connection.closeStream(videoId);
}
/**
* Sends a CloseStream connection command to close an existing Audio stream by Id.
*
* @method closeAudioStream
* @param {String} streamId - id of an existing stream
*
* @return {ConnectionRequest} - the ConnectionRequest object
*/
function closeAudioStream(streamId) {
return XPMobileSDK.library.Connection.closeAudioStream(streamId);
}
/**
* Sends a CloseStream connection command and logs out the current user.
*
* @method CloseStream
* @param {Object} params - Parameters to sent to the server. Should contain:
* <pre>
* - {String} ConnectionId - Connection ID retrieved from Connect command
* - {String} VideoId - ID of the video connection (GUID)
* - {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing messages should
* be sent from server while processing the request.
* Default depends on the value in connect command
* </pre>
* @param {Function} successCallback - function that is called when the command execution was successful and the result is passed as a parameter.
* @param {Function} failCallback - function that is called when the command execution has failed and the error is passed as a parameter.
*/
function CloseStream(params, successCallback, failCallback) {
XPMobileSDK.library.Connection.CloseStream(params, successCallback, failCallback);
}
/**
* Establishes a connection to an available web camera and requests a video push stream for that camera with requestPushStream.