forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep0030.ts
153 lines (138 loc) · 3.82 KB
/
xep0030.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
144
145
146
147
148
149
150
151
152
153
// ====================================================================
// XEP-0030: Service Discovery
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0030.html
// Version: 2.5rc3 (2017-10-03)
//
// Additional:
// --------------------------------------------------------------------
// XEP-0128: Service Discovery Extensions
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0128.html
// Version: 1.0 (2004-10-20)
// ====================================================================
import { JID } from '../JID';
import {
addAlias,
attribute,
DefinitionOptions,
JIDAttribute,
languageAttribute,
multipleChildAttribute
} from '../jxt';
import { NS_DATAFORM, NS_DISCO_INFO, NS_DISCO_ITEMS, NS_RSM } from '../Namespaces';
import { DataForm } from './';
declare module './' {
export interface IQPayload {
disco?: Disco;
}
export interface Message {
disco?: Disco;
}
export interface StreamFeatures {
disco?: DiscoInfo;
}
}
export interface DiscoInfoIdentity {
type: string;
category: string;
name?: string;
lang?: string;
}
export interface DiscoInfo {
type: 'info';
node?: string;
features?: string[];
identities?: DiscoInfoIdentity[];
// XEP-0128
extensions?: DataForm[];
}
export interface DiscoInfoResult extends DiscoInfo {
features: string[];
identities: DiscoInfoIdentity[];
// XEP-0128
extensions: DataForm[];
}
export interface DiscoItems {
type: 'items';
node?: string;
items?: DiscoItem[];
}
export interface DiscoItemsResult extends DiscoItems {
items: DiscoItem[];
}
export interface DiscoItem {
node?: string;
jid?: JID;
name?: string;
lang?: string;
}
export type Disco = DiscoInfo | DiscoItems;
const Protocol: DefinitionOptions[] = [
{
aliases: ['iq.disco', 'message.disco', 'features.disco'],
childrenExportOrder: {
identities: 1,
features: 2,
extensions: 3
},
element: 'query',
fields: {
features: multipleChildAttribute(null, 'feature', 'var'),
node: attribute('node')
},
namespace: NS_DISCO_INFO,
path: 'disco',
type: 'info',
typeField: 'type'
},
{
aliases: [{ path: 'disco.identities', selector: 'info', multiple: true }],
element: 'identity',
fields: {
category: attribute('category'),
lang: languageAttribute(),
name: attribute('name'),
type: attribute('type')
},
namespace: NS_DISCO_INFO
},
{
aliases: [{ path: 'disco.items', multiple: true, selector: 'items' }],
element: 'item',
fields: {
jid: JIDAttribute('jid'),
name: attribute('name'),
node: attribute('node')
},
namespace: NS_DISCO_ITEMS
},
{
aliases: [{ path: 'disco.items', multiple: true, selector: 'info' }],
element: 'item',
fields: {
category: JIDAttribute('category'),
lang: languageAttribute(),
name: attribute('name'),
type: attribute('type')
},
namespace: NS_DISCO_INFO
},
addAlias(NS_DATAFORM, 'x', [
// XEP-0128
{ path: 'disco.extensions', multiple: true, selector: 'info' }
]),
addAlias(NS_RSM, 'set', [{ path: 'disco.paging', selector: 'items' }]),
{
aliases: ['iq.disco', 'message.disco', 'features.disco'],
element: 'query',
fields: {
node: attribute('node')
},
namespace: NS_DISCO_ITEMS,
path: 'disco',
type: 'items',
typeField: 'type'
}
];
export default Protocol;