Compare commits

..
4 Commits
10 changed files with 104 additions and 142 deletions

No files matched your search

+4 -4
View File
@@ -69,6 +69,9 @@ configurations {
dependencies {
// syntax sugaring for data models
annotationProcessor 'org.projectlombok:lombok:1.18.12'
api 'io.grpc:grpc-protobuf-lite:1.31.1'
// listenable future is part of the SDK public API
api 'com.google.guava:guava:29.0-android'
implementation "org.projectlombok:lombok:1.18.12"
implementation 'com.google.code.gson:gson:2.8.6'
@@ -80,15 +83,12 @@ dependencies {
implementation 'com.squareup.okio:okio:2.7.0'
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
implementation 'io.grpc:grpc-protobuf-lite:1.31.1'
implementation 'io.grpc:grpc-stub:1.31.1'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
protobuf 'com.google.api.grpc:proto-google-common-protos:2.1.0'
implementation 'org.slf4j:slf4j-api:1.7.30'
api 'com.google.guava:guava:29.0-android' // listenable future is part of the SDK public API
protobuf 'com.google.api.grpc:proto-google-common-protos:2.1.0'
testCompile 'junit:junit:4.12'
}
+1 -1
View File
@@ -49,7 +49,7 @@ android {
ext{
versionFirebaseCrashlytics = "17.3.0"
versionFirebaseBom = "26.2.0"
versionNakama = "76b4af4d149f715eed491052f3fa9963e0b0d781"
versionNakama = "08587dcdecc18efce0a0592451f81b31af59bb42"
versionProtobuf = "3.13.0"
versionPlayAuth = "19.0.0"
}
@@ -18,7 +18,11 @@ package com.example.nakama_java_test_android;
import java.util.concurrent.*;
import com.google.common.util.concurrent.*;
import com.heroiclabs.nakama.*;
import com.heroiclabs.nakama.DefaultClient;
import com.heroiclabs.nakama.Session;
import com.heroiclabs.nakama.api.Account;
import android.app.*;
import android.os.Bundle;
import android.util.*;
@@ -32,35 +36,41 @@ public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final DefaultClient client = new DefaultClient("defaultkey", "10.0.2.2", 7349, false);
final ExecutorService executor = Executors.newSingleThreadExecutor();
try {
String email = "[email protected]";
String password = "batsignal";
Futures.addCallback(client.authenticateEmail(email, password), new FutureCallback<Session>() {
@Override
public void onSuccess(final Session result) {
Log.i("auth","got session: " + result.getAuthToken());
client.createSocket();
executor.shutdown();
}
@Override
public void onFailure(final Throwable throwable) {
Log.e("auth", throwable.getMessage());
executor.shutdown();
}
}, executor);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
String email = "[email protected]";
String password = "batsignal";
ListenableFuture<Session> authFuture = client.authenticateEmail(email, password);
AsyncFunction<Session, Account> accountFunction = new AsyncFunction<Session, Account>() {
public ListenableFuture<Account> apply(Session session) {
return client.getAccount(session);
}
};
ListenableFuture<Account> accountFuture = Futures.transformAsync(authFuture, accountFunction, executor);
Futures.addCallback(accountFuture, new FutureCallback<Account>() {
@Override
public void onSuccess(Account account) {
System.out.println("Got account: " + account.getUser().getId());
executor.shutdown();
}
@Override
public void onFailure(Throwable e) {
System.out.println(e.getMessage());
executor.shutdown();
}
}, executor);
try {
executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
}
}
+1
View File
@@ -0,0 +1 @@
To run this example, run ./gradlew run.
+1 -1
View File
@@ -35,7 +35,7 @@ repositories {
}
dependencies {
implementation 'com.github.heroiclabs.nakama-java:nakama-java:76b4af4d149f715eed491052f3fa9963e0b0d781'
implementation 'com.github.heroiclabs.nakama-java:nakama-java:08587dcdecc18efce0a0592451f81b31af59bb42'
// fat Jar
// implementation 'com.github.heroiclabs.nakama-java:nakama-java-all:dde7330adfa1867881dc6c6c6e27c1176512c916'
+32 -23
View File
@@ -15,40 +15,49 @@
*/
import java.util.concurrent.*;
import com.google.common.util.concurrent.*;
import com.heroiclabs.nakama.DefaultClient;
import com.heroiclabs.nakama.Session;
import com.heroiclabs.nakama.api.Account;
// fat jar
// import nakama.com.google.common.util.concurrent.*;
import com.google.common.util.concurrent.*;
import com.heroiclabs.nakama.*;
public class Main {
public static void main(String[] args) {
DefaultClient client = new DefaultClient("defaultkey", "127.0.0.1", 7349, false);
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
String email = "[email protected]";
String password = "batsignal";
Futures.addCallback(client.authenticateEmail(email, password), new FutureCallback<Session>() {
@Override
public void onSuccess(final Session result) {
System.out.println("got session: " + result.getAuthToken());
executor.shutdown();
}
@Override
public void onFailure(final Throwable throwable) {
System.out.println(throwable.getMessage());
executor.shutdown();
}
}, executor);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
String email = "[email protected]";
String password = "batsignal";
ListenableFuture<Session> authFuture = client.authenticateEmail(email, password);
AsyncFunction<Session, Account> accountFunction = new AsyncFunction<Session, Account>() {
public ListenableFuture<Account> apply(Session session) {
return client.getAccount(session);
}
};
ListenableFuture<Account> accountFuture = Futures.transformAsync(authFuture, accountFunction, executor);
Futures.addCallback(accountFuture, new FutureCallback<Account>() {
@Override
public void onSuccess(Account account) {
System.out.println("Got account: " + account.getUser().getId());
executor.shutdown();
}
@Override
public void onFailure(Throwable e) {
System.out.println(e.getMessage());
executor.shutdown();
}
}, executor);
try {
executor.awaitTermination(5, TimeUnit.SECONDS);
executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
+1
View File
@@ -0,0 +1 @@
To run this example, run `mvn compile` and then `mvn exec:java`.
+1 -34
View File
@@ -38,16 +38,10 @@
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.heroiclabs.nakama-java</groupId>
<artifactId>nakama-java</artifactId>
<version>dde7330adfa1867881dc6c6c6e27c1176512c916</version>
<version>08587dcdecc18efce0a0592451f81b31af59bb42</version>
<type>jar</type>
</dependency>
<!-- fat jar
@@ -61,7 +55,6 @@
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@@ -76,19 +69,10 @@
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
@@ -102,23 +86,6 @@
</configuration>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
@@ -16,9 +16,12 @@
import java.util.concurrent.*;
import com.google.common.util.concurrent.*;
import com.heroiclabs.nakama.DefaultClient;
import com.heroiclabs.nakama.Session;
import com.heroiclabs.nakama.api.Account;
// fat jar
// import nakama.com.google.common.util.concurrent.*;
import com.heroiclabs.nakama.*;
public class Main {
@@ -26,28 +29,35 @@ public class Main {
DefaultClient client = new DefaultClient("defaultkey", "127.0.0.1", 7349, false);
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
String email = "[email protected]";
String password = "batsignal";
Futures.addCallback(client.authenticateEmail(email, password), new FutureCallback<Session>() {
@Override
public void onSuccess(final Session result) {
System.out.println("got session: " + result.getAuthToken());
executor.shutdown();
}
@Override
public void onFailure(final Throwable throwable) {
System.out.println(throwable.getMessage());
executor.shutdown();
}
}, executor);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
String email = "[email protected]";
String password = "batsignal";
ListenableFuture<Session> authFuture = client.authenticateEmail(email, password);
AsyncFunction<Session, Account> accountFunction = new AsyncFunction<Session, Account>() {
public ListenableFuture<Account> apply(Session session) {
return client.getAccount(session);
}
};
ListenableFuture<Account> accountFuture = Futures.transformAsync(authFuture, accountFunction, executor);
Futures.addCallback(accountFuture, new FutureCallback<Account>() {
@Override
public void onSuccess(Account account) {
System.out.println("Got account: " + account.getUser().getId());
executor.shutdown();
}
@Override
public void onFailure(Throwable e) {
System.out.println(e.getMessage());
executor.shutdown();
}
}, executor);
try {
executor.awaitTermination(5, TimeUnit.SECONDS);
executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
@@ -1,36 +0,0 @@
/*
* Copyright 2020 The Nakama Authors
*
* 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 com.heroiclabs;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.heroiclabs.nakama.*;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}