public static void main(String[] args) throws SkypeException, InterruptedException { Thread.setDefaultUncaughtExceptionHandler(new UncaughtHandler()); final ContactListFrame contactListFrame = new ContactListFrame(SkypeApp.getContacts()); final Application application = SkypeApp.getApp(); final SkypeBridge skypeBridge = new SkypeBridge(SkypeApp.getOwnId()); contactListFrame.setContactListSelectedListener( new ContactListSelected() { @Override public void selected(List<String> selectedValuesList) { if (selectedValuesList.size() == 0) { JOptionPane.showMessageDialog(null, "Select at least one contact."); return; } contactListFrame.close(); skypeBridge.setServer(); skypeBridge.setInvited(selectedValuesList); SkypeApp.connectToIds(selectedValuesList); } }); application.addApplicationListener(skypeBridge); }
public void testWriteOnMultiThread() throws Exception { Skype.setDebug(true); Application application = Skype.addApplication(APPLICATION_NAME); Friend friend = TestData.getFriend(); try { Stream[] streams = application.connect(friend); assertEquals(1, streams.length); Stream stream = streams[0]; checkConnectedFriends(application, friend); checkWriteOnMultiThread(stream); checkDisconnect(application, stream); } finally { application.finish(); } }
private void checkDisconnect(Application application, Stream stream) throws Exception { final Object lock = new Object(); final boolean[] result = new boolean[1]; application.addApplicationListener( new ApplicationAdapter() { @Override public void disconnected(Stream stream) throws SkypeException { result[0] = true; synchronized (lock) { lock.notify(); } } }); synchronized (lock) { stream.write("disconnect"); try { lock.wait(10000); } catch (InterruptedException e) { fail(); } } assertTrue(result[0]); }
private void checkConnectedFriends(Application application, Friend friend) throws SkypeException { Friend[] connectableFriends = application.getAllConnectedFriends(); assertEquals(1, connectableFriends.length); assertEquals(friend, connectableFriends[0]); }