/
githubmirror
/
socket.io
Обзор
Документация
Войти
/
githubmirror
/
socket.io
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/angular-todomvc/server.ts
28 строк
631 B
Damien Arrachequesne
docs: use "connection" instead of "connect"
12 авг 2023, 11:10
Не верифицирован
12 авг 2023, 11:10
fd9dd74
Код
Авторство
О чём код?
import { Server } from "socket.io"; const io = new Server(8080, { cors: { origin: "http://localhost:4200", methods: ["GET", "POST"] } }); interface Todo { completed: boolean; editing: boolean; title: string; } let todos: Array<Todo> = []; io.on("connection", (socket) => { socket.emit("todos", todos); // note: we could also create a CRUD (create/read/update/delete) service for the todo list socket.on("update-store", (updatedTodos) => { // store it locally todos = updatedTodos; // broadcast to everyone but the sender socket.broadcast.emit("todos", todos); }); });