-
Notifications
You must be signed in to change notification settings - Fork 251
/
xep0047.ts
89 lines (82 loc) · 2.25 KB
/
xep0047.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
// ====================================================================
// XEP-0047: In-band Bytestreams
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0047.html
// Version: 2.0 (2012-06-22)
// ====================================================================
import {
attribute,
DefinitionOptions,
integerAttribute,
textBuffer,
TranslationContext,
XMLElement
} from '../jxt';
import { NS_IBB } from '../Namespaces';
import { Buffer } from '../platform';
declare module './' {
export interface Message {
ibb?: IBBData;
}
export interface IQPayload {
ibb?: IBB;
}
}
export interface IBBRequest {
action: 'open' | 'close';
sid: string;
blockSize?: number;
ack?: boolean;
}
export interface IBBData {
action: 'data';
sid: string;
seq: number;
data: Buffer;
}
export type IBB = IBBRequest | IBBData;
const Protocol: DefinitionOptions[] = [
{
aliases: ['iq.ibb', 'message.ibb'],
element: 'open',
fields: {
ack: {
importer(xml: XMLElement, context: TranslationContext): boolean {
const stanza = attribute('stanza', 'iq').importer(xml, context);
return stanza !== 'message';
},
exporter(xml: XMLElement, data: boolean, context: TranslationContext): void {
attribute('stanza').exporter(xml, data ? 'iq' : 'message', context);
}
},
blockSize: integerAttribute('block-size'),
sid: attribute('sid')
},
namespace: NS_IBB,
type: 'open',
typeField: 'action'
},
{
aliases: ['iq.ibb', 'message.ibb'],
element: 'close',
fields: {
sid: attribute('sid')
},
namespace: NS_IBB,
type: 'close',
typeField: 'action'
},
{
aliases: ['iq.ibb', 'message.ibb'],
element: 'data',
fields: {
data: textBuffer('base64'),
seq: integerAttribute('seq'),
sid: attribute('sid')
},
namespace: NS_IBB,
type: 'data',
typeField: 'action'
}
];
export default Protocol;