This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
basejingle.lua
177 lines (150 loc) · 4.44 KB
/
basejingle.lua
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
local UUID = require("uuid");
local Jingle = {};
function Jingle:new(o)
local o = o or {
sid = "",
peer = "",
peerID = "",
initiator = false,
descriptionTypes = {},
transportTypes = {},
};
o.sid = o.sid or UUID();
o.peerID = o.peerID or o.peer;
o.isInitiator = o.initiator or false;
o.isPending = false;
o.isEnded = false;
o.pendingAction = false;
o.state = 'starting';
o.connectionState = 'starting';
o.descriptionTypes = o.descriptionTypes or {};
o.pendingAction = false;
setmetatable(o, self);
self.__index = self;
return o;
end
local ACTIONS = {};
ACTIONS["content-accept"] = 'onContentAccept';
ACTIONS['content-add'] = 'onContentAdd';
ACTIONS['content-modify'] = 'onConentModify';
ACTIONS['content-reject'] = 'onContentReject';
ACTIONS['content-remove'] = 'onContentRemove';
ACTIONS['description-info'] = 'onDescriptionInfo';
ACTIONS['security-info'] = 'onSecurityInfo';
ACTIONS['session-accept'] = 'onSessionAccept';
ACTIONS['session-info'] = 'onSessionInfo';
ACTIONS['session-initiate'] = 'onSessionInitiate';
--ACTIONS['session-terminate'] = 'onSessionTerminate';
ACTIONS['transport-accept'] = 'onTransportAccept';
ACTIONS['transport-info'] = 'onTransportInfo';
ACTIONS['transport-reject'] = 'onTransportReject';
ACTIONS['transport-replace'] = 'onTransportReplace';
ACTIONS['source-add'] = 'onSourceAdd';
ACTIONS['source-remove'] = 'onSourceRemove';
local STATES = {
starting = 'isStarting',
pending = 'isPending',
active = 'isActive',
ended = 'isEnded',
connecting = 'isConnecting',
connected = 'isConnected',
disconnected = 'isDisconnected',
interrupted = 'isInterrupted',
};
function Jingle:initialize(peer, sid, sdp)
end
function Jingle:process(action, req)
--print("processing?");
if ACTIONS[action] then
if not self[ACTIONS[action]] then
--print("We don't have one of those!");
self.client:send(req:error_reply('modify', 'feature-not-implemented'));
return true;
else
return self[ACTIONS[action]](self, req);
end
else
--print("Invalid action.");
self.client:send(req:error_reply('cancel', 'bad-request'));
return true;
end
end
function Jingle:createJingleStanzaSDP(action, sdp)
local jingle = {};
if (self.initiator) then
jingle = jingletolua.toJingle(sdp, 'initiator');
jingle.attr.responder = self.peer;
jingle.attr.initiator = self.client.full;
else
jingle = jingletolua.toJingle(sdp, 'initiator');
jingle.attr.initiator = self.peer;
jingle.attr.responder = self.client.full;
end
jingle.attr.action = action;
jingle.attr.sid = self.sid;
return jingle;
end
function Jingle:createJingleStanza(action)
local jingle = self.verse.stanza('jingle', {
xmlns = "urn:xmpp:jingle:1",
action = action,
sid = self.sid,
});
if (self.initiator) then
jingle.attr.initiator = self.client.full;
else
jingle.attr.initiator = self.peer;
end
return jingle;
end
function Jingle:createIqStanza(st_type)
local iq = self.verse.iq({
to = self.peer,
from = self.client.full,
type = st_type or "set",
});
return iq;
end
function Jingle:createSetSDP(action, sdp)
local jingle = self:createJingleStanzaSDP(action, sdp);
local iq = self:createIqStanza();
iq:add_child(jingle);
return iq, jingle;
end
function Jingle:createInfo()
local jingle = self:createJingleStanza('session-info');
local iq = self:createIqStanza();
iq:add_child(jingle);
return iq, jingle;
end
function Jingle:check(state)
if STATES[state] then
return self[STATES[state]];
end
--print("State not found.");
return false;
end
function Jingle:onContentAdd(req)
end
function Jingle:onDescriptionInfo(req)
self.client:send(
req:error_reply('modify', 'feature-notimplemented')
:tag("out-of-order", {xmlns = xmlns_jingle_error})
:up()
);
end
function Jingle:onTransportInfo(req)
end
function Jingle:onSessionInfo(req)
end
function Jingle:onSessionAccept(req)
end
function Jingle:onTransportReplace(req)
end
function Jingle:terminate(reason)
local jingle = self:createJingleStanza('session-terminate')
local iq = self:createIqStanza()
iq:add_direct_child(jingle)
self.client:send(iq);
end
return Jingle;