save
This commit is contained in:
parent
821b7c9e8e
commit
ba1aa39ac3
|
|
@ -1,4 +1,4 @@
|
|||
import { _decorator, Component, Node, native } from "cc";
|
||||
import { _decorator, Component, Node, native,sys } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
import { createRequestData } from "./WalletSdkUtils";
|
||||
|
||||
|
|
@ -21,11 +21,20 @@ export class btn_click extends Component {
|
|||
*/
|
||||
public btn_onclick1() {
|
||||
console.info("点击了按钮");
|
||||
var ret = native.reflection.callStaticMethod(
|
||||
"JSHandleClass",
|
||||
"walleConnectFun:",
|
||||
"imtokenv2"
|
||||
);
|
||||
if (sys.platform == sys.Platform.ANDROID) {
|
||||
var ret = native.reflection.callStaticMethod(
|
||||
'com/cocos/game/AppActivity',
|
||||
"initWallet",
|
||||
"()V"
|
||||
);
|
||||
} else if (sys.platform == sys.Platform.IOS) {
|
||||
var ret = native.reflection.callStaticMethod(
|
||||
"JSHandleClass",
|
||||
"walleConnectFun:",
|
||||
"imtokenv2"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//发送交易
|
||||
|
|
@ -37,18 +46,33 @@ export class btn_click extends Component {
|
|||
"Mint",
|
||||
"0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
|
||||
);
|
||||
var jsonObj = {
|
||||
"method": "eth_sendTransaction",
|
||||
"params": JSON.stringify(temp)
|
||||
};
|
||||
var jsonStr = JSON.stringify(jsonObj);
|
||||
///0x2eB535d54382eA5CED9183899916A9d39e093877
|
||||
|
||||
var ret = native.reflection.callStaticMethod(
|
||||
"JSHandleClass",
|
||||
"sendContractFun:",
|
||||
jsonStr
|
||||
);
|
||||
if (sys.platform == sys.Platform.ANDROID) {
|
||||
var ret = native.reflection.callStaticMethod(
|
||||
'com/cocos/game/AppActivity',
|
||||
'sendCustomMessage',
|
||||
'(Ljava/lang/String;)Ljava/lang/String;',
|
||||
JSON.stringify({
|
||||
method: 'eth_sendTransaction',
|
||||
params: [
|
||||
temp
|
||||
],
|
||||
})
|
||||
);
|
||||
} else if (sys.platform == sys.Platform.IOS) {
|
||||
var jsonObj = {
|
||||
"method": "eth_sendTransaction",
|
||||
"params": JSON.stringify(temp)
|
||||
};
|
||||
var jsonStr = JSON.stringify(jsonObj);
|
||||
///0x2eB535d54382eA5CED9183899916A9d39e093877
|
||||
|
||||
var ret = native.reflection.callStaticMethod(
|
||||
"JSHandleClass",
|
||||
"sendContractFun:",
|
||||
jsonStr
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
public async btn_onclick3() {
|
||||
// console.info("点击了按钮");
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,15 @@
|
|||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
option(APP_NAME "Project Name" "cocos_demo_3")
|
||||
project(${APP_NAME} CXX)
|
||||
set(CC_LIB_NAME cocos)
|
||||
set(CC_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(CC_PROJ_SOURCES)
|
||||
set(CC_COMMON_SOURCES)
|
||||
set(CC_ALL_SOURCES)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt)
|
||||
|
||||
cc_android_before_target(${CC_LIB_NAME})
|
||||
add_library(${CC_LIB_NAME} SHARED ${CC_ALL_SOURCES})
|
||||
cc_android_after_target(${CC_LIB_NAME})
|
||||
|
|
@ -0,0 +1 @@
|
|||
# Supported for Cocos Service!
|
||||
|
|
@ -0,0 +1 @@
|
|||
# Supported for Cocos Service!
|
||||
Binary file not shown.
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.walletconnect_demo"
|
||||
android:installLocation="auto">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="@string/app_name"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
<!-- Tell CocosNativeActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="cocos" />
|
||||
|
||||
<activity
|
||||
android:name="com.cocos.game.AppActivity"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:launchMode="singleTask"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.cocos.lib.CocosEditBoxActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
RES_PATH = RES_PATH.replace("\\", "/")
|
||||
COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/")
|
||||
|
||||
buildDir = "${RES_PATH}/proj/build/$project.name"
|
||||
android {
|
||||
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
|
||||
buildToolsVersion PROP_BUILD_TOOLS_VERSION
|
||||
ndkPath PROP_NDK_PATH
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId APPLICATION_ID
|
||||
minSdkVersion PROP_MIN_SDK_VERSION
|
||||
targetSdkVersion PROP_TARGET_SDK_VERSION
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
targets "cocos"
|
||||
arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=gold"
|
||||
}
|
||||
ndk { abiFilters PROP_APP_ABI.split(':') }
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java.srcDirs "../src", "src"
|
||||
res.srcDirs "../res", 'res'
|
||||
jniLibs.srcDirs "../libs", 'libs'
|
||||
manifest.srcFile "AndroidManifest.xml"
|
||||
assets.srcDir "${RES_PATH}/data"
|
||||
jniLibs {
|
||||
// Vulkan validation layer
|
||||
// srcDir "${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs"
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "../CMakeLists.txt"
|
||||
buildStagingDirectory "${RES_PATH}/proj/build"
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
||||
release {
|
||||
if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) {
|
||||
storeFile file(RELEASE_STORE_FILE)
|
||||
storePassword RELEASE_STORE_PASSWORD
|
||||
keyAlias RELEASE_KEY_ALIAS
|
||||
keyPassword RELEASE_KEY_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
debuggable false
|
||||
jniDebuggable false
|
||||
renderscriptDebuggable false
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
if (project.hasProperty("RELEASE_STORE_FILE")) {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
// resValue "string", "app_name", PROP_APP_NAME
|
||||
}
|
||||
|
||||
debug {
|
||||
debuggable true
|
||||
jniDebuggable true
|
||||
renderscriptDebuggable true
|
||||
// resValue "string", "app_name", "${PROP_APP_NAME}-dbg"
|
||||
// applicationIdSuffix ".debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar'])
|
||||
implementation project(':libservice')
|
||||
implementation project(':libcocos')
|
||||
|
||||
implementation "org.java-websocket:Java-WebSocket:1.4.0"
|
||||
|
||||
implementation "com.github.komputing:khex:1.0.0-RC6"
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
|
||||
|
||||
implementation 'com.github.WalletConnect:kotlin-walletconnect-lib:0.9.6'
|
||||
|
||||
implementation "androidx.appcompat:appcompat:$versions.androidx_app_compat"
|
||||
implementation "androidx.multidex:multidex:$versions.multidex"
|
||||
|
||||
implementation 'com.squareup.moshi:moshi:1.8.0'
|
||||
implementation "com.squareup.okhttp3:okhttp:$versions.okhttp"
|
||||
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.9.1'
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Proguard Cocos2d-x-lite for release
|
||||
-keep public class com.cocos.** { *; }
|
||||
-dontwarn com.cocos.**
|
||||
|
||||
# Proguard Apache HTTP for release
|
||||
-keep class org.apache.http.** { *; }
|
||||
-dontwarn org.apache.http.**
|
||||
|
||||
# Proguard okhttp for release
|
||||
-keep class okhttp3.** { *; }
|
||||
-dontwarn okhttp3.**
|
||||
|
||||
-keep class okio.** { *; }
|
||||
-dontwarn okio.**
|
||||
|
||||
# Proguard Android Webivew for release. you can comment if you are not using a webview
|
||||
-keep public class android.net.http.SslError
|
||||
-keep public class android.webkit.WebViewClient
|
||||
|
||||
-keep public class com.google.** { *; }
|
||||
|
||||
-dontwarn android.webkit.WebView
|
||||
-dontwarn android.net.http.SslError
|
||||
-dontwarn android.webkit.WebViewClient
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,250 @@
|
|||
@file:JvmName("AppActivity")
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
*
|
||||
* http://www.cocos2d-x.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.(
|
||||
*/
|
||||
package com.cocos.game
|
||||
|
||||
import android.content.res.Configuration
|
||||
|
||||
import com.cocos.service.SDKWrapper
|
||||
import com.cocos.lib.CocosActivity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import com.example.walletconnect_demo.server.BridgeServer
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import okhttp3.OkHttpClient
|
||||
import org.komputing.khex.extensions.toNoPrefixHexString
|
||||
import org.walletconnect.Session
|
||||
import org.walletconnect.impls.*
|
||||
import org.walletconnect.nullOnThrow
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.launch
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
public class AppActivity : CocosActivity(), Session.Callback {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
|
||||
if (!isTaskRoot()) {
|
||||
// Android launched another instance of the root activity into an existing task
|
||||
// so just quietly finish and go away, dropping the user back into the activity
|
||||
// at the top of the stack (ie: the last state of this task)
|
||||
// Don't need to finish it again since it's finished in super.onCreate .
|
||||
return
|
||||
}
|
||||
// DO OTHER INITIALIZATION BELOW
|
||||
SDKWrapper.shared().init(this)
|
||||
// initBridge()
|
||||
initMoshi()
|
||||
initClient()
|
||||
initSessionStorage()
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
override fun onStatus(status: Session.Status) {
|
||||
when(status) {
|
||||
Session.Status.Approved -> sessionApproved()
|
||||
Session.Status.Closed -> sessionClosed()
|
||||
Session.Status.Connected,
|
||||
Session.Status.Disconnected,
|
||||
is Session.Status.Error -> {
|
||||
// Do Stuff
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMethodCall(call: Session.MethodCall) {
|
||||
}
|
||||
|
||||
private fun sessionApproved() {
|
||||
println("--------sessionApproved--------------")
|
||||
println(session.approvedAccounts())
|
||||
|
||||
}
|
||||
|
||||
private fun sessionClosed() {
|
||||
println("--------sessionClosed--------------")
|
||||
println(session.approvedAccounts())
|
||||
}
|
||||
|
||||
private fun initClient() {
|
||||
client = OkHttpClient.Builder().build()
|
||||
}
|
||||
|
||||
private fun initMoshi() {
|
||||
moshi = Moshi.Builder().build()
|
||||
}
|
||||
|
||||
private fun initBridge() {
|
||||
bridge = BridgeServer(moshi)
|
||||
bridge.start()
|
||||
}
|
||||
|
||||
private fun initSessionStorage() {
|
||||
storage = FileWCSessionStore(File(cacheDir, "session_store.json").apply { createNewFile() }, moshi)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
SDKWrapper.shared().onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
SDKWrapper.shared().onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
|
||||
if (!isTaskRoot()) {
|
||||
return
|
||||
}
|
||||
SDKWrapper.shared().onDestroy()
|
||||
}
|
||||
|
||||
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
|
||||
// super.onActivityResult(requestCode, resultCode, data)
|
||||
// SDKWrapper.shared().onActivityResult(requestCode, resultCode, data)
|
||||
// }
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
SDKWrapper.shared().onNewIntent(intent)
|
||||
}
|
||||
|
||||
override fun onRestart() {
|
||||
super.onRestart()
|
||||
SDKWrapper.shared().onRestart()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
SDKWrapper.shared().onStop()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
SDKWrapper.shared().onBackPressed()
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
SDKWrapper.shared().onConfigurationChanged(newConfig)
|
||||
super.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
override protected fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
SDKWrapper.shared().onRestoreInstanceState(savedInstanceState)
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
}
|
||||
|
||||
override protected fun onSaveInstanceState(outState: Bundle) {
|
||||
SDKWrapper.shared().onSaveInstanceState(outState)
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override protected fun onStart() {
|
||||
SDKWrapper.shared().onStart()
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
|
||||
override fun onLowMemory() {
|
||||
SDKWrapper.shared().onLowMemory()
|
||||
super.onLowMemory()
|
||||
}
|
||||
|
||||
fun test(){
|
||||
}
|
||||
|
||||
companion object {
|
||||
lateinit var instance: AppActivity ;
|
||||
private lateinit var client: OkHttpClient
|
||||
private lateinit var moshi: Moshi
|
||||
private lateinit var bridge: BridgeServer
|
||||
private lateinit var storage: WCSessionStore
|
||||
lateinit var config: Session.Config
|
||||
lateinit var session: Session
|
||||
|
||||
fun resetSession() {
|
||||
nullOnThrow { session }?.clearCallbacks()
|
||||
val key = ByteArray(32).also { Random().nextBytes(it) }.toNoPrefixHexString()
|
||||
config = Session.Config(UUID.randomUUID().toString(), "https://bridge.walletconnect.org/", key)
|
||||
session = WCSession(config,
|
||||
MoshiPayloadAdapter(moshi),
|
||||
storage,
|
||||
OkHttpTransport.Builder(client, moshi),
|
||||
Session.PeerMeta(name = "Example App")
|
||||
)
|
||||
session.offer()
|
||||
}
|
||||
@JvmStatic public fun initWallet() {
|
||||
println("--------initWallet--------------")
|
||||
resetSession()
|
||||
session.addCallback(instance)
|
||||
val i = Intent(Intent.ACTION_VIEW)
|
||||
i.data = Uri.parse(config.toWCUri())
|
||||
instance.startActivity(i)
|
||||
// instance.test()
|
||||
}
|
||||
///解析庄给的json字符串 并且使用custom方法发送给钱包
|
||||
@JvmStatic public fun sendCustomMessage(jsonStr:String):String{
|
||||
///解析成实体类
|
||||
var str = Gson().fromJson(jsonStr,argsModel::class.java);
|
||||
session.performMethodCall(
|
||||
Session.MethodCall.Custom(
|
||||
System.currentTimeMillis(),
|
||||
str.method!!,
|
||||
str.params!!,
|
||||
),
|
||||
::handleResponse
|
||||
)
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.data = Uri.parse("wc:")
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
instance.startActivity(intent)
|
||||
return "ok"
|
||||
}
|
||||
private fun handleResponse(resp: Session.MethodCall.Response) {
|
||||
println(resp.result as? String)
|
||||
}
|
||||
}
|
||||
}
|
||||
class argsModel {
|
||||
var method: String? = null
|
||||
var params: List<Any>? = null
|
||||
|
||||
override fun toString(): String {
|
||||
return "argsModel(method=$method, params=$params)"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.example.walletconnect_demo.server
|
||||
|
||||
|
||||
import android.util.Log
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import org.java_websocket.WebSocket
|
||||
import org.java_websocket.handshake.ClientHandshake
|
||||
import org.java_websocket.server.WebSocketServer
|
||||
import java.lang.Exception
|
||||
import java.lang.ref.WeakReference
|
||||
import java.net.InetSocketAddress
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class BridgeServer(moshi: Moshi) : WebSocketServer(InetSocketAddress(PORT)) {
|
||||
|
||||
private val adapter = moshi.adapter<Map<String, String>>(
|
||||
Types.newParameterizedType(
|
||||
Map::class.java,
|
||||
String::class.java,
|
||||
String::class.java
|
||||
)
|
||||
)
|
||||
|
||||
private val pubs: MutableMap<String, MutableList<WeakReference<WebSocket>>> = ConcurrentHashMap()
|
||||
private val pubsLock = Any()
|
||||
private val pubsCache: MutableMap<String, String?> = ConcurrentHashMap()
|
||||
|
||||
override fun onOpen(conn: WebSocket?, handshake: ClientHandshake?) {
|
||||
Log.d("#####", "onOpen: ${conn?.remoteSocketAddress?.address?.hostAddress}")
|
||||
}
|
||||
|
||||
override fun onClose(conn: WebSocket?, code: Int, reason: String?, remote: Boolean) {
|
||||
Log.d("#####", "onClose: ${conn?.remoteSocketAddress?.address?.hostAddress}")
|
||||
conn?.let { cleanUpSocket(it) }
|
||||
}
|
||||
|
||||
override fun onMessage(conn: WebSocket?, message: String?) {
|
||||
Log.d("#####", "Message: $message")
|
||||
try {
|
||||
conn ?: error("Unknown socket")
|
||||
message?.also {
|
||||
val msg = adapter.fromJson(it) ?: error("Invalid message")
|
||||
val type: String = msg["type"] ?: error("Type not found")
|
||||
val topic: String = msg["topic"] ?: error("Topic not found")
|
||||
when (type) {
|
||||
"pub" -> {
|
||||
var sendMessage = false
|
||||
pubs[topic]?.forEach { r ->
|
||||
r.get()?.apply {
|
||||
send(message)
|
||||
sendMessage = true
|
||||
}
|
||||
}
|
||||
if (!sendMessage) {
|
||||
Log.d("#####", "Cache message: $message")
|
||||
pubsCache[topic] = message
|
||||
}
|
||||
}
|
||||
"sub" -> {
|
||||
pubs.getOrPut(topic, { mutableListOf() }).add(WeakReference(conn))
|
||||
pubsCache[topic]?.let { cached ->
|
||||
Log.d("#####", "Send cached: $cached")
|
||||
conn.send(cached)
|
||||
}
|
||||
}
|
||||
else -> error("Unknown type")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
Log.d("#####", "Server started")
|
||||
connectionLostTimeout = 0
|
||||
}
|
||||
|
||||
override fun onError(conn: WebSocket?, ex: Exception?) {
|
||||
Log.d("#####", "onError")
|
||||
ex?.printStackTrace()
|
||||
conn?.let { cleanUpSocket(it) }
|
||||
}
|
||||
|
||||
private fun cleanUpSocket(conn: WebSocket) {
|
||||
synchronized(pubsLock) {
|
||||
pubs.forEach {
|
||||
it.value.removeAll { r -> r.get().let { v -> v == null || v == conn } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val PORT = 5000 + Random().nextInt(60000)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"ndk_module_path" :[
|
||||
"${COCOS_ROOT}",
|
||||
"${COCOS_ROOT}/cocos",
|
||||
"${COCOS_ROOT}/external"
|
||||
],
|
||||
"copy_resources": []
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext {
|
||||
versions = [
|
||||
kotlin : "1.4.31",
|
||||
moshi : '1.8.0',
|
||||
okhttp : '3.11.0',
|
||||
jupiter : '5.7.0',
|
||||
|
||||
'minSdk' : 14,
|
||||
'compileSdk' : 28,
|
||||
'buildTools' : '28.0.3',
|
||||
'androidPlugin' : '3.4.0',
|
||||
|
||||
androidx_app_compat : '1.0.2',
|
||||
androidx_card_view : '1.0.0',
|
||||
androidx_constraint_layout: '1.1.3',
|
||||
androidx_lifecycle : '2.0.0',
|
||||
androidx_test_ext : '1.1.0',
|
||||
androidx_recycler_view : '1.0.0',
|
||||
androidx_room : '2.0.0',
|
||||
|
||||
multidex : '2.0.1',
|
||||
]
|
||||
|
||||
ext.deps = [
|
||||
android: [
|
||||
'runtime' : 'com.google.android:android:4.1.1.4',
|
||||
'gradlePlugin': "com.android.tools.build:gradle:${versions.androidPlugin}",
|
||||
]
|
||||
]
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven { url="https://jitpack.io" }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
|
||||
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$versions.kotlin"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
flatDir {
|
||||
dirs 'libs'
|
||||
}
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,6 @@
|
|||
#Mon Sep 05 15:37:26 CST 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
package="com.example.walletconnect_demo"
|
||||
android:installLocation="auto">
|
||||
<dist:module dist:instant="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<meta-data
|
||||
android:name="aia-compat-api-min-version"
|
||||
android:value="1" />
|
||||
<!-- Tell CocosNativeActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="cocos" />
|
||||
|
||||
<activity
|
||||
android:name="com.cocos.game.InstantActivity"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:launchMode="singleTask"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter android:order="1">
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.cocos.lib.CocosEditBoxActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
RES_PATH = RES_PATH.replace("\\", "/")
|
||||
COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/")
|
||||
buildDir = "${RES_PATH}/proj/build/$project.name"
|
||||
|
||||
android {
|
||||
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
|
||||
buildToolsVersion PROP_BUILD_TOOLS_VERSION
|
||||
ndkPath PROP_NDK_PATH
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.walletconnect_demo"
|
||||
minSdkVersion PROP_MIN_SDK_VERSION
|
||||
targetSdkVersion PROP_TARGET_SDK_VERSION
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
targets "cocos"
|
||||
arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}","-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=gold"
|
||||
cppFlags "-frtti -fexceptions -fsigned-char -DANDROID_INSTANT=1"
|
||||
}
|
||||
ndk { abiFilters PROP_APP_ABI.split(':') }
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java.srcDirs "../src", "src"
|
||||
res.srcDirs "../res", 'res'
|
||||
jniLibs.srcDirs "../libs", 'libs'
|
||||
manifest.srcFile "AndroidManifest.xml"
|
||||
assets.srcDir "${RES_PATH}/data"
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "../CMakeLists.txt"
|
||||
buildStagingDirectory "${RES_PATH}/proj/build"
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
||||
release {
|
||||
if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) {
|
||||
storeFile file(RELEASE_STORE_FILE)
|
||||
storePassword RELEASE_STORE_PASSWORD
|
||||
keyAlias RELEASE_KEY_ALIAS
|
||||
keyPassword RELEASE_KEY_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
debuggable false
|
||||
jniDebuggable false
|
||||
renderscriptDebuggable false
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
if (project.hasProperty("RELEASE_STORE_FILE")) {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
// resValue "string", "app_name", PROP_APP_NAME
|
||||
}
|
||||
|
||||
debug {
|
||||
debuggable true
|
||||
jniDebuggable true
|
||||
renderscriptDebuggable true
|
||||
// resValue "string", "app_name", "${PROP_APP_NAME}-dbg"
|
||||
// applicationIdSuffix ".debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
|
||||
implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar'])
|
||||
implementation project(':libservice')
|
||||
implementation project(':libcocos')
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Proguard Cocos2d-x-lite for release
|
||||
-keep public class com.cocos.** { *; }
|
||||
-dontwarn com.cocos.**
|
||||
|
||||
# Proguard Apache HTTP for release
|
||||
-keep class org.apache.http.** { *; }
|
||||
-dontwarn org.apache.http.**
|
||||
|
||||
# Proguard okhttp for release
|
||||
-keep class okhttp3.** { *; }
|
||||
-dontwarn okhttp3.**
|
||||
|
||||
-keep class okio.** { *; }
|
||||
-dontwarn okio.**
|
||||
|
||||
# Proguard Android Webivew for release. you can comment if you are not using a webview
|
||||
-keep public class android.net.http.SslError
|
||||
-keep public class android.webkit.WebViewClient
|
||||
|
||||
-keep public class com.google.** { *; }
|
||||
|
||||
-dontwarn android.webkit.WebView
|
||||
-dontwarn android.net.http.SslError
|
||||
-dontwarn android.webkit.WebViewClient
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package com.cocos.game;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import com.cocos.service.SDKWrapper;
|
||||
import com.cocos.lib.CocosActivity;
|
||||
|
||||
public class InstantActivity extends CocosActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// DO OTHER INITIALIZATION BELOW
|
||||
SDKWrapper.shared().init(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
SDKWrapper.shared().onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
SDKWrapper.shared().onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
|
||||
if (!isTaskRoot()) {
|
||||
return;
|
||||
}
|
||||
SDKWrapper.shared().onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
SDKWrapper.shared().onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
SDKWrapper.shared().onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
SDKWrapper.shared().onRestart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
SDKWrapper.shared().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
SDKWrapper.shared().onBackPressed();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
SDKWrapper.shared().onConfigurationChanged(newConfig);
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
SDKWrapper.shared().onRestoreInstanceState(savedInstanceState);
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
SDKWrapper.shared().onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
SDKWrapper.shared().onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
SDKWrapper.shared().onLowMemory();
|
||||
super.onLowMemory();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Game.h"
|
||||
|
||||
cc::Application *cocos_main(int width, int height) {
|
||||
return new Game(width, height);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name" translatable="false">cocos_demo_3</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue