upgrade
This commit is contained in:
216
Assets/trCRM/Scripts/call/CallListner.cs
Normal file
216
Assets/trCRM/Scripts/call/CallListner.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Coolape;
|
||||
using UnityEngine.Android;
|
||||
|
||||
public class CallListner : CLBehaviour4Lua
|
||||
{
|
||||
public static CallListner self;
|
||||
const string className = "com.coolape.tianrun.U3dPlugin";
|
||||
#if UNITY_ANDROID
|
||||
AndroidJavaObject _plugin;
|
||||
public AndroidJavaObject plugin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_plugin == null)
|
||||
{
|
||||
_plugin = new AndroidJavaObject(className);
|
||||
}
|
||||
return _plugin;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public CallListner()
|
||||
{
|
||||
self = this;
|
||||
}
|
||||
|
||||
#if UNITY_IOS
|
||||
[System.Runtime.InteropServices.DllImport("__Internal")]
|
||||
private static extern void _init(string goName);
|
||||
#endif
|
||||
|
||||
public void init()
|
||||
{
|
||||
setLua();
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("init", gameObject.name);
|
||||
#elif UNITY_IOS
|
||||
_init(gameObject.name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
string[] permissions = new string[]
|
||||
{
|
||||
"android.permission.RECORD_AUDIO",
|
||||
"android.permission.CALL_PHONE",
|
||||
"android.permission.WRITE_EXTERNAL_STORAGE",
|
||||
"android.permission.READ_EXTERNAL_STORAGE",
|
||||
"android.permission.READ_PHONE_STATE",
|
||||
"android.permission.READ_CALL_LOG",
|
||||
"android.permission.WRITE_CALL_LOG",
|
||||
};
|
||||
|
||||
public void checkUserPermission()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
for (int i = 0; i < permissions.Length; i++)
|
||||
{
|
||||
if (!Permission.HasUserAuthorizedPermission(permissions[i]))
|
||||
{
|
||||
Permission.RequestUserPermission(permissions[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool hadUserPermission()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
for (int i = 0; i < permissions.Length; i++)
|
||||
{
|
||||
if (!Permission.HasUserAuthorizedPermission(permissions[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public void ready2Call(string soundRecordFileName, string onEndCallOrgs)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("begainCall", soundRecordFileName, onEndCallOrgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void waite4Callback(string onEndIncomeCallOrgs)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("waitingIncomeCall", onEndIncomeCallOrgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void prepareMedia(string audioPath, string orgs)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
// object[] paras = new object[] {audioPath, orgs, plugin};
|
||||
|
||||
plugin.Call("prepareMedia", audioPath, orgs);
|
||||
// ThreadEx.exec2(_prepareMedia, paras);
|
||||
#endif
|
||||
}
|
||||
public void _prepareMedia(object paras)
|
||||
{
|
||||
object[] objs = paras as object[];
|
||||
string audioPath = objs[0].ToString();
|
||||
string orgs = objs[1].ToString();
|
||||
#if UNITY_ANDROID
|
||||
AndroidJavaObject _plugin = objs[2] as AndroidJavaObject;
|
||||
Debug.Log("audioPath==" + audioPath);
|
||||
Debug.Log("orgs==" + orgs);
|
||||
Debug.Log(_plugin);
|
||||
|
||||
|
||||
_plugin.Call("prepareMedia", audioPath, orgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void playMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaPlay");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void pauseMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaPause");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void stopMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaStop");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void seekMedia(int progress)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaSeek", progress);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void destroyMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaDestroy");
|
||||
#endif
|
||||
}
|
||||
|
||||
public int getMediaProgress()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
return plugin.Call<int>("getMediaProgress");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("onDestroy");
|
||||
#endif
|
||||
destroyMedia();
|
||||
}
|
||||
|
||||
|
||||
//====================================================
|
||||
//电话接通
|
||||
void onConectedOutGoingCall(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onConectedOutGoingCall"), data);
|
||||
}
|
||||
|
||||
//当通话结速
|
||||
void onEndOutGoingCall(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onEndOutGoingCall"), data);
|
||||
}
|
||||
|
||||
void onEndincomeCall(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onEndincomeCall"), data);
|
||||
}
|
||||
|
||||
void onMediaPrepared(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaPrepared"), data);
|
||||
}
|
||||
|
||||
void onMediaComplet(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaComplet"), data);
|
||||
}
|
||||
void onMediaError(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaError"), data);
|
||||
}
|
||||
|
||||
void onMediaSeek(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaSeek"), data);
|
||||
}
|
||||
|
||||
}
|
||||
12
Assets/trCRM/Scripts/call/CallListner.cs.meta
Normal file
12
Assets/trCRM/Scripts/call/CallListner.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d44f47a2af61343ca8fff87bcc27321e
|
||||
timeCreated: 1487388801
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
91
Assets/trCRM/Scripts/call/RecordManager.cs
Normal file
91
Assets/trCRM/Scripts/call/RecordManager.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Coolape;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class RecordManager : CLBehaviour4Lua
|
||||
{
|
||||
public static RecordManager self;
|
||||
//public static string currentRecord;
|
||||
//public string host = "";
|
||||
//public string user = "";
|
||||
//public string password = "";
|
||||
//public string remotePath = "";
|
||||
public string url = "";
|
||||
public static Hashtable ftpMap = new Hashtable();
|
||||
|
||||
public RecordManager()
|
||||
{
|
||||
self = this;
|
||||
}
|
||||
|
||||
public void upload(string soundPath, string sectionName, object finishCallback)
|
||||
{
|
||||
//this.finishCallback = finishCallback;
|
||||
object[] paras = new object[] { soundPath, finishCallback };
|
||||
//ThreadEx.exec(doUpload, paras);
|
||||
string fileName = Path.GetFileName(soundPath);
|
||||
byte[] bytes = FileEx.ReadAllBytes(soundPath);
|
||||
UnityWebRequest www = WWWEx.uploadFile(url, sectionName, fileName, bytes, CLAssetType.text, (Callback)onUploadFile, (Callback)onUploadFile, paras, false);
|
||||
ftpMap[soundPath] = www;
|
||||
}
|
||||
|
||||
//public void doUpload(object paras)
|
||||
//{
|
||||
// object[] objs = (object[])paras;
|
||||
// string soundFile = objs[0].ToString();
|
||||
// object callback = objs[1];
|
||||
// //FTP ftp = new FTP (host, user, password);
|
||||
// Debug.LogError(host+"===="+ user+"===="+ password);
|
||||
// RenciSFTPHelper ftp = new RenciSFTPHelper(host, user, password);
|
||||
// Debug.LogError("1111111");
|
||||
// if(! ftp.connect())
|
||||
// {
|
||||
// Debug.LogError("connect failed!!!" + host + "====" + user + "====" + password);
|
||||
// onUploadFile(false, 0, soundFile);
|
||||
// return;
|
||||
// }
|
||||
// Debug.LogError("222222222");
|
||||
// ftpMap[Path.GetFileName(soundFile)] = ftp;
|
||||
// //bool ret = ftp.Upload (soundPath, remotePath);
|
||||
// string remoteFile = Path.Combine(remotePath, Path.GetFileName(soundFile));
|
||||
// bool ret = ftp.put(soundFile, remoteFile, (Callback)onUploadFile);
|
||||
//}
|
||||
|
||||
public void onUploadFile(params object[] objs)
|
||||
{
|
||||
string content = objs[0] as string;
|
||||
object[] orgs = objs[1] as object[];
|
||||
string soundPath = orgs[0] as string;
|
||||
object callback = orgs[1];
|
||||
Utl.doCallback(callback, content, soundPath);
|
||||
ftpMap.Remove(soundPath);
|
||||
}
|
||||
|
||||
public float progress(string soudPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(soudPath))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
UnityWebRequest request = ftpMap[soudPath] as UnityWebRequest;
|
||||
if (request != null)
|
||||
{
|
||||
return request.uploadProgress; //ftp;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void abort(string soundPath)
|
||||
{
|
||||
UnityWebRequest request = ftpMap[soundPath] as UnityWebRequest;
|
||||
if (request != null)
|
||||
{
|
||||
request.Dispose();
|
||||
request = null;
|
||||
ftpMap.Remove(soundPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/trCRM/Scripts/call/RecordManager.cs.meta
Normal file
12
Assets/trCRM/Scripts/call/RecordManager.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e5447461c59d40b9862ae086e7d1d68
|
||||
timeCreated: 1487641817
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user