이 오류가 왜 발생하는지 궁금합니다.
코드 :
import 'firebase-admin/firestore';
import { cert, initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
import { WebSocket, WebSocketServer } from 'ws';
import express from 'express';
const vol = 0.1;
const min = 1 / (1 + vol), max = 1 + vol;
const firebaseApp = initializeApp({
credential: cert("./serviceAccount.json"),
databaseURL: "https://stock-testify.firebaseio.com"
}, "admin_" + (Date.now().toString(32)));
const db = getFirestore(firebaseApp);
const wss = new WebSocketServer({ port: 8080 });
/**
* @type WebSocket[]
*/
let wsArr = [];
wss.on('connection', function connection(ws) {
const index = `${new Date().getTime()}${Math.random()}`;
wsArr.push(ws);
ws.on('error', console.error);
ws.on('message', function message(data) {
console.log('received: %s', data);
});
ws.on('close', () => {
console.log('closed');
wsArr = wsArr.filter(w => w.ws != ws);
})
});
updateStocks();
function updateStocks() {
setTimeout(() => {
// console.log(new Date());
db.collection('stocks').get()
.then(q => {
q.docs.forEach(async (doc) => {
const priceList = doc.data().priceList ?? [];
const date = new Date();
const newPrice = {
value: Math.round((priceList.length > 0 ? priceList[priceList.length - 1].value
* (Math.random() * (max - min) + min) * (Math.random() * (max - min) + min) : 1000) * 100) / 100,
time: date
};
priceList.unshift(newPrice);
doc.ref.update({ priceList: priceList });
wsArr.forEach(ws => ws.send(`${doc.id}/${newPrice.value}/${date.getTime()}`));
});
});
updateStocks();
}, 60000 - (new Date().getSeconds() * 1000 + new Date().getMilliseconds()))
}
```
불러오는 중...