-
Notifications
You must be signed in to change notification settings - Fork 0
/
bfcp-lib.js
2152 lines (2138 loc) · 81.8 KB
/
bfcp-lib.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
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BFCPLib = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var primitive_1 = require("../messages/primitive");
var Complements = require("../parser/complements");
var parser_1 = require("../parser/parser");
var format_1 = require("./format");
var type_1 = require("./type");
exports.ATTRIBUTE_HEADER_SIZE = 2;
/**
* Attribute class is an abstraction of the Attribute as defined in the
* RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2
* @memberof bfcp-lib
*/
var Attribute = /** @class */ (function () {
/**
* @constructor
* @param type Attribute Type
* @param format Attribute format
* @param content The attribute content, which can be an Integer, or other attributes, depending of the format
*/
function Attribute(type, length, format, content) {
this._mandatory = true;
this._type = type;
this._length = length;
this._format = format;
this._content = content;
}
Object.defineProperty(Attribute.prototype, "type", {
get: function () {
return this._type;
},
set: function (type) {
this._type = type;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attribute.prototype, "length", {
get: function () {
return this._length;
},
set: function (length) {
this._length = length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attribute.prototype, "format", {
get: function () {
return this._format;
},
set: function (format) {
this._format = format;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attribute.prototype, "content", {
get: function () {
return this._content;
},
set: function (content) {
this._content = content;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attribute.prototype, "mandatory", {
get: function () {
return this._mandatory;
},
set: function (mandatary) {
this._mandatory = mandatary;
},
enumerable: true,
configurable: true
});
Attribute.prototype.getContentAttriute = function (type) {
if (this.content instanceof Array) {
return this.content.find(function (a) { return a.type === type; });
}
return null;
};
/**
* Encodes this Attribute instance from object oriented format to the binary
* format.
* @return Binary string representing the BFCP Attribute
* @public
*/
Attribute.prototype.encode = function () {
var type = Complements.complementBinary(this.type, 7);
var mandatary = this.mandatory ? "1" : "0";
var length = Complements.complementBinary(this.length, 8);
var content = null;
switch (this.format) {
case format_1.Format.Unsigned16:
content = Complements.complementBinary(this.content, 16);
break;
case format_1.Format.Grouped:
content = this._encodeGroupedAttributeContent();
break;
case format_1.Format.OctetString:
content = this._encodeOctetStringContent();
break;
case format_1.Format.OctetString16:
content = this._encodeOctetString16Content();
break;
default:
throw new Error("I can't encode this attribute. Format unknown.");
}
return Complements.complementPadding(type + mandatary + length + content);
};
/**
* Encodes the Grouped type attribute content.
* @return Binary string representing the BFCP object content
* @private
*/
Attribute.prototype._encodeGroupedAttributeContent = function () {
var e_1, _a;
var newContent = "";
try {
for (var _b = __values(this.content), _c = _b.next(); !_c.done; _c = _b.next()) {
var attribute = _c.value;
if (attribute instanceof Attribute) {
newContent = newContent + attribute.encode();
}
else if (typeof attribute === "number") {
newContent = newContent + Complements.complementBinary(attribute, 16);
}
else if (typeof attribute === "string" || attribute instanceof String) {
newContent = newContent + attribute;
}
else {
throw new Error("Unknown attribute!");
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return newContent;
};
/**
* Encodes the OctetString type attribute content.
* @return Binary string representing the BFCP object content
* @private
*/
Attribute.prototype._encodeOctetStringContent = function () {
var e_2, _a, e_3, _b;
var newContent = "";
switch (this.type) {
case type_1.Type.SupportedAttributes:
try {
for (var _c = __values(this.content), _d = _c.next(); !_d.done; _d = _c.next()) {
var attributeType = _d.value;
newContent = newContent + Complements.complementBinary(attributeType, 7) + "0";
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
return newContent;
case type_1.Type.SupportedPrimitives:
try {
for (var _e = __values(this.content), _f = _e.next(); !_f.done; _f = _e.next()) {
var primitiveType = _f.value;
newContent = newContent + Complements.complementBinary(primitiveType, 8);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_3) throw e_3.error; }
}
return newContent;
default:
throw new Error("I can't encode this octet string attribute. Type unknown.");
}
};
/**
* Encodes the OctetString16 type attribute content.
* @return Binary string representing the BFCP object content
* @private
*/
Attribute.prototype._encodeOctetString16Content = function () {
switch (this.type) {
case type_1.Type.RequestStatus:
var requestStatus = Complements.complementBinary(this.content[0], 8);
var queuePosition = Complements.complementBinary(this.content[1], 8);
return requestStatus + queuePosition;
default:
throw new Error("I can't encode this octet string 16 attribute. Type unknown.");
}
};
return Attribute;
}());
exports.Attribute = Attribute;
/**
* BeneficiaryId class is an abstraction of the BeneficiaryId attribute
* as defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.1
* @extends Attribute
*/
var BeneficiaryId = /** @class */ (function (_super) {
__extends(BeneficiaryId, _super);
/**
* @constructor
* @param beneficiaryId The beneficiary id integer
*/
function BeneficiaryId(beneficiaryId) {
return _super.call(this, type_1.Type.BeneficiaryId, 2 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Unsigned16, beneficiaryId) || this;
}
BeneficiaryId.decode = function (data) {
// 2-byte
var beneficiaryId = parser_1.getInteger(data);
return new BeneficiaryId(beneficiaryId);
};
Object.defineProperty(BeneficiaryId.prototype, "beneficiaryId", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return BeneficiaryId;
}(Attribute));
exports.BeneficiaryId = BeneficiaryId;
/**
* FloorId class is an abstraction of the FloorId attribute
* as defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.2
* @extends Attribute
*/
var FloorId = /** @class */ (function (_super) {
__extends(FloorId, _super);
/**
* @constructor
* @param floorId The floor id
*/
function FloorId(floorId) {
return _super.call(this, type_1.Type.FloorId, 2 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Unsigned16, floorId) || this;
}
FloorId.decode = function (data) {
// 2-byte
var floorId = parser_1.getInteger(data);
return new FloorId(floorId);
};
Object.defineProperty(FloorId.prototype, "floorId", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return FloorId;
}(Attribute));
exports.FloorId = FloorId;
/**
* FloorRequestId class is an abstraction of the FloorRequestId attribute
* as defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.3
* @extends Attribute
*/
var FloorRequestId = /** @class */ (function (_super) {
__extends(FloorRequestId, _super);
/**
* @constructor
* @param floorRequestId The floor request id
*/
function FloorRequestId(floorRequestId) {
return _super.call(this, type_1.Type.FloorRequestId, 2 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Unsigned16, floorRequestId) || this;
}
FloorRequestId.decode = function (data) {
// 2-byte
var floorRequestId = parser_1.getInteger(data);
return new FloorRequestId(floorRequestId);
};
Object.defineProperty(FloorRequestId.prototype, "floorRequestId", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return FloorRequestId;
}(Attribute));
exports.FloorRequestId = FloorRequestId;
var Priority = /** @class */ (function (_super) {
__extends(Priority, _super);
function Priority(priority) {
return _super.call(this, type_1.Type.Priority, 2 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Unsigned16, priority) || this;
}
Priority.decode = function (data) {
// 2-byte
var priority = parser_1.getInteger(data) >> 5;
return new Priority(priority);
};
Object.defineProperty(Priority.prototype, "floorId", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return Priority;
}(Attribute));
exports.Priority = Priority;
/**
* RequestStatus class is an abstraction of the RequestStatus attribute as
* defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.5
* @extends Attribute
*/
var RequestStatus = /** @class */ (function (_super) {
__extends(RequestStatus, _super);
/**
* @constructor
* @param requestStatus The request status
* @param queuePosition The queue position
*/
function RequestStatus(requestStatus, queuePosition) {
if (queuePosition === void 0) { queuePosition = 0; }
var _this = this;
var content = [
requestStatus,
queuePosition,
];
_this = _super.call(this, type_1.Type.RequestStatus, 1 + 1 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.OctetString16, content) || this;
return _this;
}
RequestStatus.decode = function (data) {
// 1-byte x 2
var requestStatus = parser_1.getInteger(data, 0, 1);
var queuePosition = parser_1.getInteger(data, 1, 1);
return new RequestStatus(requestStatus, queuePosition);
};
Object.defineProperty(RequestStatus.prototype, "requestStatus", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(RequestStatus.prototype, "queuePosition", {
get: function () {
if (this.content instanceof Array) {
return this.content[1];
}
},
enumerable: true,
configurable: true
});
return RequestStatus;
}(Attribute));
exports.RequestStatus = RequestStatus;
/**
* ErrorCode class is an abstraction of the ErrorCode attribute
* as defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.2
* @extends Attribute
*/
var ErrorCode = /** @class */ (function (_super) {
__extends(ErrorCode, _super);
/**
* @constructor
* @param errorCode The error code
*/
function ErrorCode(errorCode, errorInfo) {
var _this = this;
var content = [];
content.push(errorCode);
if (errorInfo) {
content.push(errorInfo); // optional
}
_this = _super.call(this, type_1.Type.ErrorCode, 1 + (errorInfo ? errorInfo.length : 0) + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, content) || this;
return _this;
}
ErrorCode.decode = function (data) {
// 1-byte
var errorCode = parser_1.getInteger(data, 0, 1);
var errorInfo = null;
if (data.length > 1) {
/* We have Error Specific Details */
errorInfo = parser_1.getString(data, 1);
}
return new ErrorCode(errorCode, errorInfo);
};
Object.defineProperty(ErrorCode.prototype, "errorCode", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
return ErrorCode;
}(Attribute));
exports.ErrorCode = ErrorCode;
/* string attributes */
var ErrorInfo = /** @class */ (function (_super) {
__extends(ErrorInfo, _super);
function ErrorInfo(errorInfo) {
return _super.call(this, type_1.Type.ErrorInfo, errorInfo.length + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, [errorInfo]) || this;
}
ErrorInfo.decode = function (data) {
return new ErrorInfo(parser_1.getString(data));
};
Object.defineProperty(ErrorInfo.prototype, "errorInfo", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return ErrorInfo;
}(Attribute));
exports.ErrorInfo = ErrorInfo;
var ParticipantProvidedInfo = /** @class */ (function (_super) {
__extends(ParticipantProvidedInfo, _super);
function ParticipantProvidedInfo(partProviderInfo) {
return _super.call(this, type_1.Type.ErrorInfo, partProviderInfo.length + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, [partProviderInfo]) || this;
}
ParticipantProvidedInfo.decode = function (data) {
return new ParticipantProvidedInfo(parser_1.getString(data));
};
Object.defineProperty(ParticipantProvidedInfo.prototype, "partProviderInfo", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return ParticipantProvidedInfo;
}(Attribute));
exports.ParticipantProvidedInfo = ParticipantProvidedInfo;
var StatusInfo = /** @class */ (function (_super) {
__extends(StatusInfo, _super);
function StatusInfo(statusInfo) {
return _super.call(this, type_1.Type.ErrorInfo, statusInfo.length + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, [statusInfo]) || this;
}
StatusInfo.decode = function (data) {
return new StatusInfo(parser_1.getString(data));
};
Object.defineProperty(StatusInfo.prototype, "statusInfo", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return StatusInfo;
}(Attribute));
exports.StatusInfo = StatusInfo;
var UserDisplayName = /** @class */ (function (_super) {
__extends(UserDisplayName, _super);
function UserDisplayName(userDisplayName) {
return _super.call(this, type_1.Type.ErrorInfo, userDisplayName.length + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, [userDisplayName]) || this;
}
UserDisplayName.decode = function (data) {
return new UserDisplayName(parser_1.getString(data));
};
Object.defineProperty(UserDisplayName.prototype, "userDisplayName", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return UserDisplayName;
}(Attribute));
exports.UserDisplayName = UserDisplayName;
var UserUri = /** @class */ (function (_super) {
__extends(UserUri, _super);
function UserUri(userUri) {
return _super.call(this, type_1.Type.ErrorInfo, userUri.length + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, [userUri]) || this;
}
UserUri.decode = function (data) {
return new UserUri(parser_1.getString(data));
};
Object.defineProperty(UserUri.prototype, "userUri", {
get: function () {
return this.content;
},
enumerable: true,
configurable: true
});
return UserUri;
}(Attribute));
exports.UserUri = UserUri;
/* grouped attributes */
/**
* The BENEFICIARY-INFORMATION attribute is a grouped attribute that
* consists of a header, which is referred to as BENEFICIARY-
* INFORMATION-HEADER, followed by a sequence of attributes.
* @extends Attribute
*/
var BeneficiaryInformation = /** @class */ (function (_super) {
__extends(BeneficiaryInformation, _super);
function BeneficiaryInformation(beneficiaryId, attributes) {
if (attributes === void 0) { attributes = []; }
var _this = this;
var content = [];
content.push(beneficiaryId);
content.push.apply(content, __spread(attributes));
_this = _super.call(this, type_1.Type.BeneficiaryInformation, 2 + sumLengths(attributes) + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, content) || this;
return _this;
}
BeneficiaryInformation.decode = function (data) {
var beneficiaryId = parser_1.getInteger(data, 0, 2);
var attributes = parser_1.parseAttributes(data.slice(2));
return new BeneficiaryInformation(beneficiaryId, attributes);
};
Object.defineProperty(BeneficiaryInformation.prototype, "beneficiaryId", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
return BeneficiaryInformation;
}(Attribute));
exports.BeneficiaryInformation = BeneficiaryInformation;
/**
* The FLOOR-REQUEST-INFORMATION attribute is a grouped attribute that
* consists of a header, followed by a sequence of attributes.
* @extends Attribute
*/
var FloorRequestInformation = /** @class */ (function (_super) {
__extends(FloorRequestInformation, _super);
/**
* @constructor
* @param floorRequestId The floor request id
* @param floorId The floor id
* @param requestStatus The request status
*/
function FloorRequestInformation(floorRequestId, attributes) {
if (attributes === void 0) { attributes = []; }
var _this = this;
var content = [];
content.push(floorRequestId);
content.push.apply(content, __spread(attributes));
_this = _super.call(this, type_1.Type.FloorRequestInformation, 2 + sumLengths(attributes) + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, content) || this;
return _this;
}
FloorRequestInformation.decode = function (data) {
var requestedById = parser_1.getInteger(data, 0, 2);
var attributes = parser_1.parseAttributes(data.slice(2));
return new FloorRequestInformation(requestedById, attributes);
};
Object.defineProperty(FloorRequestInformation.prototype, "floorRequestId", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(FloorRequestInformation.prototype, "floorId", {
get: function () {
var frs = _super.prototype.getContentAttriute.call(this, type_1.Type.FloorRequestStatus);
return frs ? frs.floorId : null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FloorRequestInformation.prototype, "requestStatus", {
get: function () {
var ors = _super.prototype.getContentAttriute.call(this, type_1.Type.OverallRequestStatus);
return ors ? ors.requestStatus : null;
},
enumerable: true,
configurable: true
});
return FloorRequestInformation;
}(Attribute));
exports.FloorRequestInformation = FloorRequestInformation;
/**
* The REQUESTED-BY-INFORMATION attribute is a grouped attribute that
* consists of a header, followed by a sequence of attributes.
*/
var RequestedByInformation = /** @class */ (function (_super) {
__extends(RequestedByInformation, _super);
function RequestedByInformation(requestedById, attributes) {
if (attributes === void 0) { attributes = []; }
var _this = this;
var content = [];
content.push(requestedById);
content.push.apply(content, __spread(attributes));
_this = _super.call(this, type_1.Type.RequestedByInformation, 2 + sumLengths(attributes) + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, content) || this;
return _this;
}
RequestedByInformation.decode = function (data) {
var requestedById = parser_1.getInteger(data, 0, 2);
var attributes = parser_1.parseAttributes(data.slice(2));
return new RequestedByInformation(requestedById, attributes);
};
Object.defineProperty(RequestedByInformation.prototype, "requestedById", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
return RequestedByInformation;
}(Attribute));
exports.RequestedByInformation = RequestedByInformation;
/**
* The FLOOR-REQUEST-STATUS attribute is a grouped attribute that
* consists of a header, followed by a sequence of attributes.
* @extends Attribute
*/
var FloorRequestStatus = /** @class */ (function (_super) {
__extends(FloorRequestStatus, _super);
/**
* @constructor
* @param floorId The floor id
* @param requestStatus The request status
*/
function FloorRequestStatus(floorId, attributes) {
if (attributes === void 0) { attributes = []; }
var _this = this;
var content = [];
content.push(floorId);
content.push.apply(content, __spread(attributes));
_this = _super.call(this, type_1.Type.FloorRequestStatus, 2 + sumLengths(attributes) + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, content) || this;
return _this;
}
FloorRequestStatus.decode = function (data) {
var floorId = parser_1.getInteger(data, 0, 2);
var attributes = parser_1.parseAttributes(data.slice(2));
return new FloorRequestStatus(floorId, attributes);
};
Object.defineProperty(FloorRequestStatus.prototype, "floorId", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
return FloorRequestStatus;
}(Attribute));
exports.FloorRequestStatus = FloorRequestStatus;
/**
* The OVERALL-REQUEST-STATUS attribute is a grouped attribute that
* consists of a header, followed by a sequence of attributes.
* @extends Attribute
*/
var OverallRequestStatus = /** @class */ (function (_super) {
__extends(OverallRequestStatus, _super);
/**
* @constructor
* @param floorRequestId The request status
*/
function OverallRequestStatus(floorRequestId, attributes) {
if (attributes === void 0) { attributes = []; }
var _this = this;
var content = [];
content.push(floorRequestId);
content.push.apply(content, __spread(attributes));
_this = _super.call(this, type_1.Type.OverallRequestStatus, 2 + sumLengths(attributes) + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.Grouped, content) || this;
return _this;
}
OverallRequestStatus.decode = function (data) {
var floorRequestId = parser_1.getInteger(data, 0, 2);
var attributes = parser_1.parseAttributes(data.slice(2));
return new OverallRequestStatus(floorRequestId, attributes);
};
Object.defineProperty(OverallRequestStatus.prototype, "floorRequestId", {
get: function () {
if (this.content instanceof Array) {
return this.content[0];
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(OverallRequestStatus.prototype, "requestStatus", {
get: function () {
var rs = _super.prototype.getContentAttriute.call(this, type_1.Type.RequestStatus);
return rs ? {
queuePosition: rs.queuePosition,
requestStatus: rs.requestStatus,
} : null;
},
enumerable: true,
configurable: true
});
return OverallRequestStatus;
}(Attribute));
exports.OverallRequestStatus = OverallRequestStatus;
/**
* SupportedAttributes class is an abstraction of the SupportedAttributes
* attribute as defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.10
* @extends Attribute
*/
var SupportedAttributes = /** @class */ (function (_super) {
__extends(SupportedAttributes, _super);
/**
* @constructor
* @param attributes A Attribute Type list
* representing the supported attributes
*/
function SupportedAttributes(attributes) {
var _this = this;
var supported = [];
if (!attributes) {
supported = [
type_1.Type.BeneficiaryId,
type_1.Type.FloorId,
type_1.Type.FloorRequestId,
// Type.Priority,
type_1.Type.RequestStatus,
// Type.ErrorCode,
// Type.ErrorInfo,
// Type.ParticipantProvidedInfo,
// Type.StatusInfo,
type_1.Type.SupportedAttributes,
type_1.Type.SupportedPrimitives,
// Type.UserDisplayName,
// Type.UserUri,
// Type.BeneficiaryInformation,
// Type.FloorRequestInformation,
// Type.RequestedByInformation,
type_1.Type.FloorRequestStatus,
type_1.Type.OverallRequestStatus,
];
}
else {
supported = attributes;
}
_this = _super.call(this, type_1.Type.SupportedAttributes, supported.length * 1 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.OctetString, supported) || this;
return _this;
}
SupportedAttributes.decode = function (data) {
var e_4, _a;
var types = [];
try {
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
var attr = data_1_1.value;
// first 7 bits
var type = attr >> 1;
types.push(type);
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_4) throw e_4.error; }
}
return new SupportedAttributes(types);
};
Object.defineProperty(SupportedAttributes.prototype, "suportedAttributes", {
get: function () {
if (this.content instanceof Array) {
return __spread(this.content);
}
},
enumerable: true,
configurable: true
});
return SupportedAttributes;
}(Attribute));
exports.SupportedAttributes = SupportedAttributes;
/**
* SupportedPrimitives class is an abstraction of the SupportedPrimitives
* attribute as defined in the RFC 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2.11
* @extends Attribute
*/
var SupportedPrimitives = /** @class */ (function (_super) {
__extends(SupportedPrimitives, _super);
/**
* @constructor
* @param primitives A Message Primitive list
* representing the supported primitives (messages)
*/
function SupportedPrimitives(primitives) {
var _this = this;
var supported = [];
if (!primitives) {
supported = [
primitive_1.Primitive.FloorRequest,
primitive_1.Primitive.FloorRelease,
// Primitive.FloorRequestQuery,
// Primitive.FloorRequestStatus,
// Primitive.UserQuery,
// Primitive.UserStatus,
primitive_1.Primitive.FloorQuery,
primitive_1.Primitive.FloorStatus,
primitive_1.Primitive.Hello,
primitive_1.Primitive.HelloAck,
// Primitive.Error,
// Primitive.FloorRequestStatusAck,
// Primitive.ErrorAck,
primitive_1.Primitive.FloorStatusAck,
primitive_1.Primitive.Goodbye,
primitive_1.Primitive.GoodbyeAck,
];
}
else {
supported = primitives;
}
_this = _super.call(this, type_1.Type.SupportedPrimitives, supported.length * 1 + exports.ATTRIBUTE_HEADER_SIZE, format_1.Format.OctetString, supported) || this;
return _this;
}
SupportedPrimitives.decode = function (data) {
var e_5, _a;
var primitives = [];
try {
for (var data_2 = __values(data), data_2_1 = data_2.next(); !data_2_1.done; data_2_1 = data_2.next()) {
var prim = data_2_1.value;
primitives.push(prim);
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (data_2_1 && !data_2_1.done && (_a = data_2.return)) _a.call(data_2);
}
finally { if (e_5) throw e_5.error; }
}
return new SupportedPrimitives(primitives);
};
Object.defineProperty(SupportedPrimitives.prototype, "supportedPrimitives", {
get: function () {
if (this.content instanceof Array) {
return __spread(this.content);
}
},
enumerable: true,
configurable: true
});
return SupportedPrimitives;
}(Attribute));
exports.SupportedPrimitives = SupportedPrimitives;
function sumLengths(attributes) {
if (attributes.length === 0) {
return 0;
}
return attributes.map(function (a) { return a.length; }).reduce(function (acc, val) { return acc + val; });
}
},{"../messages/primitive":8,"../parser/complements":11,"../parser/parser":12,"./format":3,"./type":5}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Error class is a abstract representation of the error code as
* defined in the RFCP 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2
*/
var Error;
(function (Error) {
Error[Error["ConfNotExist"] = 1] = "ConfNotExist";
Error[Error["UserNotExist"] = 2] = "UserNotExist";
Error[Error["UnknownPrim"] = 3] = "UnknownPrim";
Error[Error["UnknownMandAttr"] = 4] = "UnknownMandAttr";
Error[Error["UnauthOperation"] = 5] = "UnauthOperation";
Error[Error["InvalidFloorId"] = 6] = "InvalidFloorId";
Error[Error["FloorReqIdNotExist"] = 7] = "FloorReqIdNotExist";
Error[Error["MaxFloorReqReached"] = 8] = "MaxFloorReqReached";
Error[Error["UseTls"] = 9] = "UseTls";
Error[Error["ParseError"] = 10] = "ParseError";
Error[Error["UseDtls"] = 11] = "UseDtls";
Error[Error["UnsupportedVersion"] = 12] = "UnsupportedVersion";
Error[Error["BadLength"] = 13] = "BadLength";
Error[Error["GenericError"] = 14] = "GenericError";
})(Error = exports.Error || (exports.Error = {}));
},{}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Format class is a abstraction of the attribute Format as defined in
* the RFCP 4582 - BFCP
* https://tools.ietf.org/html/rfc4582#section-5.2
*/
var Format;
(function (Format) {
/** Gets Unsigned16 Format string */
Format["Unsigned16"] = "Unsigned16";
/** Gets OctetString16 Format string */
Format["OctetString16"] = "OctetString16";
/** Gets OctetString Format string */
Format["OctetString"] = "OctetString";
/** Gets Grouped Format string */
Format["Grouped"] = "Grouped";
})(Format = exports.Format || (exports.Format = {}));
},{}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Name class is a abstraction of the attribute Names
*/
var Name;
(function (Name) {
/** Gets BeneficiaryId Name string */
Name["BeneficiaryId"] = "BeneficiaryId";
/** Gets FloorId Name string */
Name["FloorId"] = "FloorId";
/** Gets FloorRequestId Name string */
Name["FloorRequestId"] = "FloorRequestId";
/** Gets Priority Name string */
Name["Priority"] = "Priority";
/** Gets RequestStatus Name string */
Name["RequestStatus"] = "RequestStatus";
/** Gets ErrorCode Name string */
Name["ErrorCode"] = "ErrorCode";
/** Gets ErrorInfo Name string */
Name["ErrorInfo"] = "ErrorInfo";
/** Gets ParticipantProvidedInfo Name string */
Name["ParticipantProvidedInfo"] = "ParticipantProvidedInfo";
/** Gets StatusInfo Name string */
Name["StatusInfo"] = "StatusInfo";
/** Gets SupportedAttributes Name string */
Name["SupportedAttributes"] = "SupportedAttributes";
/** Gets SupportedPrimitives Name string */
Name["SupportedPrimitives"] = "SupportedPrimitives";
/** Gets UserDisplayName Name string */
Name["UserDisplayName"] = "UserDisplayName";
/** Gets UserUri Name string */
Name["UserUri"] = "UserUri";
/** Gets BeneficiaryInformation Name string */
Name["BeneficiaryInformation"] = "BeneficiaryInformation";
/** Gets FloorRequestInformation Name string */
Name["FloorRequestInformation"] = "FloorRequestInformation";
/** Gets RequestedByInformation Name string */
Name["RequestedByInformation"] = "RequestedByInformation";
/** Gets FloorRequestStatus Name string */
Name["FloorRequestStatus"] = "FloorRequestStatus";
/** Gets OverallRequestStatus Name string */
Name["OverallRequestStatus"] = "OverallRequestStatus";