This commit is contained in:
2020-08-26 19:56:45 +08:00
parent 7ff6b2ec35
commit 3ece010fc1
208 changed files with 14753 additions and 637 deletions

View File

@@ -0,0 +1,226 @@
-- 去电监听
CLLCallListner = {}
local Permission
if CLPathCfg.self.platform == "Android" then
Permission = CS.UnityEngine.Android.Permission
end
---@type CallListner
local csSelf = CallListner.self
local transform = nil
local dataUploadQueue = Queue()
local isWaiting4IncomeCall = false
local endIncomeCallParms
local permissions = {
"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"
}
-- 初始化,只会调用一次
function CLLCallListner.init(csObj)
csSelf = csObj
transform = csObj.transform
end
function CLLCallListner.checkAndSetUserPermission(callback)
if not CLLCallListner.hadUserPermission() then
CLLCallListner.checkUserPermission()
InvokeEx.invoke(CLLCallListner.checkAndSetUserPermission, callback, 2)
else
Utl.doCallback(callback)
end
end
function CLLCallListner.ready2Call(callback, custPhone)
local soundRecordFile = CLLRecordMgr.getSoundRecordFile()
local orgs = Hashtable()
orgs.callback = callback
orgs.soundRecordFile = soundRecordFile
orgs.phone = custPhone
orgs.created_time = DateEx.nowString()
orgs.answered_time = DateEx.nowString()
csSelf:ready2Call(soundRecordFile, JSON.JsonEncode(orgs))
end
function CLLCallListner.waite4Callback(ors)
isWaiting4IncomeCall = true
endIncomeCallParms = ors
csSelf:waite4Callback(ors)
end
function CLLCallListner.hadUserPermission()
-- return csSelf:hadUserPermission()
if CLPathCfg.self.platform == "Android" and Permission then
for i, v in ipairs(permissions) do
if not Permission.HasUserAuthorizedPermission(v) then
return false
end
end
end
return true
end
function CLLCallListner.checkUserPermission()
if CLPathCfg.self.platform == "Android" and Permission then
for i, v in ipairs(permissions) do
if not Permission.HasUserAuthorizedPermission(v) then
Permission.RequestUserPermission(v)
end
end
end
end
--电话接通
function CLLCallListner.onConectedOutGoingCall(recordFile)
print("CLLCallListner.onConectedOutGoingCall===" .. recordFile)
end
function CLLCallListner.prepareMedia(soundUrl, onPrepareMedia, onMediaComplet, onMediaSeek, onMediaError, orgs)
orgs.onPrepareMedia = onPrepareMedia
orgs.onMediaComplet = onMediaComplet
orgs.onMediaSeek = onMediaSeek
orgs.onMediaError = onMediaError
csSelf:prepareMedia(soundUrl, JSON.JsonEncode(orgs))
end
function CLLCallListner.play()
csSelf:playMedia()
end
function CLLCallListner.pause()
csSelf:pauseMedia()
end
function CLLCallListner.stop()
csSelf:stopMedia()
end
function CLLCallListner.destroyMedia()
csSelf:destroyMedia()
end
function CLLCallListner.seekMedia(progress)
csSelf:seekMedia(progress)
end
function CLLCallListner.getMediaProgress()
return csSelf:getMediaProgress()
end
-- function CLLCallListner.Update()
-- if (dataUploadQueue.Count > 0) then
-- local d = dataUploadQueue:Dequeue()
-- CLLCallListner.doCallbackProc(d)
-- end
-- end
----------------------------------------------------------
-- 当通话结速
function CLLCallListner.onEndOutGoingCall(jsonStr)
print("CLLCallListner.onEndOutGoingCall=====" .. jsonStr)
CLLCallListner.procEndCall(jsonStr)
end
function CLLCallListner.onEndincomeCall(jsonStr)
print("CLLCallListner.onEndincomeCall=====" .. jsonStr)
CLLCallListner.procEndCallIncoming(jsonStr)
end
function CLLCallListner.procEndCallIncoming(jsonStr)
-- local data = json.decode(jsonStr)
-- if (data == nil) then
-- return
-- end
-- local orgsStr = data.orgs
-- local orgs = (not isNilOrEmpty(orgsStr)) and json.decode(orgsStr) or nil
local data = {}
data.orgs = (not isNilOrEmpty(endIncomeCallParms)) and json.decode(endIncomeCallParms) or nil
local incomingNumber = data.code
if true then --//TODO:判断打进来的电话是否是回拨号码
if isWaiting4IncomeCall then
CLLCallListner.doCallbackProc(data)
end
isWaiting4IncomeCall = false
end
end
function CLLCallListner.procEndCall(jsonStr)
local data = json.decode(jsonStr)
if (data == nil) then
return
end
local orgsStr = data.orgs
local orgs = json.decode(orgsStr)
orgs.over_time = DateEx.nowString()
data.orgs = orgs
CLLCallListner.doCallbackProc(data)
end
function CLLCallListner.doCallbackProc(data)
local orgs = data.orgs
local callback = getLuaFunc(orgs.callback)
if (callback ~= nil) then
callback(orgs)
end
end
--[[
function CLLCallListner.onMediaPrepared(jsonStr)
local data = json.decode(jsonStr)
if (data == nil) then
return
end
local mediaLen = data.code
local orgsStr = data.orgs
local orgs = json.decode(orgsStr)
orgs.mediaLen = mediaLen
orgs.callback = orgs.onPrepareMedia
data.orgs = orgs
dataUploadQueue:Enqueue(data)
end
function CLLCallListner.onMediaComplet(jsonStr)
local data = json.decode(jsonStr)
if (data == nil) then
return
end
local orgsStr = data.orgs
local orgs = json.decode(orgsStr)
orgs.callback = orgs.onMediaComplet
data.orgs = orgs
dataUploadQueue:Enqueue(data)
end
function CLLCallListner.onMediaError(jsonStr)
local data = json.decode(jsonStr)
if (data == nil) then
return
end
local orgsStr = data.orgs
local orgs = json.decode(orgsStr)
orgs.callback = orgs.onMediaError
data.orgs = orgs
dataUploadQueue:Enqueue(data)
end
function CLLCallListner.onMediaSeek(jsonStr)
local data = json.decode(jsonStr)
if (data == nil) then
return
end
local orgsStr = data.orgs
local orgs = json.decode(orgsStr)
orgs.callback = orgs.onMediaSeek
data.orgs = orgs
dataUploadQueue:Enqueue(data)
end
]]
--------------------------------------------
return CLLCallListner

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f8e057cacf5ed44d49298c665577783d
timeCreated: 1487389984
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,202 @@
-- 录音管理
CLLRecordMgr = {}
local csSelf = RecordManager.self
local isBegainUpload = false
local SoundRecordRoot = PStr.b():a(CLPathCfg.self.basePath):a("/SoundRecords/"):e()
local SoundRecordFinishPath = PStr.b():a(SoundRecordRoot):a("Finished/"):e()
local SoundRecordUploadPath = PStr.b():a(SoundRecordRoot):a("Upload/"):e()
local isFinishUpload = false
local isUploading = false
local isInited = false
local finishUploadQueue = Queue()
function CLLRecordMgr.getLocalRecord(recordName)
local filePath = ""
filePath = PStr.b():a(CLLRecordMgr.getSoundRecordFinishPath()):a(recordName):e()
if (File.Exists(filePath)) then
return filePath
end
filePath = PStr.b():a(CLLRecordMgr.getSoundRecordUploadPath()):a(recordName):e()
if (File.Exists(filePath)) then
return filePath
end
filePath = PStr.b():a(CLLRecordMgr.getSoundRecordBasePath()):a(recordName):e()
if (File.Exists(filePath)) then
return filePath
end
end
function CLLRecordMgr.getData()
return finishUploadQueue
end
function CLLRecordMgr.init()
--csSelf.host = Prefs.getHost();
--csSelf.user = "app";
--csSelf.password = "app";
--csSelf.remotePath = "/";
csSelf.url = "http://39.106.144.191:29002/httpService/uploadMp3"
end
function CLLRecordMgr.begainUpload()
if (isBegainUpload) then
return
end
isBegainUpload = true
CLLRecordMgr.uploadAll()
end
function CLLRecordMgr.canUpload()
local netState = Utl.getNetState()
if isUploading then
CLAlert.add("正在上传其它录音文件,请稍后再试!", Color.white, 1)
return false
elseif netState == "None" then
CLAlert.add("网络不可用,无法上传!", Color.white, 1)
return false
else
return true
end
end
function CLLRecordMgr.uploadAll()
local netState = Utl.getNetState()
if
((netState == "WiFi" and (not Prefs.getisWifiRecord())) or
(netState ~= "WiFi" and (not Prefs.getisMobileRecord())) or
isUploading)
then
-- 只有wifi情况下上传
csSelf:cancelInvoke4Lua(CLLRecordMgr.uploadAll)
csSelf:invoke4Lua(CLLRecordMgr.uploadAll, nil, 5, true)
return
end
local localDir = CLLRecordMgr.getSoundRecordUploadPath()
if (not Directory.Exists(localDir)) then
return
end
local fileList = Directory.GetFiles(localDir)
if (fileList ~= nil and fileList.Length > 0) then
isUploading = true
CLLRecordMgr.upLoad(fileList[0])
else
csSelf:cancelInvoke4Lua(CLLRecordMgr.uploadAll)
csSelf:invoke4Lua(CLLRecordMgr.uploadAll, nil, 5, true)
end
end
-- 把录音文件移动到需要更新的目录中
function CLLRecordMgr.moveRecord2Upload(soundFile)
local recordName = Path.GetFileName(soundFile)
local fromPath = PStr.b():a(CLLRecordMgr.getSoundRecordBasePath()):a(recordName):e()
local desPath = PStr.b():a(CLLRecordMgr.getSoundRecordUploadPath()):a(recordName):e()
FileEx.CreateDirectory(Path.GetDirectoryName(desPath))
File.Move(fromPath, desPath)
end
function CLLRecordMgr.upLoad(soudFile)
isUploading = true
CLLRecordMgr.init()
print(soudFile)
local recordName = Path.GetFileName(soudFile)
local recordFile = PStr.b():a(CLLRecordMgr.getSoundRecordUploadPath()):a(recordName):e()
if (File.Exists(recordFile)) then
csSelf:upload(recordFile, CLLRecordMgr.onFinishUpload)
else
isUploading = false
print("The file not exist.==" .. recordFile)
end
end
function CLLRecordMgr.onFinishUpload(ret, soundFile)
print("CLLRecordMgr.onFinishUpload==" .. soundFile)
isUploading = false
if (ret) then
local m = JSON.DecodeMap(ret)
if m.error == 0 then
finishUploadQueue:Enqueue(Path.GetFileName(soundFile))
end
end
isFinishUpload = true
end
function CLLRecordMgr.getProgress(recordName)
return csSelf:progress(Path.GetFileName(recordName))
end
function CLLRecordMgr.Update()
if (finishUploadQueue.Count > 0) then
local uploadedRecord = finishUploadQueue:Dequeue()
--通知服务器
if (uploadedRecord ~= nil and uploadedRecord ~= "") then
-- local soundName = Path.GetFileName(uploadedRecord);
CLLNet.upgradeRecord(uploadedRecord)
-- Move path
local fromPath = PStr.b():a(CLLRecordMgr.getSoundRecordUploadPath()):a(uploadedRecord):e()
local desPath = PStr.b():a(CLLRecordMgr.getSoundRecordFinishPath()):a(uploadedRecord):e()
FileEx.CreateDirectory(Path.GetDirectoryName(desPath))
print("fromPath==" .. fromPath)
print("desPath==" .. desPath)
File.Move(fromPath, desPath)
end
end
if (isFinishUpload) then
isFinishUpload = false
csSelf:cancelInvoke4Lua(CLLRecordMgr.uploadAll)
csSelf:invoke4Lua(CLLRecordMgr.uploadAll, nil, 2, true)
end
end
function CLLRecordMgr.getSoundRecordBasePath()
local sdCard = "/sdcard/"
local basePath = PStr.b():a(sdCard):a(SoundRecordRoot):e()
return basePath
end
function CLLRecordMgr.getSoundRecordUploadPath()
local sdCard = "/sdcard/"
local basePath = PStr.b():a(sdCard):a(SoundRecordUploadPath):e()
return basePath
end
function CLLRecordMgr.getSoundRecordFinishPath()
local sdCard = "/sdcard/"
local basePath = PStr.b():a(sdCard):a(SoundRecordFinishPath):e()
return basePath
end
-- 取得录音文件名
function CLLRecordMgr.getSoundRecordFile()
local sdCard = "/sdcard/"
if (sdCard == "" or (not Directory.Exists(sdCard))) then
CLAlert.add("无法记录通话录音,请确认是否有SD卡", Color.white, 1)
return ""
end
local basePath = PStr.b():a(sdCard):a(SoundRecordRoot):e()
local ret = PStr.b():a(basePath):a("app_"):a(Utl.uuid):a("_"):a(DateEx.nowMS):a(".mp3"):e()
FileEx.CreateDirectory(Path.GetDirectoryName(ret))
return ret
end
function CLLRecordMgr.delRecords()
local fileList = Directory.GetFiles(CLLRecordMgr.getSoundRecordBasePath())
for i = 0, fileList.Length - 1 do
FileEx.Delete(fileList[i])
end
fileList = Directory.GetFiles(CLLRecordMgr.getSoundRecordFinishPath())
for i = 0, fileList.Length - 1 do
FileEx.Delete(fileList[i])
end
end
--------------------------------------------
return CLLRecordMgr

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f160e626a759c49e1ad86c524a24e782
timeCreated: 1487643335
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant: