人脸比对
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,33 +1,116 @@
|
||||
import fc from '@/common/publicFc.js'
|
||||
let timer=null
|
||||
let retimer=null
|
||||
import config from "@/common/config.js"
|
||||
let timer = null
|
||||
let retimer = null
|
||||
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
|
||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||
|
||||
export default {
|
||||
socketTask:null,
|
||||
socketTask: null,
|
||||
// 连接WebSocket
|
||||
connectSocket() {
|
||||
this.socketTask=uni.connectSocket({
|
||||
|
||||
const ListenerMap = {
|
||||
onSocketConnectEvent: (option, status, data) => {
|
||||
console.log("已建立连接:" + JSON.stringify(status));
|
||||
},
|
||||
onSocketErrorEvent: (error) => {
|
||||
console.log("连接出现错误:" + userId);
|
||||
},
|
||||
onSocketReConnectEvent: () => {
|
||||
console.log("正在重连:");
|
||||
},
|
||||
onSocketCloseEvent: () => {
|
||||
console.log("连接关闭:");
|
||||
},
|
||||
onSocketReConnectSuccessEvent: () => {
|
||||
console.log("重连成功");
|
||||
},
|
||||
onTestMessage: (e) => {
|
||||
console.log("onTestMessage :" + e);
|
||||
},
|
||||
onP2PMessage: (e) => {
|
||||
console.log("onP2PMessage :" + e);
|
||||
e = JSON.parse(e)
|
||||
e.pushType="TEXT"
|
||||
uni.$emit('onP2PMessage', e.data);
|
||||
},
|
||||
onLogin: (uid) => {
|
||||
console.log("用户" + uid + "登陆sdk成功");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
const userId = uni.getStorageSync("userId")
|
||||
const imUserSign = uni.getStorageSync("imUserSign")
|
||||
|
||||
var listeners = {};
|
||||
for (const v in ListenerMap) {
|
||||
listeners[v] = ListenerMap[v];
|
||||
}
|
||||
|
||||
console.log(lim)
|
||||
|
||||
if (this.socketTask != null) {
|
||||
return false
|
||||
}
|
||||
|
||||
lim.lim.im.init(config.getImApiUrl(), config.getImAppId(), userId, imUserSign, listeners, (
|
||||
sdk) => {
|
||||
if (sdk) {
|
||||
console.warn("====================")
|
||||
this.socketTask = sdk;
|
||||
console.log(this.socketTask)
|
||||
|
||||
console.log('sdk 成功连接的回调, 可以使用 sdk 请求数据了.');
|
||||
sdk.getAllFriend().then(res => {
|
||||
console.warn(res)
|
||||
})
|
||||
sdk.getUserSequence().then(res => {
|
||||
console.warn(res)
|
||||
})
|
||||
|
||||
sdk.getUserConversationList(0).then(res => {
|
||||
console.warn(res)
|
||||
})
|
||||
|
||||
return uni.switchTab({
|
||||
url: "/pages/tabbar/index/index"
|
||||
})
|
||||
} else {
|
||||
console.log('sdk 初始化失败.');
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
|
||||
this.socketTask = uni.connectSocket({
|
||||
url: 'wss://im-api.q3z3.com/ws?Authorization=' + uni.getStorageSync('Authorization'),
|
||||
complete: () => {}
|
||||
});
|
||||
this.socketTask.onOpen(res => {
|
||||
console.log('WebSocket连接已打开!');
|
||||
// 设置心跳
|
||||
timer=setInterval(()=>{
|
||||
timer = setInterval(() => {
|
||||
uni.sendSocketMessage({
|
||||
data:'isConnact',
|
||||
success:res=>{
|
||||
if(res.errMsg=='sendSocketMessage:ok'){
|
||||
data: 'isConnact',
|
||||
success: res => {
|
||||
if (res.errMsg == 'sendSocketMessage:ok') {
|
||||
console.log('WebSocket已连接')
|
||||
}else{
|
||||
} else {
|
||||
this.connectSocket()
|
||||
}
|
||||
}
|
||||
})
|
||||
},5000)
|
||||
}, 5000)
|
||||
})
|
||||
// 监听接收
|
||||
this.socketTask.onMessage(res => {
|
||||
if(res.data=='ok'){
|
||||
if (res.data == 'ok') {
|
||||
return
|
||||
}
|
||||
var data = JSON.parse(res.data);
|
||||
@@ -37,34 +120,35 @@ export default {
|
||||
// 监听关闭
|
||||
this.socketTask.onClose(res => {
|
||||
console.log('WebSocket连接已关闭!');
|
||||
let token= uni.getStorageSync('Authorization');
|
||||
if(this.socketTask&&token){
|
||||
let token = uni.getStorageSync('Authorization');
|
||||
if (this.socketTask && token) {
|
||||
this.socketTaskClose()
|
||||
retimer=setTimeout(()=>{
|
||||
retimer = setTimeout(() => {
|
||||
this.connectSocket()
|
||||
},5000)
|
||||
}, 5000)
|
||||
}
|
||||
})
|
||||
// 监听异常
|
||||
this.socketTask.onError(res => {
|
||||
console.log('WebSocket连接打开失败,正在尝试重新打开!');
|
||||
if(this.socketTask){
|
||||
if (this.socketTask) {
|
||||
this.socketTaskClose()
|
||||
retimer=setTimeout(()=>{
|
||||
retimer = setTimeout(() => {
|
||||
this.connectSocket()
|
||||
},5000)
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
},
|
||||
// 关闭WebSocket
|
||||
socketTaskClose() {
|
||||
if(this.socketTask){
|
||||
if (this.socketTask) {
|
||||
this.socketTask.close()
|
||||
clearInterval(timer)
|
||||
clearTimeout(retimer)
|
||||
console.log('关闭WebSocket!');
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,6 @@ import http from '@/common/request'
|
||||
import store from './store'
|
||||
import md5 from "@/common/md5.js";
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
|
||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||
|
||||
|
||||
import publicFc from "@/common/publicFc.js";
|
||||
@@ -21,6 +18,9 @@ import App from './App'
|
||||
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
Vue.prototype.$socketTask = socketTask;
|
||||
|
||||
Vue.prototype.$http = http
|
||||
Vue.prototype.$store = store
|
||||
Vue.prototype.$fc = publicFc;
|
||||
@@ -28,7 +28,7 @@ Vue.prototype.$md5 = md5
|
||||
Vue.prototype.$zmmFormCheck = zmmFormCheck;
|
||||
Vue.prototype.$pinyin = pinyin;
|
||||
// #ifdef H5
|
||||
Vue.prototype.$socketTask = socketTask;
|
||||
|
||||
|
||||
// uni.lim = lim;
|
||||
|
||||
@@ -50,15 +50,15 @@ import { createSSRApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.config.globalProperties.$socketTask = socketTask
|
||||
|
||||
app.config.globalProperties.$http = http
|
||||
app.config.globalProperties.$fc = publicFc
|
||||
app.config.globalProperties.$md5 = md5
|
||||
app.config.globalProperties.$zmmFormCheck = zmmFormCheck
|
||||
app.config.globalProperties.$pinyin = pinyin
|
||||
// #ifdef H5
|
||||
app.config.globalProperties.$socketTask = socketTask
|
||||
|
||||
app.config.globalProperties.imsdk = lim
|
||||
|
||||
|
||||
// #endif
|
||||
app.use(store);
|
||||
|
||||
@@ -132,11 +132,12 @@ import { createStore } from 'vuex'
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatlistData', JSON.stringify(data2));
|
||||
// 初始化聊天数据
|
||||
var data1=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatData')
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject)=>{
|
||||
if(!data1[userId]){
|
||||
console.log('初始化聊天')
|
||||
switch (windowType){
|
||||
case 'SINGLE':
|
||||
|
||||
http.request({
|
||||
url: '/friend/info/'+userId,
|
||||
complete:(res)=>{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,9 +45,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// #ifdef APP-PLUS
|
||||
const TUICalling = uni.requireNativePlugin("TUICallingUniPlugin-TUICallingModule");
|
||||
// #endif
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -223,7 +221,9 @@
|
||||
uni.setStorageSync('appId', data.appId);
|
||||
uni.setStorageSync('userId', data.userId);
|
||||
uni.setStorageSync('imUserSign', data.imUserSign);
|
||||
uni.setStorageSync('userSign', data.userSign);
|
||||
uni.setStorageSync('userCSign', data.userSign);
|
||||
|
||||
this.$socketTask.connectSocket()
|
||||
|
||||
uni.reLaunch({
|
||||
url: '../tabbar1/index'
|
||||
|
||||
@@ -21,39 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import config from "@/common/config.js"
|
||||
|
||||
|
||||
|
||||
const ListenerMap = {
|
||||
onSocketConnectEvent: (option, status, data) => {
|
||||
console.log("已建立连接:" + JSON.stringify(status));
|
||||
},
|
||||
onSocketErrorEvent: (error) => {
|
||||
console.log("连接出现错误:" + userId);
|
||||
},
|
||||
onSocketReConnectEvent: () => {
|
||||
console.log("正在重连:");
|
||||
},
|
||||
onSocketCloseEvent: () => {
|
||||
console.log("连接关闭:");
|
||||
},
|
||||
onSocketReConnectSuccessEvent: () => {
|
||||
console.log("重连成功");
|
||||
},
|
||||
onTestMessage: (e) => {
|
||||
console.log("onTestMessage :" + e);
|
||||
},
|
||||
onP2PMessage: (e) => {
|
||||
console.log("onP2PMessage :" + e);
|
||||
e = JSON.parse(e)
|
||||
uni.$emit('P2PMessage', e.data);
|
||||
},
|
||||
onLogin: (uid) => {
|
||||
console.log("用户" + uid + "登陆sdk成功");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export default {
|
||||
@@ -191,43 +159,10 @@
|
||||
},
|
||||
mounted() {
|
||||
|
||||
console.log(this.imsdk)
|
||||
|
||||
|
||||
var listeners = {};
|
||||
for (const v in ListenerMap) {
|
||||
listeners[v] = ListenerMap[v];
|
||||
}
|
||||
this.$socketTask.connectSocket()
|
||||
|
||||
|
||||
const userId=uni.getStorageSync("userId")
|
||||
const imUserSign=uni.getStorageSync("imUserSign")
|
||||
|
||||
console.log(this.imsdk)
|
||||
|
||||
this.imsdk.lim.im.init(config.getImApiUrl(),config.getImAppId(),userId,imUserSign, listeners, function(
|
||||
sdk) {
|
||||
if (sdk) {
|
||||
console.log('sdk 成功连接的回调, 可以使用 sdk 请求数据了.');
|
||||
sdk.getAllFriend().then(res=>{
|
||||
console.warn(res)
|
||||
})
|
||||
sdk.getUserSequence().then(res=>{
|
||||
console.warn(res)
|
||||
})
|
||||
|
||||
sdk.getUserConversationList(0).then(res=>{
|
||||
console.warn(res)
|
||||
})
|
||||
|
||||
return uni.switchTab({
|
||||
url: "/pages/tabbar/index/index"
|
||||
})
|
||||
} else {
|
||||
console.log('sdk 初始化失败.');
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
})
|
||||
*/
|
||||
uni.navigateTo({
|
||||
url: '../chatWindow/index?userId=' + e.item.data.userId + '&windowType=' + e.windowType
|
||||
url: '../chatWindow/index?userId=' + e.item.data.userId + '&windowType=' + "SINGLE"
|
||||
});
|
||||
},
|
||||
getflist(){
|
||||
|
||||
Reference in New Issue
Block a user