socket.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. const {
  2. io
  3. } = require('./socket.io-v4.msgpack.js');
  4. var user = require('./services/user.js');
  5. const api = require('/config/api.js');
  6. const util = require('/utils/util.js');
  7. const UNLOGIN = 'NO_LOGIN'
  8. const btoa = require('./utils/btoa');
  9. const manyCount = 50
  10. import remote from './config.js'
  11. var app = getApp();
  12. var isIos = false
  13. wx.getSystemInfo({
  14. success: function (res) {
  15. isIos = res.platform == "ios"
  16. }
  17. })
  18. const debounce = (fn, wait) => {
  19. let callback = fn;
  20. let timerId = null;
  21. function debounced() {
  22. let context = this;
  23. let args = arguments;
  24. clearTimeout(timerId);
  25. timerId = setTimeout(function () {
  26. callback.apply(context, args);
  27. }, wait);
  28. }
  29. return debounced;
  30. }
  31. let urlToJson = (url = window.location.href) => { // 箭头函数默认传值为当前页面url
  32. let obj = {},
  33. index = url.indexOf('?'), // 看url有没有参数
  34. params = url.substr(index + 1); // 截取url参数部分 id = 1 & type = 2
  35. if (index != -1) { // 有参数时
  36. let parr = params.split('&'); // 将参数分割成数组 ["id = 1 ", " type = 2"]
  37. for (let i of parr) { // 遍历数组
  38. let arr = i.split('='); // 1) i id = 1 arr = [id, 1] 2)i type = 2 arr = [type, 2]
  39. obj[arr[0]] = arr[1]; // obj[arr[0]] = id, obj.id = 1 obj[arr[0]] = type, obj.type = 2
  40. }
  41. }
  42. return obj;
  43. }
  44. export default {
  45. joinUrl() {
  46. let url = this.data.url;
  47. //隐藏部分
  48. // if (this.data.url && /smobile.html/.test(this.data.url)) {
  49. // const newUrl = this.data.url.replace('smobile.html', 'shop.html')
  50. // url = newUrl
  51. // this.setData({
  52. // url: newUrl
  53. // });
  54. // }
  55. let options = {
  56. API_BASE_URL: api.API_BASE_URL,
  57. "url": url,
  58. // "url": 'http://192.168.0.112:8080',
  59. "reload": this.data.reload,
  60. "token": wx.getStorageSync('token'),
  61. "code": this.mcode,
  62. "brandId": this.options.id,
  63. "open": this.data.showCommodity,
  64. "pauseVideo": this.pauseVideo,
  65. "bottom": this.data.bottom || 0,
  66. socket: {
  67. socketHost: remote.socketHost,
  68. path: '/new-zfb',
  69. options: {
  70. ...this.data.socketOptions,
  71. // nickname: encodeURI(encodeURI(this.data.socketOptions.nickname))
  72. nickname: encodeURIComponent(encodeURIComponent(this.data.socketOptions.nickname))
  73. }
  74. }
  75. }
  76. // let base = 'http://127.0.0.1:5500/index.html'
  77. // let base = remote.viewHost + '/shop-container/shop.html'
  78. let sponsor = !!this.data.canShow
  79. if (this.data.join && !this.options.join) {
  80. sponsor = false
  81. }
  82. // 33是从我的房间出来的
  83. if (Number(this.data.type) === 33) {
  84. sponsor = true;
  85. }
  86. // debugger
  87. // remote.viewHost
  88. let hostUrl
  89. if (options.url.indexOf('www.4dkankan.com') != -1) {
  90. hostUrl = 'https://www.4dkankan.com/shop-container-zfb/'
  91. } else if (options.url.indexOf('test.4dkankan.com') != -1) {
  92. hostUrl = 'https://test.4dkankan.com/shop-container-zfb/'
  93. } else {
  94. // hostUrl = 'https://zfb.4dkankan.com/shop-container/'
  95. // hostUrl = remote.viewHost + '/shop-container/'
  96. hostUrl = remote.viewHost + '/shop-container-v4/'
  97. }
  98. // let base = remote.viewHost + '/shop-container/fashilong.html?env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
  99. let base = hostUrl + 'fashilong.html?time=' + Date.now() + '&env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
  100. // let base = remote.viewHost + '/shop.html'
  101. this.data.reload = false
  102. this.data.showCommodity = false
  103. //上线前隐藏Vlog
  104. // options.url = options.url + '&vlog';
  105. if (!this.data.webviewUrl) {
  106. console.log(base)
  107. this.setData({
  108. 'webviewUrl': base + '#' + JSON.stringify(options)
  109. })
  110. } else {
  111. this.socketSendMessage('clientSyncAction', {
  112. sender: 'h5',
  113. type: 'hashChange',
  114. data: options
  115. })
  116. }
  117. },
  118. onShow() {
  119. this.setData({
  120. isIos,
  121. showComtypesAllTab: false
  122. })
  123. // wx.showToast({
  124. // title: '测试--socket.connected' + this.socket.connected,
  125. // })
  126. const onlineAction = () => {
  127. this.pauseVideo = false
  128. this.joinUrl()
  129. // debugger
  130. this.socketSendMessage('changeOnlineStatus', {
  131. status: 1
  132. })
  133. }
  134. console.warn("socketInstance-1", this.socketInstance);
  135. if (this.socketInstance) {
  136. if (!this.socketInstance.connected) {
  137. // wx.showToast({
  138. // title: 'socketInstance-2',
  139. // icon: 'none',
  140. // duration: 5000
  141. // })
  142. // this.socketInstance.connect();
  143. // wx.showModal({
  144. // title: '提示',
  145. // content: '欧克',
  146. // showCancel: false,
  147. // confirmColor: '#0075DC',
  148. // success: function (res) {}
  149. // })
  150. setTimeout(onlineAction, 300)
  151. } else {
  152. // wx.showToast({
  153. // title: 'socketInstance-3',
  154. // icon: 'none',
  155. // duration: 5000
  156. // })
  157. onlineAction();
  158. }
  159. }
  160. // if (this.socketSendMessage) {
  161. // this.pauseVideo = false
  162. // this.joinUrl()
  163. // // debugger
  164. // this.socketSendMessage('changeOnlineStatus', {
  165. // status: 1
  166. // })
  167. // }
  168. },
  169. changeShowComtypesAllTab(ev) {
  170. this.setData({
  171. showCommodity: false
  172. })
  173. setTimeout(() => {
  174. this.setData({
  175. showComtypesAllTab: ev.currentTarget.dataset.show,
  176. showCommodity: true
  177. })
  178. }, 100)
  179. },
  180. async authorizeRecord() {
  181. let isAuth = await new Promise((r, j) => {
  182. wx.authorize({
  183. scope: 'scope.record',
  184. success: () => r(true),
  185. fail: () => r(false)
  186. })
  187. })
  188. if (isAuth) return true
  189. let res = await new Promise(r => {
  190. wx.showModal({
  191. title: '提示',
  192. content: '您未授权录音,说话功能将无法使用',
  193. showCancel: true,
  194. confirmText: "授权",
  195. confirmColor: "#52a2d8",
  196. success: res => r(res),
  197. fail: () => r(false)
  198. })
  199. })
  200. if (!res || res.cancel) return;
  201. isAuth = await new Promise((r) => {
  202. wx.openSetting({
  203. success: res => r(res.authSetting['scope.record']),
  204. fail: () => r(false)
  205. })
  206. })
  207. return isAuth
  208. },
  209. // 获取录音权限状态
  210. async getAuthorizeRecordStatus() {
  211. const isAuth = await new Promise((r, j) => {
  212. wx.authorize({
  213. scope: 'scope.record',
  214. success: () => r(true),
  215. fail: () => r(false)
  216. })
  217. })
  218. return Promise.resolve(isAuth)
  219. },
  220. async agetUserInfo() {
  221. const res = await util.request(api.UserInfo)
  222. if (res.errno === 401) {
  223. return {
  224. userId: UNLOGIN,
  225. avatar: ''
  226. }
  227. } else {
  228. const data = res.data
  229. data.region = data.city ? data.city.split(',') : []
  230. data.birthday = data.birthday || '1990-01-01'
  231. return data
  232. }
  233. },
  234. async getUserInfo() {
  235. let userInfo = wx.getStorageSync('userInfo');
  236. let token = wx.getStorageSync('token');
  237. if (userInfo && userInfo.userId && token) {
  238. let info = await this.agetUserInfo()
  239. return {
  240. ...userInfo,
  241. ...info,
  242. avatarUrl: info.avatar
  243. };
  244. } else {
  245. return {
  246. userId: UNLOGIN,
  247. avatar: ''
  248. }
  249. }
  250. // let detail
  251. // let isAuth = await new Promise((r, j) => {
  252. // wx.authorize({
  253. // scope: 'scope.userInfo',
  254. // success: () => r(true),
  255. // fail: () => r(false)
  256. // })
  257. // })
  258. // if (!isAuth) {
  259. // this.setData({userAuth: true})
  260. // detail = await new Promise(r => {
  261. // this.bindGetUserInfo = (e) => {
  262. // if (e.detail.userInfo) {
  263. // this.setData({userAuth: false})
  264. // console.log('gei', e.detail)
  265. // r(e.detail)
  266. // }
  267. // }
  268. // })
  269. // } else {
  270. // detail = await new Promise(r => {
  271. // wx.getUserInfo({
  272. // success: res => r(res),
  273. // fail: () => r(false)
  274. // })
  275. // })
  276. // }
  277. // try {
  278. // let res = await user.loginByWeixin(detail)
  279. // app.globalData.userInfo = res.data.userInfo;
  280. // app.globalData.token = res.data.token;
  281. // return res.data.userInfo
  282. // } catch(e) {
  283. // return false
  284. // }
  285. },
  286. login() {
  287. getApp().setLoginProps(false)
  288. },
  289. async getSocketOptions(sceneId, roomId) {
  290. //TODO
  291. console.log('this.data.type', this.data.type)
  292. // debugger;
  293. let result
  294. if (Number(this.data.type) === 33) {
  295. result = await util.request(api.enterRoom, {
  296. businessId: roomId
  297. }, 'POST', 'application/json')
  298. if (result.code !== 200) {
  299. wx.showModal({
  300. content: result.error,
  301. complete: () => {
  302. if (result.message && result.message.isAnchor == 0) {
  303. wx.switchTab({
  304. url: '/pages/index/index',
  305. })
  306. } else {
  307. wx.redirectTo({
  308. url: '/pages/roomManger/roomManger',
  309. });
  310. }
  311. }
  312. })
  313. return
  314. }
  315. }
  316. const capacities = !!result ? result.message.capacities : 50 // 房间限制人数
  317. const {
  318. isAnchor,
  319. assistant,
  320. } = !!result ? result.message : {}
  321. let userInfo = await this.getUserInfo()
  322. // console.log('---', userInfo)
  323. // this.setData({
  324. // userInfoa: userInfo.nickname.split('').join(' ')
  325. // })
  326. userInfo.nickname = userInfo.nickname.replace(/[^\u4E00-\u9FA5A-Za-z0-9]/g, '')
  327. if (userInfo.nickname == "") {
  328. userInfo.nickname = "口"
  329. }
  330. // this.role !== 'leader'
  331. // let roomType
  332. // if ((!this.data.canShow && !this.data.join) || (this.data.join && !this.options.join)) {
  333. // // roomType = '1v1'
  334. // if (this.options.roomId) {
  335. // this.role = 'leader'
  336. // }
  337. // console.log('**************')
  338. // console.log(this.options)
  339. // }
  340. let isAllowMic // 真正MIC权, 房主与 授权一个 要在房间isAllowMic开启
  341. if (Number(isAnchor) === 1) {
  342. this.role = "leader"
  343. isAllowMic = 1
  344. } else {
  345. this.role = 'customer'
  346. isAllowMic = 0
  347. }
  348. // 助手改用isAssistant作为flag, role因为V3不能新增角色,只支持leader/customer。
  349. let isAssistant
  350. if (assistant && assistant.userId && assistant.userId == userInfo.userId) {
  351. isAssistant = true;
  352. } else {
  353. isAssistant = false
  354. }
  355. console.log('进入房间角色, 是否助手 %s', this.role, isAssistant);
  356. const isAuthMic = await this.getAuthorizeRecordStatus();
  357. // console.log('当前用户录音权限状态', isAuthMic)
  358. this.setData({
  359. isAllowMic,
  360. isAuthMic
  361. })
  362. const assistantId = (assistant && assistant.userId) ? assistant.userId : '';
  363. if (capacities) {
  364. this.setData({
  365. peopleCount: capacities
  366. })
  367. } else {
  368. this.setData({
  369. peopleCount: manyCount
  370. })
  371. }
  372. return {
  373. role: this.role,
  374. userId: userInfo.userId,
  375. // roomType,
  376. avatar: userInfo.avatarUrl,
  377. nickname: userInfo.nickname,
  378. voiceStatus: getApp().globalData.voiceProps.noMute ? 0 : 2,
  379. isAuthMic: isAuthMic ? 1 : 0,
  380. isAllowMic: isAllowMic,
  381. roomId: roomId,
  382. sceneNumber: sceneId,
  383. onlineStatus: 1,
  384. assistantId: assistantId,
  385. isAssistant: isAssistant ? 1 : 0,
  386. oid: userInfo.weixin_openid,
  387. userLimitNum: capacities || 50
  388. }
  389. },
  390. async socketStart({
  391. sceneId,
  392. roomId,
  393. options
  394. }) {
  395. if (!options) {
  396. options = await this.getSocketOptions(sceneId, roomId)
  397. }
  398. console.log('小程序参数', options)
  399. if (!options.roomId) {
  400. return Promise.resolve(false)
  401. }
  402. // 真正进入统计
  403. if (options.roomId !== '888888') {
  404. util.request(api.trackRoom, {
  405. roomId: options.roomId,
  406. type: 0
  407. }, 'POST', 'application/json')
  408. }
  409. let userInfo = await this.getUserInfo()
  410. let socket = io(remote.socketHost, {
  411. path: '/new-zfb',
  412. transport: ['websocket'],
  413. extraHeaders: {
  414. "oid": userInfo.weixin_openid
  415. },
  416. query: {
  417. ...options,
  418. isClient: true,
  419. from: 2
  420. }
  421. });
  422. this.socketInstance = socket
  423. console.error('新建socket Room', options.roomId)
  424. this.setData({
  425. socketStatus: 0,
  426. })
  427. socket.on('connect', () => this.setData({
  428. socketStatus: 1
  429. }))
  430. socket.on('connect_error', () => this.setData({
  431. socketStatus: -1
  432. }))
  433. socket.on('connect_timeout', () => this.setData({
  434. socketStatus: -1
  435. }))
  436. socket.on('disconnect', () => this.setData({
  437. socketStatus: -1
  438. }))
  439. socket.on('reconnect', () => {
  440. // wx.showToast({
  441. // title: '重连',
  442. // })
  443. this.setData({
  444. socketStatus: this.data.socketStatus
  445. })
  446. let noMute = getApp().globalData.voiceProps.noMute
  447. this.socketSendMessage('changeVoiceStatus', {
  448. status: noMute ? 0 : 2
  449. })
  450. this.socketSendMessage('changeOnlineStatus', {
  451. status: 1
  452. })
  453. })
  454. socket.on('reconnect_failed', () => this.setData({
  455. socketStatus: -1
  456. }))
  457. socket.on('error', () => this.setData({
  458. socketStatus: -1
  459. }))
  460. socket.on('roomIn', config => {
  461. let enableTalk = config.roomsConfig.enableTalk !== false
  462. let noMute = getApp().globalData.voiceProps.noMute
  463. getApp().globalData.voiceProps.force = enableTalk
  464. if (!enableTalk && !noMute) {
  465. if (this.role !== 'leader') {
  466. // this.mic()
  467. }
  468. }
  469. })
  470. this.socketSendMessage = (event, obj) => {
  471. console.error('发送 socket Room', options.roomId, event, obj)
  472. socket.emit(event, obj)
  473. }
  474. socket.on('clientSyncAction', (data) => {
  475. console.log('调用', data.type, '方法', data)
  476. if (this[data.type]) {
  477. this[data.type](data)
  478. } else if (data.type == 'wx-subscribe') {
  479. this.getUrlCode(data.data)
  480. } else {
  481. console.error('没有', data.type, '方法')
  482. }
  483. })
  484. socket.on('action', (data) => {
  485. if (data.type === 'navigateToGoods') {
  486. this.navigateToGoodsAction(data.data)
  487. }
  488. })
  489. socket.on('changeRoomEnableTalk', config => {
  490. if (this.role !== 'leader') {
  491. this.changeRoomEnableTalk(config)
  492. }
  493. })
  494. socket.on('startCall', this.startCall.bind(this))
  495. socket.on('stopCall', (data) => {
  496. console.log('on stopCall')
  497. this.stopCall(data)
  498. })
  499. this.handleSomeOneInRoom = this.handleSomeOneInRoom.bind(this)
  500. // socket.on('someOneInRoom', debounce(this.handleSomeOneInRoom, 100))
  501. socket.on('someOneInRoom', debounce(this.handleSomeOneInRoom, 100))
  502. socket.on('someOneLeaveRoom', (user, data) => {
  503. this.handleSomeOneLeave(user)
  504. })
  505. socket.on('roomClose', (data) => {
  506. console.log('on roomClose')
  507. this.stopCall(data)
  508. })
  509. socket.on('autoReJoin', (data) => {
  510. console.log('on autoReJoin')
  511. if ('roomId' in data) {
  512. options.roomId = Number(data.roomId)
  513. }
  514. })
  515. // 有MIC通知,主要是其他用户禁MIC 移到中间层处理。
  516. // socket.on('beHasMic', (data) => {
  517. // const socketOptions = this.data.socketOptions
  518. // if (data.user) {
  519. // const isOther = (socketOptions.role !== 'leader' && (Number(socketOptions.userId) !== Number(data.user.userId)));
  520. // if (isOther) {
  521. // this.closeMic();
  522. // // wx.showToast({
  523. // // title: '关mic' + isOther
  524. // // })
  525. // }
  526. // }
  527. // })
  528. socket.on("beKicked", data => {
  529. const that = this
  530. if (data.userId && data.roomId) {
  531. const socketOptions = this.data.socketOptions
  532. const userId = data.userId
  533. const roomId = data.roomId
  534. // debugger
  535. if (socketOptions.userId == userId && this.options.roomId == roomId) {
  536. this.exitRoom();
  537. wx.showToast({
  538. title: '您已被踢出房间!',
  539. icon: 'none',
  540. complete: () => {
  541. setTimeout(() => {
  542. that.socketStop();
  543. wx.switchTab({
  544. url: '/pages/index/index',
  545. })
  546. }, 1000)
  547. }
  548. })
  549. }
  550. }
  551. });
  552. socket.on("roomMaximum", () => {
  553. this.setData({
  554. roomMaximum: true
  555. })
  556. });
  557. //全员退出
  558. socket.on('roomDisMiss', () => {
  559. // wx.showToast({
  560. // title: '全员退出',
  561. // });
  562. this.setData({
  563. roomDisMiss: true
  564. })
  565. try {
  566. this.exitRoomApi();
  567. } catch (error) {
  568. console.log('error', error)
  569. }
  570. // this.exitRoom();
  571. })
  572. //服务器未知错误重进
  573. socket.on('unKnowError', () => {
  574. this.setData({
  575. unKnowError: true
  576. })
  577. })
  578. //被动通知开关MIC 要3秒后
  579. socket.on('serverOnMic', ({
  580. voiceStatus
  581. }) => {
  582. setTimeout(() => {
  583. if (Number(voiceStatus) === 2) {
  584. // wx.showToast({
  585. // title: '开MIC',
  586. // icon:'none'
  587. // })
  588. this.openMic();
  589. }
  590. if (Number(voiceStatus) === 0) {
  591. // wx.showToast({
  592. // title: '关MIC',
  593. // icon:'none'
  594. // })
  595. this.closeMic();
  596. }
  597. }, 3000)
  598. });
  599. this.socketStop = () => {
  600. if (socket) {
  601. socket.close()
  602. console.error('断开 并滞空 socket Room', options.roomId)
  603. this.setData({
  604. socketStatus: 2
  605. })
  606. socket = null
  607. }
  608. }
  609. return options
  610. },
  611. getUrlCode(url) {
  612. this.socketSendMessage('clientSyncAction', {
  613. sender: 'wx',
  614. type: 'wx-subscribe-result',
  615. data: 3020
  616. })
  617. // wx.request({
  618. // url: url, //仅为示例,并非真实的接口地址
  619. // method: 'get',
  620. // success: (res) => {
  621. // let code = -1
  622. // if (typeof res.data.code != 'undefined') {
  623. // code = res.data.code
  624. // }
  625. // this.socketSendMessage('clientSyncAction', {
  626. // sender: 'wx',
  627. // type: 'wx-subscribe-result',
  628. // data: code
  629. // })
  630. // },
  631. // fail: (err) => {
  632. // console.log(err)
  633. // }
  634. // })
  635. },
  636. changeRoomEnableTalk(data) {
  637. console.log(data)
  638. let noMute = getApp().globalData.voiceProps.noMute
  639. getApp().globalData.voiceProps.force = data.enableTalk
  640. // noMute true 静音
  641. // enableTalk false 静音
  642. if (!!data.enableTalk === !!noMute) {
  643. this.mic()
  644. }
  645. },
  646. navigateToGoods({
  647. data
  648. }) {
  649. // wx.showToast({
  650. // title: JSON.stringify(data).substr(40)
  651. // })
  652. this.navigateToGoodsAction(data)
  653. },
  654. navigateToGoodsAction(id) {
  655. wx.navigateTo({
  656. url: '/pages/goods/goods?id=' + id,
  657. })
  658. },
  659. getUrl(url, socketOptions, isJoin) {
  660. url += '&room_id=' + socketOptions.roomId + '&user_id=' + socketOptions.userId + '&origin=fashilong'
  661. if (isJoin) {
  662. url += '&role=' + this.role + '&shopping'
  663. } else {
  664. url += '&role=' + this.role
  665. }
  666. console.error(url)
  667. console.log(isJoin)
  668. return url
  669. },
  670. navigateToMiniProgram(data) {
  671. wx.showModal({
  672. title: '温馨提示',
  673. content: '即将跳到其他小程序,是否继续?',
  674. showCancel: true, //是否显示取消按钮
  675. cancelText: "取消", //默认是“取消”
  676. confirmText: "确定", //默认是“确定”
  677. success: function (res) {
  678. if (res.cancel) {
  679. //点击取消,wx.navigateBack
  680. } else {
  681. wx.navigateToMiniProgram(data.data)
  682. }
  683. },
  684. fail: function (res) {
  685. //接口调用失败的回调函数,wx.navigateBack
  686. },
  687. complete: function (res) {
  688. //接口调用结束的回调函数(调用成功、失败都会执行)
  689. },
  690. })
  691. },
  692. async handleSomeOneInRoom(data) {
  693. if (data && data.user) {
  694. console.log('handleSomeOneInRoom', data)
  695. this.startCall(data)
  696. }
  697. },
  698. async startCall(data) {
  699. //TODO 触发三次
  700. console.log('startCall-data', data)
  701. // if( this.role =='leader'){
  702. this.setData({
  703. shareStatus: 1
  704. })
  705. if (!data) return;
  706. this.setData({
  707. surplus: this.data.peopleCount - data.roomsPerson.length
  708. })
  709. //undefined是未授权,状态为3
  710. let voiceStatus
  711. if (!this.isAuthorizeRecord) {
  712. const unAuth = await this.authorizeRecord();
  713. if (typeof unAuth === 'undefined') {
  714. // debugger
  715. voiceStatus = 3
  716. } else {
  717. voiceStatus = Number(unAuth)
  718. }
  719. }
  720. //限制只有主持人才可以开麦
  721. // if (this.role == 'leader') {
  722. // if (!this.isAuthorizeRecord) {
  723. // const voiceStatus = Number(await this.authorizeRecord())
  724. // this.isAuthorizeRecord = true
  725. // // getApp().setVoiceProps({
  726. // // noMute: !voiceStatus
  727. // // })
  728. // // console.log(getApp().globalData.voiceProps.noMute)
  729. // // this.socketSendMessage('changeVoiceStatus', {
  730. // // status: getApp().globalData.voiceProps.noMute ? 0 : 2
  731. // // })
  732. // // this.data.socketOptions.voiceStatus = 1
  733. // // this.socketSendMessage('changeVoiceStatus', {status: noMute ? 0 : 2})
  734. // }
  735. // }
  736. const socketOptions = this.data.socketOptions
  737. getApp().globalData.roomId = socketOptions.roomId
  738. const user = data.roomsPerson.find(user => user.userId == socketOptions.userId)
  739. if (!user) {
  740. return
  741. }
  742. //屏蔽有人进来才开麦克风
  743. // if (data.roomsPerson.length <= 1) {
  744. // return
  745. // }
  746. user.noMute = getApp().globalData.voiceProps.noMute
  747. getApp().setVoiceProps({
  748. ...user,
  749. action: 'startCall'
  750. })
  751. // this.socketSendMessage('changeVoiceStatus', {
  752. // status: getApp().globalData.voiceProps.noMute ? 0 : 2
  753. // })
  754. // }
  755. },
  756. stopCall() {
  757. console.error('stopCall')
  758. this.setData({
  759. shareStatus: 0
  760. })
  761. getApp().setVoiceProps({
  762. noMute: false,
  763. action: 'stopCall'
  764. })
  765. if (this.runManager) {
  766. // this.recorderManager.stop()
  767. this.runManager = false
  768. }
  769. },
  770. handleSomeOneLeave(data) {
  771. if (data.roomsPerson.length <= 1) {
  772. // this.stopCall()
  773. }
  774. this.setData({
  775. surplus: this.data.peopleCount - data.roomsPerson.length
  776. })
  777. },
  778. //deprecated
  779. async newRoomBk(data) {
  780. if (data.roomId) return;
  781. this.stopCall()
  782. getApp().globalData.rtcParams = []
  783. getApp().globalData.pusher = ''
  784. if (this.data.join && !this.options.join) {
  785. wx.switchTab({
  786. url: '/pages/index/index',
  787. })
  788. return;
  789. }
  790. this.role = this.data.canShow ? 'leader' : 'customer'
  791. let options = await this.getSocketOptions(this.mcode)
  792. this.socketSendMessage('clientSyncAction', {
  793. type: 'newRoom',
  794. data: options
  795. })
  796. setTimeout(async () => {
  797. this.wssSuccess = false
  798. this.socketStop && this.socketStop()
  799. this.data.many = !!this.data.canShow
  800. // this.setData({
  801. // // peopleCount: this.data.many ? manyCount : 5
  802. // peopleCount: manyCount
  803. // })
  804. let base = this.base
  805. let socketOptions = await this.socketStart({
  806. options
  807. })
  808. let url = this.getUrl(base, socketOptions, false) + (this.urlPj || '')
  809. this.base = base
  810. this.setData({
  811. url,
  812. socketOptions,
  813. })
  814. this.joinUrl()
  815. this.setData({
  816. socketOptions
  817. })
  818. this.loadConponSuccess = true
  819. this.readySendCouponCtrl()
  820. }, 300)
  821. },
  822. // 真正退出房间
  823. async exitRoom() {
  824. const roomId = this.data.socketOptions.roomId;
  825. const role = this.role;
  826. const result = await util.request(api.exitRoom, {
  827. businessId: roomId
  828. }, 'POST', 'application/json');
  829. this.socketSendMessage('stopCall', {
  830. from: 2
  831. })
  832. this.stopCall();
  833. this.socketStop();
  834. if (role === 'leader') {
  835. wx.redirectTo({
  836. url: '/pages/roomManger/roomManger',
  837. });
  838. } else {
  839. wx.switchTab({
  840. url: '/pages/index/index'
  841. });
  842. }
  843. },
  844. // 一些情况下单调API退出
  845. exitRoomApi() {
  846. const roomId = this.data.socketOptions.roomId;
  847. const role = this.role;
  848. util.request(api.exitRoom, {
  849. businessId: roomId
  850. }, 'POST', 'application/json');
  851. },
  852. async exit() {
  853. // this.stopCall()
  854. getApp().globalData.rtcParams = []
  855. getApp().globalData.pusher = ''
  856. this.socketStop && this.socketStop()
  857. this.role = 'leader'
  858. let base = this.base
  859. let socketOptions = await this.socketStart({
  860. sceneId: this.mcode
  861. })
  862. let url = this.getUrl(base, socketOptions, false) + (this.urlPj || '')
  863. this.base = base
  864. wx.nextTick(() => {
  865. setTimeout(() => {
  866. this.setData({
  867. url,
  868. loadUrl: true,
  869. socketOptions,
  870. showCommodityCtrl: false,
  871. hideWebView: false,
  872. reload: true
  873. })
  874. this.joinUrl()
  875. }, 500)
  876. })
  877. },
  878. clearDebuger() {
  879. this.setData({
  880. debugerInfo: ''
  881. })
  882. },
  883. async mic({
  884. data
  885. }) {
  886. if (Number(data.user.isAllowMic) === 1) {
  887. let noMute = getApp().globalData.voiceProps.noMute
  888. // debugger
  889. // noMute true 静音
  890. // enableTalk false 静音
  891. // if (!!getApp().globalData.voiceProps.force === !!noMute)
  892. // return
  893. // if (!getApp().globalData.voiceProps.force && (!this.data.socketOptions.voiceStatus || noMute)) return;
  894. if (!this.data.socketOptions.voiceStatus) {
  895. let voiceStatus = await this.authorizeRecord()
  896. if (voiceStatus) {
  897. this.data.socketOptions.voiceStatus = 1
  898. noMute = false
  899. } else {
  900. noMute = true
  901. }
  902. } else {
  903. noMute = !noMute
  904. }
  905. getApp().globalData.voiceProps.noMute = noMute
  906. this.socketSendMessage('changeVoiceStatus', {
  907. status: noMute ? 0 : 2,
  908. user: data.user
  909. })
  910. getApp().setVoiceProps({
  911. noMute
  912. })
  913. wx.showToast({
  914. title: `已${noMute ? '关闭' : '开启'}麦克风`,
  915. })
  916. }
  917. },
  918. closeMic() {
  919. getApp().globalData.voiceProps.noMute = true
  920. this.socketSendMessage('changeVoiceStatus', {
  921. status: 0,
  922. })
  923. getApp().setVoiceProps({
  924. noMute: true
  925. })
  926. },
  927. openMic() {
  928. getApp().globalData.voiceProps.noMute = false
  929. this.socketSendMessage('changeVoiceStatus', {
  930. status: 2,
  931. })
  932. getApp().setVoiceProps({
  933. noMute: false
  934. })
  935. },
  936. callPhone() {
  937. wx.makePhoneCall({
  938. phoneNumber: this.data.contractPhone,
  939. })
  940. this.setData({
  941. showContact: false
  942. })
  943. },
  944. /**
  945. * 用户点击右上角分享
  946. */
  947. onShareAppMessage: function (res) {
  948. let {
  949. id,
  950. newPicUrl
  951. } = this.data
  952. if (res.from === 'button') {
  953. this.setData({
  954. sendShare: false
  955. })
  956. return {
  957. title: '【好友推荐】一起来云逛吧',
  958. imageUrl: newPicUrl,
  959. path: `/pages/webview/index?id=${id}&type=${this.data.type}&join=true&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}`,
  960. }
  961. } else {
  962. return {
  963. imageUrl: newPicUrl,
  964. path: `/pages/webview/index?id=${id}&type=${this.data.type}&join=false`,
  965. }
  966. }
  967. },
  968. /**
  969. * 生命周期函数--监听页面卸载
  970. */
  971. onUnload: function () {
  972. console.log('on onUnload')
  973. // this.socketSendMessage('stopCall', {})
  974. // this.stopCall()
  975. this.socketStop && this.socketStop()
  976. getApp().globalData.pusher = ''
  977. },
  978. cart(data) {
  979. this.setData({
  980. showCommodityCtrl: data.data
  981. })
  982. },
  983. share() {
  984. console.log('share-debug')
  985. const companyName = `指房宝(杭州)科技有限公司`
  986. const vrLink = `/pages/webview/index`
  987. const img_url = this.data.newPicUrl || 'http://video.cgaii.com/new4dage/images/images/home_2_a.jpg'
  988. const shareImg = img_url
  989. this.count = this.count || 0
  990. console.log('share-debug many:%s shareStatus: %s', !!this.data.many, this.data.shareStatus);
  991. if (this.data.many && this.data.shareStatus == 1) {
  992. //开启一起逛时候的分享
  993. console.log(`share-debug: /pages/shareRoom/shareRoom?img_url=${btoa(img_url)}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}`)
  994. console.log('share-debug', this.data.socketOptions)
  995. wx.navigateTo({
  996. url: `/pages/shareRoom/shareRoom?img_url=${btoa(img_url)}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}`,
  997. })
  998. } else {
  999. console.log(`share-debug: /pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}`);
  1000. wx.navigateTo({
  1001. url: `/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}`,
  1002. })
  1003. }
  1004. },
  1005. back(data) {
  1006. if (data.sender !== 'h5') return;
  1007. wx.switchTab({
  1008. url: '/pages/index/index'
  1009. })
  1010. this.setData({
  1011. showCommodityCtrl: false
  1012. })
  1013. },
  1014. service() {
  1015. this.setData({
  1016. showContact: true,
  1017. showCommodity: false,
  1018. showCoupon: false
  1019. })
  1020. },
  1021. invite(data) {
  1022. if (data.sender !== 'h5') return;
  1023. // 分享房间进入统计
  1024. if (this.data.socketOptions.roomId !== '888888') {
  1025. util.request(api.trackRoom, {
  1026. roomId: this.data.socketOptions.roomId,
  1027. type: 1,
  1028. }, 'POST', 'application/json')
  1029. }
  1030. this.setData({
  1031. sendShare: true,
  1032. count: ++this.data.count
  1033. })
  1034. },
  1035. coupon(data) {
  1036. if (data.sender !== 'h5') return;
  1037. this.setData({
  1038. showContact: false,
  1039. showCommodity: false,
  1040. showCoupon: true
  1041. })
  1042. },
  1043. liveGotoGood(ev) {
  1044. let id = ev.currentTarget.dataset.item.goodsId
  1045. wx.navigateTo({
  1046. url: '/pages/goods/goods?id=' + id,
  1047. })
  1048. },
  1049. gotoGoodsDOM(event) {
  1050. this.gotoGoods(event.currentTarget.dataset.item.hotIdList[0])
  1051. },
  1052. gotoGoodsSocket(data) {
  1053. this.gotoGoods(data.data)
  1054. },
  1055. gotoGoods(id) {
  1056. console.log('---', id)
  1057. this.socketSendMessage('clientSyncAction', {
  1058. type: 'openTag',
  1059. data: id
  1060. })
  1061. this.setData({
  1062. showCommodity: false
  1063. })
  1064. this.joinUrl()
  1065. },
  1066. addCard(event) {
  1067. wx.navigateTo({
  1068. url: '/pages/goods/goods?id=' + event.currentTarget.dataset.id + '&oper=addCard',
  1069. })
  1070. },
  1071. buyGoods(event) {
  1072. wx.navigateTo({
  1073. url: '/pages/goods/goods?id=' + event.currentTarget.dataset.id + '&oper=buyGoods',
  1074. })
  1075. },
  1076. showCommodityFn() {
  1077. this.setData({
  1078. showCommodity: true,
  1079. showContact: false,
  1080. showCoupon: false
  1081. })
  1082. this.joinUrl()
  1083. },
  1084. hideComodity() {
  1085. this.setData({
  1086. showCommodity: false
  1087. })
  1088. this.joinUrl()
  1089. },
  1090. hideCoupon() {
  1091. this.setData({
  1092. showCoupon: !this.data.showCoupon
  1093. })
  1094. },
  1095. async receive(ev) {
  1096. let item = ev.target.dataset.item
  1097. try {
  1098. // wx.showToast({
  1099. // title: '领取优惠卷',
  1100. // })
  1101. // return;
  1102. if (item.hasReceived || item.number <= item.receiveNumber) return;
  1103. let res = await util.request(api.CouponExchange, {
  1104. couponId: item.id
  1105. })
  1106. if (res.code === 0) {
  1107. wx.showToast({
  1108. title: '已成功领取',
  1109. success: () => {
  1110. this.setData({
  1111. showCoupon: false
  1112. })
  1113. wx.nextTick(() => {
  1114. this.setData({
  1115. coupons: this.data.coupons.map(citem => {
  1116. return {
  1117. ...citem,
  1118. hasReceived: citem.id === item.id ? true : citem.hasReceived
  1119. }
  1120. }),
  1121. showCoupon: true
  1122. })
  1123. })
  1124. }
  1125. })
  1126. } else if (res.errno === 401) {
  1127. getApp().setLoginProps(false)
  1128. } else {
  1129. wx.showToast({
  1130. title: res.msg,
  1131. })
  1132. }
  1133. } catch (e) {
  1134. console.error(e)
  1135. wx.showToast({
  1136. icon: 'none',
  1137. title: '领取失败',
  1138. })
  1139. }
  1140. },
  1141. async getCouponList(id) {
  1142. const success = (res) => {
  1143. this.setData({
  1144. coupons: res.data.list.map(item => {
  1145. item.typeMoney = item.typeMoney.toString()
  1146. item.fontSize = item.typeMoney.length === 3 ? '90rpx' :
  1147. item.typeMoney.length === 4 ? '70rpx' : '130rpx'
  1148. return item
  1149. })
  1150. })
  1151. this.loadConponSuccess = true
  1152. this.readySendCouponCtrl()
  1153. }
  1154. let res = await util.request(api.BrandCouponList, {
  1155. brandId: id,
  1156. pageNum: 1,
  1157. pageSize: 10000
  1158. }, 'GET')
  1159. console.log(res)
  1160. if (res.code === 0) {
  1161. success(res)
  1162. } else {
  1163. let res = await util.request(api.UNBrandCouponList, {
  1164. brandId: id,
  1165. pageNum: 1,
  1166. pageSize: 10000
  1167. }, 'GET')
  1168. success(res)
  1169. }
  1170. },
  1171. ready() {
  1172. this.wssSuccess = true
  1173. this.readySendCouponCtrl()
  1174. },
  1175. readySendCouponCtrl() {
  1176. if (this.wssSuccess && this.loadConponSuccess) {
  1177. this.loadConponSuccess = false
  1178. this.socketSendMessage('clientSyncAction', {
  1179. type: 'showCoupon',
  1180. data: this.data.coupons.length > 0
  1181. })
  1182. }
  1183. },
  1184. getBrand: function (id, code) {
  1185. this.getGoodsCount(code, id)
  1186. return;
  1187. },
  1188. getGoodsCount(code, id) {
  1189. util.request(api.GoodsNumCount, {
  1190. isDelete: 0,
  1191. isOnSale: 1,
  1192. brandId: id
  1193. }, 'GET')
  1194. .then(res => {
  1195. if (res.errno === 0) {
  1196. this.setData({
  1197. goodsCount: res.data
  1198. })
  1199. }
  1200. this.getCouponList(id)
  1201. })
  1202. },
  1203. getGoodsList(id, category_id) {
  1204. var that = this;
  1205. if (!(this.data.navList && this.data.navList.length)) {
  1206. that.navDatas = {}
  1207. let navDatas = this.data.navList = this.data.comtypes
  1208. // util.request(api.GoodsCategory, { id: category_id })
  1209. // .then(function (res) {
  1210. // if (res.errno == 0) {
  1211. // let navDatas = res.data.brotherCategory
  1212. // that.setData({
  1213. // navList: navDatas,
  1214. // currTypeId: category_id
  1215. // });
  1216. that.navDatas = {}
  1217. navDatas.forEach(item => {
  1218. util.request(api.GoodsList, {
  1219. brandId: id,
  1220. categoryId: item.category_id,
  1221. page: that.data.page,
  1222. size: that.data.size
  1223. })
  1224. .then(res => {
  1225. if (res.errno === 0) {
  1226. that.navDatas[item.category_id] = res.data.goodsList
  1227. }
  1228. })
  1229. })
  1230. // }
  1231. // })
  1232. }
  1233. if (that.navDatas[category_id]) {
  1234. if (!isIos) {
  1235. let showCommodity = that.data.showCommodity
  1236. that.setData({
  1237. showCommodity: false
  1238. })
  1239. setTimeout(() => {
  1240. wx.nextTick(() => {
  1241. that.setData({
  1242. goodsList: that.navDatas[category_id],
  1243. currTypeId: category_id,
  1244. showCommodity: showCommodity
  1245. });
  1246. })
  1247. }, 500)
  1248. } else {
  1249. that.setData({
  1250. goodsList: that.navDatas[category_id],
  1251. currTypeId: category_id,
  1252. });
  1253. }
  1254. } else {
  1255. console.error('诱惑去啦')
  1256. util.request(api.GoodsList, {
  1257. brandId: id,
  1258. categoryId: category_id,
  1259. page: that.data.page,
  1260. size: that.data.size
  1261. })
  1262. .then(function (res) {
  1263. if (res.errno === 0) {
  1264. that.setData({
  1265. goodsList: res.data.goodsList,
  1266. currTypeId: category_id
  1267. });
  1268. // this.data.navList
  1269. }
  1270. });
  1271. }
  1272. },
  1273. getBrandDetail: function (id, type, cb) {
  1274. console.log('getBrandDetail-params', id, type)
  1275. util.request(api.BrandDetail, {
  1276. id: id,
  1277. type: type,
  1278. }).then((res) => {
  1279. console.log('getBrandDetail', res)
  1280. let base = res.data.brand.sceneUrl
  1281. // let base = 'http://192.168.0.112:8080/shop.html?m=t-7Uqj9Fq&origin=fashilong'
  1282. if (res.errno === 0) {
  1283. let url = base + "&sid=" + id
  1284. // debugger
  1285. this.setData({
  1286. id: id,
  1287. newPicUrl: res.data.brand.appListPicUrl,
  1288. sceneNum: res.data.brand.sceneNum,
  1289. canShow: res.data.brand.canShow,
  1290. contractPhone: res.data.brand.contractPhone,
  1291. contactInfo: {
  1292. contactPhone: res.data.brand.contactPhone || '',
  1293. contactHead: res.data.brand.contactHead || '',
  1294. contactCompanyName: res.data.brand.contactCompanyName || '',
  1295. contactNickName: res.data.brand.contactNickName || '',
  1296. brands: res.data.brand.brands || []
  1297. }
  1298. })
  1299. if (this.data.many === void 0) {
  1300. this.data.many = !!res.data.brand.canShow
  1301. }
  1302. this.setData({
  1303. // peopleCount: this.data.many ? manyCount : 5,
  1304. peopleCount: manyCount
  1305. })
  1306. if (!res.data.brand.canShow) {
  1307. this.role = 'customer'
  1308. } else if (!this.options.join) {
  1309. this.role = 'leader'
  1310. }
  1311. cb(url, urlToJson(url).m, )
  1312. }
  1313. });
  1314. },
  1315. sendContactInfo() {
  1316. // this.socketSendMessage('getContactInfo', {
  1317. // contactInfo: this.data.contactInfo,
  1318. // })
  1319. this.socketSendMessage('clientSyncAction', {
  1320. type: 'getContactInfo',
  1321. contactInfo: this.data.contactInfo
  1322. })
  1323. },
  1324. goToCase({
  1325. data
  1326. }) {
  1327. console.log('data', data)
  1328. wx.showModal({
  1329. title: '提示',
  1330. content: `是否跳转到新的场景?`,
  1331. showCancel: true,
  1332. confirmColor: "#52a2d8",
  1333. success: res => {
  1334. if (res.confirm) {
  1335. wx.navigateTo({
  1336. url: `/pages/webview/index?id=${data.id}&type=32`,
  1337. })
  1338. }
  1339. },
  1340. fail: () => {
  1341. }
  1342. })
  1343. },
  1344. selectType(ev) {
  1345. this.getGoodsList(this.options.id, ev.target.dataset.item.category_id)
  1346. },
  1347. hideCS() {
  1348. this.setData({
  1349. showCommodity: false,
  1350. showCoupon: false,
  1351. showContact: false
  1352. })
  1353. },
  1354. hideContact() {
  1355. this.setData({
  1356. showContact: false
  1357. })
  1358. },
  1359. calcShare() {
  1360. // this.exit()
  1361. this.setData({
  1362. sendShare: false
  1363. })
  1364. },
  1365. contactKf() {
  1366. let keys = Object.keys(this.navDatas)
  1367. let goodsId = this.navDatas[keys[0]][0].id
  1368. let user = wx.getStorageSync('userinfoDetail')
  1369. util.request(api.AddTalkCount, {
  1370. goodsId,
  1371. viewId: user && user.userId || '',
  1372. sceneNum: this.data.sceneNum
  1373. }, 'get')
  1374. this.hideAlert && this.hideAlert()
  1375. this.hideContact && this.hideContact()
  1376. },
  1377. onHide() {
  1378. this.socketSendMessage('changeOnlineStatus', {
  1379. status: 0
  1380. })
  1381. this.pauseVideo = true
  1382. this.joinUrl()
  1383. }
  1384. }