Skip to content

Commit 27b590a

Browse files
committed
add jvb api iq provider
1 parent c4f0e0b commit 27b590a

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright @ 2018 - present 8x8, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jitsi.xmpp.extensions.colibri;
18+
19+
import org.jitsi.xmpp.extensions.*;
20+
import org.jivesoftware.smack.packet.*;
21+
import org.jivesoftware.smack.provider.*;
22+
import org.xmlpull.v1.*;
23+
24+
public class JvbApiIqProvider extends IQProvider<JvbApiIq>
25+
{
26+
27+
@Override
28+
public JvbApiIq parse(XmlPullParser parser, int initialDepth) throws Exception
29+
{
30+
if (!JvbApiIq.NAMESPACE.equals(parser.getNamespace()))
31+
{
32+
return null;
33+
}
34+
if (!JvbApiIq.ELEMENT_NAME.equals(parser.getName()))
35+
{
36+
return null;
37+
}
38+
JvbApiIq iq = new JvbApiIq();
39+
40+
boolean done = false;
41+
int eventType = parser.next();
42+
if (eventType == XmlPullParser.START_TAG)
43+
{
44+
String name = parser.getName();
45+
if (name.equals(JsonPacketExtension.ELEMENT_NAME))
46+
{
47+
ExtensionElementProvider<JsonPacketExtension> jsonProvider =
48+
new DefaultPacketExtensionProvider<>(JsonPacketExtension.class);
49+
JsonPacketExtension jsonPE = jsonProvider.parse(parser);
50+
iq.addExtension(jsonPE);
51+
}
52+
}
53+
54+
55+
56+
57+
return iq;
58+
}
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright @ 2018 - present 8x8, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jitsi.xmpp.extensions.colibri;
18+
19+
import junit.framework.*;
20+
import org.jivesoftware.smack.provider.*;
21+
import org.jivesoftware.smack.util.*;
22+
import org.xmlpull.v1.*;
23+
24+
public class JvbApiIqProviderTest extends TestCase
25+
{
26+
private final JvbApiIqProvider jvbApiIqProvider = new JvbApiIqProvider();
27+
28+
@Override
29+
protected void setUp() throws Exception
30+
{
31+
super.setUp();
32+
ProviderManager.addIQProvider(
33+
JvbApiIq.ELEMENT_NAME,
34+
JvbApiIq.NAMESPACE,
35+
jvbApiIqProvider
36+
);
37+
}
38+
39+
public void testSimple() throws Exception
40+
{
41+
String xml = "" +
42+
"<jvb-api xmlns='http://jitsi.org/protocol/colibri/v2'/>";
43+
44+
XmlPullParser parser = PacketParserUtils.getParserFor(xml);
45+
JvbApiIq parsed = jvbApiIqProvider.parse(parser);
46+
assertTrue(parsed.toXML().toString().contains(xml));
47+
}
48+
49+
public void testWithJson() throws Exception
50+
{
51+
String xml = "" +
52+
"<jvb-api xmlns='http://jitsi.org/protocol/colibri/v2'><json>{}</json></jvb-api>";
53+
XmlPullParser parser = PacketParserUtils.getParserFor(xml);
54+
JvbApiIq parsed = jvbApiIqProvider.parse(parser);
55+
assertTrue(parsed.toXML().toString().contains(xml));
56+
assertNotNull(parsed.getJsonContent());
57+
assertEquals("{}", parsed.getJsonContent());
58+
}
59+
}

0 commit comments

Comments
 (0)