gateway客æ·ç«¯è天
程序员文章站
2024-03-22 15:04:52
...
å 为项ç®éè¦ï¼è·çæç¨åäºä¸ªåºäºgatewayçä¸å¯¹ä¸è天demoï¼å·²ç»å®ç°äºå¾çãææ¬è天åè½ï¼åtinkphp5.0æ¡æ¶ç»åçã
客æ·ç«¯ä»£ç ï¼
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>è天çé¢</title>
<link rel="stylesheet" type="text/css" href="chat.css" />
<script src="js/jquery.min.js"></script>
<script src="js/flexible.js"></script>
</head>
<body>
<header class="header">
<a class="back" href="javascript:history.go(-1)"></a>
<h5 class="tit"></h5>
<div class="right"></div>
</header>
<div class="message" id="message">
<!-- <div class="send">
<div class="time">05/22 06:30</div>
<div class="msg">
<img src="images/touxiang.png" alt="" />
<p><i class="msg_input"></i>ä½ å¥½å¨ä¸å¨åï¼å¦¹åï¼</p>
</div>
</div>
<div class="show">
<div class="time">05/22 06:30</div>
<div class="msg">
<img src="images/touxiangm.png" alt="" />
<p><i clas="msg_input"></i>ä½ å¥½ä½ å¥½ä½ å¥½</p>
</div>
</div> -->
</div>
<div class="footer">
<img src="images/jia.jpg" id="img-up" alt="" />
<input type="file" name="file" id="file" style="display:none">
<img src="images/xiaolian.png" alt="" />
<input type="text" />
<p>åé</p>
</div>
<script src="js/chat.js" type="text/javascript" charset="utf-8"></script>
<script>
var token = getUrlParam(window.location.href,'token');
var demand_id = getUrlParam(window.location.href,'demand_id');
var accept_id = getUrlParam(window.location.href,'accept_id');
var client_id = null;
var user = null;
var ip = null;
var host = "http://xxxxxxx.com";
//é讯交äº
var ws = new WebSocket('ws://0.0.0.0:8282');
ws.onmessage = function(e){
var info = eval('('+e.data+')');
console.log(info)
switch(info.type){
case 'init':
client_id = info.data;
ip = info.ip;
break;
case 'text':
//æ£æµ éå½å两人é讯ä¸è¿æ¥
if(info.fromid == user.to_id){
send(user.to_avatar,info.data);
updateRead();
}
break;
case 'img':
//æ£æµ éå½å两人é讯ä¸è¿æ¥
if(info.fromid == user.to_id){
sendImg(user.to_avatar,host+info.data);
updateRead();
}
break;
}
}
//åå§å请æ±æ°æ®
$.get(host+url,{token:token,demand_id:demand_id,accept_id:accept_id},function(data){
user = data.data;
$('.tit').text(user.to_name)
if(data.code == 1){
//ç»å®UID
ws.send('{"type":"bind","client_id":"'+client_id+'","uid":"'+user.from_id+'"}');
//è·åè天记å½
getLoad();
}else{
alert(data.msg)
}
})
//è·åè天记å½
function getLoad()
{
$.post(host+url,{token:token,demand_id:demand_id,accept_id:accept_id},function(data){
if(data.code == 0){
return false;
}
var list = data.data.list;
for(var i=0;i<list.length;i++){
if(list[i].fromid==user.from_id){
if(list[i].type==1){
//ææ¬
show(user.from_avatar,list[i].content);
}else if(list[i].type==2){
//å¾ç
showImg(user.from_avatar,host+list[i].content);
}
}else{
if(list[i].type==1){
//ææ¬
send(user.to_avatar,list[i].content);
}else if(list[i].type==2){
//å¾ç
sendImg(user.to_avatar,host+list[i].content);
}
}
}
})
}
//åéæ°æ®
$('.footer p').click(function(){
var msg = $(this).prev().val();
if(msg == ''){
return false;
}
show(user.from_avatar,msg);
var str = '{"type":"say","data":"'+msg+'","fromid":"'+user.from_id+'","toid":"'+user.to_id+'"}';
//ä¿åè®°å½
saveRecord(msg,1);
ws.send(str);
$(this).prev().val('');
$(this).css('background','#ddd').prop('disabled',false);
})
//æ¶æ¯è®°å½æä¹
å
function saveRecord(str,type)
{
var arr = {};
arr.token = token;
arr.demand_id = demand_id;
arr.accept_id = accept_id;
arr.content = str;
arr.toid = user.to_id;
arr.fromid = user.from_id;
arr.type = type;
$.post(host+url,arr,function(data){
if(data.code==0){
console.log(data.msg)
}
})
}
//触åéæ©å¾ç
$('#img-up').click(function(){
$('#file').click();
})
$('#file').change(function(){
var formData = new FormData();
formData.append('token',token);
formData.append('file',$('#file')[0].files[0]);
//ä¸ä¼ å¾ç
$.ajax({
url:host+url,
type:'post',
cache:false,
data:formData,
dataType:'json',
processData:false,
contentType:false,
success:function(data){
if(data.code==1){
url = host+data.data.url;
showImg(user.from_avatar,url);
var str = '{"type":"img","data":"'+data.data.url+'","fromid":"'+user.from_id+'","toid":"'+user.to_id+'"}';
//ä¿åè®°å½
saveRecord(data.data.url,2);
ws.send(str);
}else{
alert(data.msg)
}
}
})
})
/**
* æ¶æ¯è®°å½æ°æ®æ´æ°
*/
function updateRead()
{
$.get(host+url,{token:token,demand_id:demand_id,accept_id:accept_id},function(data){
console.log(data)
})
}
</script>
</body>
</html>
æ½ç©ºåå ä¸å¿è·³çæµï¼æ¥ä¸æ¥è¦æ群ç»è天åè½ã
推荐阅读
-
记一次 nginx 504 Gateway Time-out,nginxtime-out
-
php线程打开文件句柄受限导致的异常502 Bad Gateway
-
nginx+php-fpm出现502 bad gateway异常解决办法
-
Spring Cloud Gateway转发Spring WebSocket
-
SAP云平台部署应用时遇到的502 Updating service failed - Bad Gateway SAP成都研究院SAP Cloud PlatformSAP云平台SAPABAP
-
gateway客æ·ç«¯è天
-
502 Bad Gateway,PHP Interpreter is not configured(此类问题处理) 博客分类: php
-
spring cloud gateway部署到k8s上UrlEncode问题
-
Java Spring cloud gateway nacos 配置
-
nacos+spring cloud gateway 出现503 Service Unavailable