-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsignal-xmpp.js
96 lines (87 loc) · 1.87 KB
/
signal-xmpp.js
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
"use strict";
var xmpp = null;
var wxmpp = null;
var owner = null;
var signal = null;
var signals = [];
function load(modules)
{
xmpp = modules.xmpp;
wxmpp = modules.wxmpp;
owner = modules.config.owner;
signal = modules.signal;
}
function sendSignal(s)
{
if(wxmpp.checkConnected())
{
var t = wxmpp.getConnection();
if(s.value)
{
var tag = new xmpp.Element('signal', s);
if(wxmpp.ownerIsAvailable())
t.sendWyliodrin(owner, tag, false);
else
t.sendWyliodrin(owner, tag, true);
}
else
{
var tag = new xmpp.Element('signal', {signal:s.signal, id:s.id, time:s.time});
for(var i=0; i<s.component.length; i++)
{
tag.c('component',{name:component[i].signal, value:component[i].value});
}
if(wxmpp.ownerIsAvailable())
t.sendWyliodrin(owner, tag, false);
else
t.sendWyliodrin(owner, tag, true);
}
}
else
{
console.log('push signal');
signals.push(s)
}
}
function sendSignalBuffer()
{
if(signals.length > 0)
{
console.log('send buffer');
var t = wxmpp.getConnection();
var tag = new xmpp.Element('signals');
for(var i=0; i<signals.length; i++)
{
if(signals[i].value)
{
tag.c('signal', signals[i]);
}
else
{
tag.c('signal',{signal:signals[i].signal, id:signals[i].id, time:signals[i].time});
for(var j=0; j<signals[i].component.length; i++)
tag.c('component',{name:signals[i].component[j].signal, value:signals[i].component[j].value});
}
}
if(wxmpp.ownerIsAvailable())
t.sendWyliodrin(owner, tag, false);
else
t.sendWyliodrin(owner, tag, true);
}
}
function signalStanza(t, from, to, es, error)
{
if(!error)
{
if(es.attrs.signal)
{
var signal = es.attrs.signal;
var value = es.attrs.value;
var id = es.attrs.id;
signal.setSignal(signal, value, id);
}
}
}
exports.sendSignalBuffer = sendSignalBuffer;
exports.sendSignal = sendSignal;
exports.load = load;