|
@@ -1,9 +1,9 @@
|
|
|
var websocket = null;
|
|
|
var ipAddress = "";
|
|
|
-//测试环境
|
|
|
-//var serverAddress="ws://172.16.32.161:81/thmz/evaluationWebSocket/";
|
|
|
-//生产环境
|
|
|
-var serverAddress="ws://webhis.thyy.cn:81/thmz/evaluationWebSocket/";
|
|
|
+// //测试环境
|
|
|
+// //var serverAddress="ws://172.16.32.161:81/thmz/evaluationWebSocket/";
|
|
|
+// //生产环境
|
|
|
+// var serverAddress="ws://webhis.thyy.cn:81/thmz/evaluationWebSocket/";
|
|
|
/**
|
|
|
* 创建webSocket
|
|
|
* @param type
|
|
@@ -13,66 +13,80 @@ function openEvaluationWebSocket(type) {
|
|
|
getUserIP(function(ip) {
|
|
|
ipAddress = ip
|
|
|
if('WebSocket' in window){
|
|
|
- websocket = new WebSocket(serverAddress+ipAddress+"/"+type);
|
|
|
- }else{
|
|
|
- alert('当前浏览器不支持WebSocket,请更换浏览器');
|
|
|
- }
|
|
|
- websocket.onerror = function(){
|
|
|
- console.log("连接出错");
|
|
|
- }
|
|
|
- websocket.onopen = function(){
|
|
|
- console.log("连接成功");
|
|
|
- }
|
|
|
- websocket.onmessage = function(event){
|
|
|
- var data = JSON.parse(event.data);
|
|
|
- if(data.type=="url"){
|
|
|
- window.open(data.url, '_self');
|
|
|
- return;
|
|
|
- }
|
|
|
- //推送价格
|
|
|
- if(data.type=="priceData"){
|
|
|
|
|
|
- }
|
|
|
- if(data.type=="content"){
|
|
|
- if(data.id=="client_evaluate"){
|
|
|
- $("#client_evaluate").show();
|
|
|
- $("#client_index").hide();
|
|
|
- $("#client_price").hide();
|
|
|
- var mp3 = $("#mp3");
|
|
|
- mp3.attr("src",data.messageAudio);
|
|
|
- mp3.get(0).play();
|
|
|
- return;
|
|
|
- }else if(data.id=="client_price"){
|
|
|
- $("#client_price").show();
|
|
|
- $("#client_evaluate").hide();
|
|
|
- $("#client_index").hide();
|
|
|
- $("#pName").text(data.name);
|
|
|
- $("#pGender").text(data.call);
|
|
|
- $("#needPay").text(data.needPay);
|
|
|
- $("#pay").text(data.pay);
|
|
|
- $("#changeAmount").text(data.changeAmount);
|
|
|
- //播放语音
|
|
|
- var mp3 = $("#mp3");
|
|
|
- mp3.attr("src",data.messageAudio);
|
|
|
- mp3.get(0).play();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- console.log("收到消息" + event.data);
|
|
|
- }
|
|
|
- websocket.onclose = function(){
|
|
|
- console.log("退出连接");
|
|
|
- }
|
|
|
- window.onbeforeunload = function(){
|
|
|
- clos();
|
|
|
- }
|
|
|
+ $.ajax({
|
|
|
+ type: "GET",
|
|
|
+ url: '/thmz/getWebSocketHost',
|
|
|
+ contentType: "application/json;charset=UTF-8",
|
|
|
+ dataType: "json",
|
|
|
+ headers: {'Accept': 'application/json'},
|
|
|
+ success: function (res) {
|
|
|
+ if (res.code == 0) {
|
|
|
+ var serverAddress=res.data;
|
|
|
+ serverAddress=serverAddress+"evaluationWebSocket/"+ipAddress+"/"+type;
|
|
|
+ websocket = new WebSocket(serverAddress);
|
|
|
+ websocket.onerror = function(){
|
|
|
+ console.log("连接出错");
|
|
|
+ }
|
|
|
+ websocket.onopen = function(){
|
|
|
+ console.log("连接成功");
|
|
|
+ }
|
|
|
+ websocket.onmessage = function(event){
|
|
|
+ var data = JSON.parse(event.data);
|
|
|
+ if(data.type=="url"){
|
|
|
+ window.open(data.url, '_self');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //推送价格
|
|
|
+ if(data.type=="priceData"){
|
|
|
|
|
|
- function clos(){
|
|
|
- websocket.close(3000,"强制关闭");
|
|
|
- }
|
|
|
- function send(){
|
|
|
- var msg = document.getElementById('text').value;
|
|
|
- websocket.send(msg);
|
|
|
+ }
|
|
|
+ if(data.type=="content"){
|
|
|
+ if(data.id=="client_evaluate"){
|
|
|
+ $("#client_evaluate").show();
|
|
|
+ $("#client_index").hide();
|
|
|
+ $("#client_price").hide();
|
|
|
+ var mp3 = $("#mp3");
|
|
|
+ mp3.attr("src",data.messageAudio);
|
|
|
+ mp3.get(0).play();
|
|
|
+ return;
|
|
|
+ }else if(data.id=="client_price"){
|
|
|
+ $("#client_price").show();
|
|
|
+ $("#client_evaluate").hide();
|
|
|
+ $("#client_index").hide();
|
|
|
+ $("#pName").text(data.name);
|
|
|
+ $("#pGender").text(data.call);
|
|
|
+ $("#needPay").text(data.needPay);
|
|
|
+ $("#pay").text(data.pay);
|
|
|
+ $("#changeAmount").text(data.changeAmount);
|
|
|
+ //播放语音
|
|
|
+ var mp3 = $("#mp3");
|
|
|
+ mp3.attr("src",data.messageAudio);
|
|
|
+ mp3.get(0).play();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log("收到消息" + event.data);
|
|
|
+ }
|
|
|
+ websocket.onclose = function(){
|
|
|
+ console.log("退出连接");
|
|
|
+ }
|
|
|
+ window.onbeforeunload = function(){
|
|
|
+ clos();
|
|
|
+ }
|
|
|
+
|
|
|
+ function clos(){
|
|
|
+ websocket.close(3000,"强制关闭");
|
|
|
+ }
|
|
|
+ function send(){
|
|
|
+ var msg = document.getElementById('text').value;
|
|
|
+ websocket.send(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ alert('当前浏览器不支持WebSocket,请更换浏览器');
|
|
|
}
|
|
|
})
|
|
|
}
|