forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep0124.ts
124 lines (119 loc) · 3.74 KB
/
xep0124.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
// ====================================================================
// XEP-0124: Bidirectional-streams Over Synchronous HTTP (BOSH)
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0124.html
// Version: 1.11.1 (2016-11-16)
//
// Additional:
// --------------------------------------------------------------------
// XEP-0206: XMPP over BOSH
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0206.html
// Version: 1.4 (2014-04-09)
// ====================================================================
import { JID } from '../JID';
import {
attribute,
childText,
DefinitionOptions,
integerAttribute,
JIDAttribute,
languageAttribute,
namespacedAttribute,
namespacedBooleanAttribute
} from '../jxt';
import { NS_BOSH, NS_BOSH_XMPP } from '../Namespaces';
type BOSHErrorCondition =
| 'bad-request'
| 'host-gone'
| 'host-unknown'
| 'improper-addressing'
| 'internal-server-error'
| 'item-not-found'
| 'other-request'
| 'policy-violation'
| 'remote-connection-failed'
| 'remote-stream-error'
| 'see-other-uri'
| 'system-shutdown'
| 'undefined-condition';
export interface BOSH {
seeOtherURI?: string;
acceptMediaTypes?: string;
ack?: number;
maxSessionPause?: number;
characterSets?: string;
from?: JID;
to?: JID;
lang?: string;
version?: string;
maxWaitTime?: number;
maxHoldOpen?: number;
route?: string;
sid?: string;
rid?: number;
maxClientRequests?: number;
minPollingInterval?: number;
maxInactivityTime?: number;
report?: number;
timeSinceReport?: number;
type?: 'error' | 'terminate';
condition?: BOSHErrorCondition;
// XEP-0206
xmppRestart?: boolean;
xmppRestartLogic?: boolean;
xmppVersion?: string;
}
const Protocol: DefinitionOptions = {
element: 'body',
fields: {
acceptMediaTypes: attribute('accept'),
ack: integerAttribute('ack'),
authId: attribute('authid'),
characterSets: attribute('charsets'),
condition: attribute('condition'),
from: JIDAttribute('from'),
key: attribute('key'),
lang: languageAttribute(),
maxClientRequests: integerAttribute('requests'),
maxHoldOpen: integerAttribute('hold'),
maxInactivityTime: integerAttribute('inactivity'),
maxSessionPause: integerAttribute('maxpause'),
maxWaitTime: integerAttribute('wait'),
mediaType: attribute('content'),
minPollingInterval: integerAttribute('polling'),
newKey: attribute('newkey'),
pauseSession: integerAttribute('pause'),
report: integerAttribute('report'),
rid: integerAttribute('rid'),
route: attribute('string'),
seeOtherURI: childText(null, 'uri'),
sid: attribute('sid'),
stream: attribute('stream'),
time: integerAttribute('time'),
to: JIDAttribute('to'),
type: attribute('type'),
version: attribute('ver'),
// XEP-0206
xmppRestart: namespacedBooleanAttribute('xmpp', NS_BOSH_XMPP, 'restart', undefined, {
writeValue: (value: boolean) => {
return value ? 'true' : 'false';
}
}),
xmppRestartLogic: namespacedBooleanAttribute(
'xmpp',
NS_BOSH_XMPP,
'restartlogic',
undefined,
{
writeValue: (value: boolean) => {
return value ? 'true' : 'false';
}
}
),
xmppVersion: namespacedAttribute('xmpp', NS_BOSH_XMPP, 'version')
},
namespace: NS_BOSH,
path: 'bosh'
};
export default Protocol;