307 lines
10 KiB
Plaintext
Executable File
307 lines
10 KiB
Plaintext
Executable File
/****************************************************************************
|
||
Copyright (c) 2010-2013 cocos2d-x.org
|
||
Copyright (c) 2013-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.
|
||
****************************************************************************/
|
||
|
||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||
|
||
#import "AppController.h"
|
||
#import "cocos2d.h"
|
||
#import "AppDelegate.h"
|
||
#import "RootViewController.h"
|
||
#import "SDKWrapper.h"
|
||
#import "platform/ios/CCEAGLView-ios.h"
|
||
#import "YMVoiceService.h"
|
||
#import "CEBG-Swift.h"
|
||
|
||
using namespace cocos2d;
|
||
|
||
@interface AppController ()<VoiceEngineCallback>
|
||
|
||
@end
|
||
|
||
@implementation AppController
|
||
|
||
Application* app = nullptr;
|
||
@synthesize window;
|
||
|
||
#pragma mark -
|
||
#pragma mark Application lifecycle
|
||
|
||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||
[[SDKWrapper getInstance] application:application didFinishLaunchingWithOptions:launchOptions];
|
||
// Add the view controller's view to the window and display.
|
||
float scale = [[UIScreen mainScreen] scale];
|
||
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||
window = [[UIWindow alloc] initWithFrame: bounds];
|
||
|
||
// cocos2d application instance
|
||
app = new AppDelegate(bounds.size.width * scale, bounds.size.height * scale);
|
||
app->setMultitouch(true);
|
||
|
||
// Use RootViewController to manage CCEAGLView
|
||
_viewController = [[RootViewController alloc]init];
|
||
#ifdef NSFoundationVersionNumber_iOS_7_0
|
||
_viewController.automaticallyAdjustsScrollViewInsets = NO;
|
||
_viewController.extendedLayoutIncludesOpaqueBars = NO;
|
||
_viewController.edgesForExtendedLayout = UIRectEdgeAll;
|
||
#else
|
||
_viewController.wantsFullScreenLayout = YES;
|
||
#endif
|
||
// Set RootViewController to window
|
||
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
|
||
{
|
||
// warning: addSubView doesn't work on iOS6
|
||
[window addSubview: _viewController.view];
|
||
}
|
||
else
|
||
{
|
||
// use this method on ios6
|
||
[window setRootViewController:_viewController];
|
||
}
|
||
|
||
[window makeKeyAndVisible];
|
||
|
||
[[UIApplication sharedApplication] setStatusBarHidden:YES];
|
||
|
||
// realtime audio
|
||
// 启动YoumeService
|
||
YMVoiceService *youMeVoiceEngineOC = [YMVoiceService getInstance];
|
||
//允许使用移动网络
|
||
[youMeVoiceEngineOC setUseMobileNetworkEnabled:true];
|
||
|
||
|
||
[[YMVoiceService getInstance] initSDK:self appkey:@"YOUME1838B3633FF1410BDC9124BBD806F245B9D2E5AC" appSecret:@"q6B570yTyj/00Nk4mYZtgDwyew5v05t13V1vo4mxpEuAaWUiinAyVxG41sNu3vsFe8sipOLfKfIVYGhzpQrqzvj5sId3mrBfj/s65a2gp36yDrI/nX5BnUAJB317SEosR6xLoPuhBvHU+/1DWI7nKSKaRNxnQiC46PJKFc2kX50BAAE=" regionId:RTC_CN_SERVER serverRegionName:@"cn"];
|
||
|
||
//run the cocos2d-x game scene
|
||
app->start();
|
||
|
||
return YES;
|
||
}
|
||
|
||
+(void)connectwallet:(NSString *)url{
|
||
UIApplication *app = [UIApplication sharedApplication];
|
||
[app openURL:[NSURL URLWithString:url]];
|
||
}
|
||
|
||
WalletUtils *wallet = [WalletUtils new];
|
||
|
||
+(void)connectMetaMask{
|
||
[wallet connectMetaMask];
|
||
}
|
||
|
||
|
||
+(void)connectimToken{
|
||
[wallet connectimToken];
|
||
}
|
||
|
||
+(void)connectAlphaWallet{
|
||
[wallet connectAlphaWallet];
|
||
}
|
||
|
||
|
||
+(void)signApp:(NSString *)param{
|
||
[wallet walletSignWithParam:param];
|
||
}
|
||
|
||
+(void)signOK:(NSString *)sign{
|
||
std::string strRet = std::string([sign UTF8String]);
|
||
std::string jsCallStr = cocos2d::StringUtils::format("window.signApp(\"%s\");", strRet.c_str());
|
||
se::ScriptEngine::getInstance()->evalString(jsCallStr.c_str());
|
||
}
|
||
|
||
|
||
+(void)openSocialUrl:(NSString *)uri{
|
||
UIApplication *app = [UIApplication sharedApplication];
|
||
[app openURL:[NSURL URLWithString:uri]];
|
||
}
|
||
|
||
|
||
+(void)connectOK:(NSString *) accountid{
|
||
NSLog(@"call js in oc");
|
||
std::string strRet = std::string([accountid UTF8String]);
|
||
std::string jsCallStr = cocos2d::StringUtils::format("window.connectOK(\"%s\");", strRet.c_str());
|
||
se::ScriptEngine::getInstance()->evalString(jsCallStr.c_str());
|
||
|
||
}
|
||
|
||
+ (void)showToast:(NSString *) msg {
|
||
std::string strRet = std::string([msg UTF8String]);
|
||
std::string jsCallStr = cocos2d::StringUtils::format("window.showToast(\"%s\");", strRet.c_str());
|
||
se::ScriptEngine::getInstance()->evalString(jsCallStr.c_str());
|
||
}
|
||
|
||
|
||
+(void)changeArea:(NSString *) data{
|
||
NSLog(@"change area in oc");
|
||
// [[YMVoiceService getInstance] unInit];
|
||
if([data isEqual:@"0"]){
|
||
[[YMVoiceService getInstance] setServerRegion:RTC_JP_SERVER regionName:@"jp" bAppend:false];
|
||
}else if([data isEqual: @"1"]){
|
||
[[YMVoiceService getInstance] setServerRegion:RTC_SG_SERVER regionName:@"sg" bAppend:false];
|
||
}else if([data isEqual: @"2"]){
|
||
[[YMVoiceService getInstance] setServerRegion:RTC_IN_SERVER regionName:@"in" bAppend:false];
|
||
}else if([data isEqual: @"3"]){
|
||
[[YMVoiceService getInstance] setServerRegion:RTC_USM_SERVER regionName:@"usa" bAppend:false];
|
||
}
|
||
|
||
}
|
||
+(void)leaveRoom{
|
||
NSLog(@"leave all channel");
|
||
[[YMVoiceService getInstance] leaveChannelAll];
|
||
}
|
||
+(void)joinRoom:(NSString *) roomid who:(NSString *)who{
|
||
NSLog(@"join room");
|
||
[[YMVoiceService getInstance] joinChannelSingleMode:who channelID:roomid userRole:YOUME_USER_TALKER_FREE ];
|
||
|
||
[[YMVoiceService getInstance] setSpeakerMute:false];
|
||
[[YMVoiceService getInstance] setMicrophoneMute:false];
|
||
[[YMVoiceService getInstance] setVolume:70];
|
||
}
|
||
|
||
//通用事件回调
|
||
- (void)onYouMeEvent:(YouMeEvent_t)eventType errcode:(YouMeErrorCode_t)iErrorCode roomid:(NSString *)roomid param:(NSString *)param
|
||
{
|
||
switch (eventType)
|
||
{
|
||
//case案例只覆盖了部分,仅供参考,详情请查询枚举类型YouMeEvent_t
|
||
case YOUME_EVENT_INIT_OK:
|
||
|
||
NSLog(@"SDK初始化成功!");
|
||
|
||
break;
|
||
case YOUME_EVENT_INIT_FAILED:
|
||
|
||
NSLog(@"SDK初始化失败");
|
||
|
||
break;
|
||
case YOUME_EVENT_JOIN_OK:
|
||
|
||
NSLog(@"加入房间成功");
|
||
|
||
break;
|
||
case YOUME_EVENT_LEAVED_ALL:
|
||
|
||
NSLog(@"离开房间成功");
|
||
|
||
break;
|
||
case YOUME_EVENT_JOIN_FAILED:
|
||
|
||
NSLog(@"加入房间失败");
|
||
|
||
break;
|
||
case YOUME_EVENT_PAUSED:
|
||
|
||
NSLog(@"暂停通话");
|
||
|
||
|
||
break;
|
||
case YOUME_EVENT_RESUMED:
|
||
|
||
NSLog(@"恢复通话");
|
||
|
||
|
||
break;
|
||
case YOUME_EVENT_REC_PERMISSION_STATUS:
|
||
if(iErrorCode == YOUME_ERROR_REC_NO_PERMISSION) {
|
||
NSLog(@"录音启动失败(此时不管麦克风mute状态如何,都没有声音输出");
|
||
}
|
||
break;
|
||
case YOUME_EVENT_RECONNECTING:
|
||
NSLog(@"断网,重连。。。");
|
||
break;
|
||
case YOUME_EVENT_RECONNECTED:
|
||
NSLog(@"重连成功");
|
||
break;
|
||
case YOUME_EVENT_OTHERS_VOICE_ON:
|
||
NSLog(@"UserID:%@ 开始讲话",param);
|
||
break;
|
||
case YOUME_EVENT_OTHERS_VOICE_OFF:
|
||
NSLog(@"UserID:%@ 停止讲话",param);
|
||
break;
|
||
default:
|
||
//"事件类型" + eventType + ",错误码" +
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||
/*
|
||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||
*/
|
||
[[SDKWrapper getInstance] applicationWillResignActive:application];
|
||
}
|
||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||
/*
|
||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||
*/
|
||
[[SDKWrapper getInstance] applicationDidBecomeActive:application];
|
||
}
|
||
|
||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||
/*
|
||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||
*/
|
||
[[SDKWrapper getInstance] applicationDidEnterBackground:application];
|
||
app->applicationDidEnterBackground();
|
||
|
||
}
|
||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||
/*
|
||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||
*/
|
||
[[SDKWrapper getInstance] applicationWillEnterForeground:application];
|
||
app->applicationWillEnterForeground();
|
||
|
||
}
|
||
|
||
- (void)applicationWillTerminate:(UIApplication *)application
|
||
{
|
||
[[SDKWrapper getInstance] applicationWillTerminate:application];
|
||
delete app;
|
||
app = nil;
|
||
}
|
||
|
||
|
||
#pragma mark -
|
||
#pragma mark Memory management
|
||
|
||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||
/*
|
||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||
*/
|
||
}
|
||
|
||
@end
|
||
|
||
|
||
|