mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 18:29:45 +02:00
Add support for XEP-0118: UserTune
This commit will enable user to communicate information about music to which user is listening. This feature is less of a requirement and more like fun to me. An attempt at solving SMACK-257. Incase you see any chances of improvement, please let me know :)
This commit is contained in:
parent
8f371c5381
commit
260c5539b5
13 changed files with 835 additions and 0 deletions
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Aditya Borikar.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.usertune;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smackx.usertune.element.UserTuneElement;
|
||||
|
||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||
import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil;
|
||||
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||
import org.junit.AfterClass;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
||||
public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
private final UserTuneManager utm1;
|
||||
private final UserTuneManager utm2;
|
||||
|
||||
public UserTuneIntegrationTest(SmackIntegrationTestEnvironment<?> environment) throws NotLoggedInException {
|
||||
super(environment);
|
||||
utm1 = UserTuneManager.getInstanceFor(conOne);
|
||||
utm2 = UserTuneManager.getInstanceFor(conTwo);
|
||||
}
|
||||
|
||||
@SmackIntegrationTest
|
||||
public void test() throws Exception {
|
||||
URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#9");
|
||||
UserTuneElement.Builder builder = UserTuneElement.getBuilder();
|
||||
UserTuneElement userTuneElement1 = builder.setArtist("Yes")
|
||||
.setLength(686)
|
||||
.setRating(8)
|
||||
.setSource("Yessongs")
|
||||
.setTitle("Heart of the Sunrise")
|
||||
.setTrack("3")
|
||||
.setUri(uri)
|
||||
.build();
|
||||
|
||||
IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
|
||||
|
||||
final SimpleResultSyncPoint userTuneReceived = new SimpleResultSyncPoint();
|
||||
|
||||
final UserTuneListener userTuneListener = new UserTuneListener() {
|
||||
@Override
|
||||
public void onUserTuneUpdated(BareJid jid, Message message, UserTuneElement userTuneElement) {
|
||||
if (userTuneElement.equals(userTuneElement1)) {
|
||||
userTuneReceived.signal();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
utm2.addUserTuneListener(userTuneListener);
|
||||
|
||||
try {
|
||||
utm1.publishUserTune(userTuneElement1);
|
||||
userTuneReceived.waitForResult(timeout);
|
||||
} finally {
|
||||
utm2.removeUserTuneListener(userTuneListener);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void unsubscribe()
|
||||
throws SmackException.NotLoggedInException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Aditya Borikar.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.usertune;
|
Loading…
Add table
Add a link
Reference in a new issue