сделал все, что хотел
This commit is contained in:
parent
0143526428
commit
8286b61597
8 changed files with 38 additions and 58 deletions
|
@ -14,6 +14,7 @@ export async function UserCheck(){
|
||||||
|
|
||||||
else{
|
else{
|
||||||
console.log(response)
|
console.log(response)
|
||||||
|
location.assign('/login')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
export default function createWebSocket(url, token, onMessageCallback, maxRetries = 10) {
|
export default function createWebSocket(url, token, onMessageCallback) {
|
||||||
let socket;
|
let socket;
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
|
const maxRetries = 5
|
||||||
let messageQueue = [];
|
let messageQueue = [];
|
||||||
token = token.split(" ")[1];
|
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
closeWebSocket();
|
|
||||||
|
|
||||||
socket = new WebSocket(url, [token]);
|
socket = new WebSocket(url, [token]);
|
||||||
|
|
||||||
|
@ -16,6 +15,7 @@ export default function createWebSocket(url, token, onMessageCallback, maxRetrie
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
console.log('WebSocket is open now.')
|
console.log('WebSocket is open now.')
|
||||||
|
console.log(socket)
|
||||||
retries = 0 //сброс попыток
|
retries = 0 //сброс попыток
|
||||||
|
|
||||||
while (messageQueue.length > 0) {
|
while (messageQueue.length > 0) {
|
||||||
|
@ -25,16 +25,6 @@ export default function createWebSocket(url, token, onMessageCallback, maxRetrie
|
||||||
|
|
||||||
socket.onclose = (event) => {
|
socket.onclose = (event) => {
|
||||||
console.log('WebSocket is closed now.', event)
|
console.log('WebSocket is closed now.', event)
|
||||||
if (retries < maxRetries) {
|
|
||||||
retries++
|
|
||||||
const timeout = Math.min(1000 * Math.pow(2, retries), 30000)
|
|
||||||
setTimeout(() => {
|
|
||||||
console.log(`Reconnecting... attempt ${retries}`)
|
|
||||||
connect()
|
|
||||||
}, timeout)
|
|
||||||
} else {
|
|
||||||
console.log('Max retries reached. Could not reconnect.')
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onerror = (error) => {
|
socket.onerror = (error) => {
|
||||||
|
@ -44,13 +34,6 @@ export default function createWebSocket(url, token, onMessageCallback, maxRetrie
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeWebSocket() {
|
|
||||||
if (socket) {
|
|
||||||
socket.close();
|
|
||||||
socket = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connect()
|
connect()
|
||||||
|
|
||||||
return socket
|
return socket
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
<script>
|
|
||||||
import Header from './Header.svelte';
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import {UserCheck} from '$lib/userFunction.js';
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
|
|
||||||
|
|
||||||
</style>
|
|
|
@ -83,10 +83,13 @@
|
||||||
const websocketUrl = `wss://docs.black-phoenix.ru/api/chat/ws/${chatId}`
|
const websocketUrl = `wss://docs.black-phoenix.ru/api/chat/ws/${chatId}`
|
||||||
|
|
||||||
console.log(socket)
|
console.log(socket)
|
||||||
if (socket)
|
if (socket){
|
||||||
|
console.log("Сокет есть")
|
||||||
|
socket.close();
|
||||||
socket = null
|
socket = null
|
||||||
|
}
|
||||||
socket = createWebSocket(websocketUrl, token, async (message) => {
|
let tokenForSocket = token.split(" ")[1];
|
||||||
|
socket = createWebSocket(websocketUrl, tokenForSocket, async (message) => {
|
||||||
|
|
||||||
console.log(message, "сообщение!!!!!")
|
console.log(message, "сообщение!!!!!")
|
||||||
if(message.flag === "pin" ){
|
if(message.flag === "pin" ){
|
||||||
|
@ -144,6 +147,8 @@
|
||||||
image = "https://images.black-phoenix.ru/static/images/images/%D0%B6%D0%BE%D0%BF%D0%B0%20%D1%81%D1%8A%D0%B5%D0%BB%D0%B0%20%D1%82%D1%80%D1%83%D1%81%D1%8B.jpg"
|
image = "https://images.black-phoenix.ru/static/images/images/%D0%B6%D0%BE%D0%BF%D0%B0%20%D1%81%D1%8A%D0%B5%D0%BB%D0%B0%20%D1%82%D1%80%D1%83%D1%81%D1%8B.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(socket.readyState === WebSocket.OPEN){
|
||||||
|
|
||||||
socket.send(JSON.stringify({flag: flag,
|
socket.send(JSON.stringify({flag: flag,
|
||||||
message: messageText,
|
message: messageText,
|
||||||
image_url: image,
|
image_url: image,
|
||||||
|
@ -158,6 +163,12 @@
|
||||||
answerMessageImgShow = false
|
answerMessageImgShow = false
|
||||||
answerMessage = ""
|
answerMessage = ""
|
||||||
answerMessageImg = ""
|
answerMessageImg = ""
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
console.log("ноуп" )
|
||||||
|
console.log(socket)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -201,15 +212,14 @@ let pickedId
|
||||||
let PickedText = ""
|
let PickedText = ""
|
||||||
let PickedImg = ""
|
let PickedImg = ""
|
||||||
let PickedName = ""
|
let PickedName = ""
|
||||||
//$: console.log(pickedId)
|
|
||||||
//$: console.log(answer)
|
|
||||||
|
|
||||||
let pinOrNot = false
|
let pinOrNot = false
|
||||||
|
|
||||||
function helperDivShow(event, id, text, img, username) {
|
function helperDivShow(event, id, text, img, username) {
|
||||||
|
if(pinnedMsg != null){
|
||||||
pinOrNot = pinnedMsg.some(msg => msg.id == id)
|
pinOrNot = pinnedMsg.some(msg => msg.id == id)
|
||||||
console.log(pinOrNot)
|
console.log(pinOrNot)
|
||||||
|
}
|
||||||
|
|
||||||
if (helperDiv) {
|
if (helperDiv) {
|
||||||
helperDivBoolShow = false
|
helperDivBoolShow = false
|
||||||
|
@ -787,7 +797,6 @@ let pinOrNot = false
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 80%;
|
height: 80%;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
//background-color: red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.newChatButtonDiv{
|
.newChatButtonDiv{
|
||||||
|
@ -796,7 +805,6 @@ let pinOrNot = false
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
//background-color: red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.newChatName {
|
.newChatName {
|
||||||
|
@ -869,7 +877,6 @@ let pinOrNot = false
|
||||||
.pickedChatDiv{
|
.pickedChatDiv{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
//background-color: red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.pickedChatImg{
|
.pickedChatImg{
|
||||||
|
@ -1183,7 +1190,6 @@ let pinOrNot = false
|
||||||
margin-top: -7px;
|
margin-top: -7px;
|
||||||
width: 50px;
|
width: 50px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
//background-color: red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.messageImage{
|
.messageImage{
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
<div class="noiseGif">
|
<div class="noiseGif">
|
||||||
<div class="regregDiv">
|
<div class="regregDiv">
|
||||||
<h2 class="reg1">Нет аккаунта? Лох!</h2>
|
<h2 class="reg1">Нет аккаунта? Лох!</h2>
|
||||||
<button class="reg2" on:click={() => (window.location.href = '/register')}
|
<button class="reg2" on:click={() => (location.assign('/register'))}
|
||||||
>Перестать был лохом</button>
|
>Перестать был лохом</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -120,21 +120,27 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="previewField">
|
<div class="previewField">
|
||||||
<h3>не жопа</h3>
|
<div class="previewCenter">
|
||||||
|
<h2 transition:blur={{delay:300, duration: 1000 }}>BP Chat</h2>
|
||||||
|
<img class="ImgOnRight" src="./BPytka.png" alt="птичка" transition:fly={{ y: -1920, duration: 1200, backInOut }}>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|
||||||
// .passwordError{
|
.previewCenter{
|
||||||
// z-index: 1;
|
display: flex;
|
||||||
// position: absolute;
|
flex-direction: column;
|
||||||
// color: var(--disable);
|
align-items: center;
|
||||||
// border: 1px solid white;
|
justify-content: center;
|
||||||
// bottom: 29.5%;
|
height: 100%;
|
||||||
// }
|
}
|
||||||
// не рабочая . переделать как нибудь <h3 class="passwordError">{passwordError}</h3>
|
|
||||||
|
.ImgOnRight{
|
||||||
|
width: 60%;
|
||||||
|
}
|
||||||
|
|
||||||
.greetingsDiv{
|
.greetingsDiv{
|
||||||
height: 30%;
|
height: 30%;
|
||||||
|
@ -239,7 +245,6 @@
|
||||||
.loginField {
|
.loginField {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
outline: 1px dotted red;
|
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
@ -263,10 +268,6 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.marginDiv > * {
|
|
||||||
//border: 1px solid white;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
input {
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
background:
|
background:
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
BIN
static/image/happy pig.jpg
Normal file
BIN
static/image/happy pig.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
Loading…
Add table
Reference in a new issue