-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathxep0234.ts
143 lines (134 loc) · 4.3 KB
/
xep0234.ts
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
// ====================================================================
// XEP-0234: Jingle File Transfer
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0234.html
// Version: Version 0.18.3 (2017-08-24)
// ====================================================================
import { JINGLE_INFO_CHECKSUM_5, JINGLE_INFO_RECEIVED_5, JingleSessionRole } from '../Constants';
import {
addAlias,
attribute,
childDate,
childInteger,
childText,
DefinitionOptions,
integerAttribute
} from '../jxt';
import {
NS_HASHES_1,
NS_HASHES_2,
NS_JINGLE_FILE_TRANSFER_4,
NS_JINGLE_FILE_TRANSFER_5,
NS_THUMBS_1
} from '../Namespaces';
import { Hash, HashUsed, JingleApplication, JingleInfo, Thumbnail } from './';
export interface FileTransferDescription extends JingleApplication {
applicationType: typeof NS_JINGLE_FILE_TRANSFER_5 | typeof NS_JINGLE_FILE_TRANSFER_4;
file: FileDescription;
}
export interface FileDescription {
name?: string;
description?: string;
mediaType?: string;
size?: number;
date?: Date;
range?: FileRange;
hashes?: Hash[];
hashesUsed?: HashUsed[];
thumbnails?: Thumbnail[];
}
export interface FileRange {
offset?: number;
length?: number;
}
export interface FileTransferInfo extends JingleInfo {
infoType: typeof JINGLE_INFO_CHECKSUM_5 | typeof JINGLE_INFO_RECEIVED_5;
creator?: JingleSessionRole;
name: string;
file?: FileDescription;
}
let Protocol: DefinitionOptions[] = [
addAlias(NS_HASHES_2, 'hash', [
{ path: 'file.hashes', multiple: true },
{ path: 'file.range.hashes', multiple: true }
]),
addAlias(NS_HASHES_1, 'hash', [
{ path: 'file.hashes', multiple: true },
{ path: 'file.range.hashes', multiple: true }
]),
addAlias(NS_HASHES_2, 'hash-used', [{ path: 'file.hashesUsed', multiple: true }]),
addAlias(NS_THUMBS_1, 'thumbnail', [{ path: 'file.thumbnails', multiple: true }])
];
for (const ftVersion of [NS_JINGLE_FILE_TRANSFER_4, NS_JINGLE_FILE_TRANSFER_5]) {
Protocol = Protocol.concat([
{
aliases: [
'file',
{
impliedType: true,
path: 'iq.jingle.contents.application.file',
selector: ftVersion
},
{
impliedType: true,
path: 'iq.jingle.info.file',
selector: `{${ftVersion}}checksum`
}
],
defaultType: NS_JINGLE_FILE_TRANSFER_5,
element: 'file',
fields: {
date: childDate(null, 'date'),
description: childText(null, 'desc'),
mediaType: childText(null, 'media-type'),
name: childText(null, 'name'),
size: childInteger(null, 'size')
},
namespace: ftVersion,
type: ftVersion,
typeField: 'version'
},
{
aliases: [{ impliedType: true, path: 'file.range', selector: ftVersion }],
defaultType: NS_JINGLE_FILE_TRANSFER_5,
element: 'range',
fields: {
length: integerAttribute('length'),
offset: integerAttribute('offset', 0)
},
namespace: ftVersion,
type: ftVersion,
typeField: 'version'
},
{
element: 'description',
namespace: ftVersion,
path: 'iq.jingle.contents.application',
type: ftVersion,
typeField: 'applicationType'
},
{
element: 'received',
fields: {
creator: attribute('creator'),
name: attribute('name')
},
namespace: ftVersion,
path: 'iq.jingle.info',
type: `{${ftVersion}}received`,
typeField: 'infoType'
},
{
element: 'checksum',
fields: {
creator: attribute('creator'),
name: attribute('name')
},
namespace: ftVersion,
path: 'iq.jingle.info',
type: `{${ftVersion}}checksum`,
typeField: 'infoType'
}
]);
}
export default Protocol;