Socket.IO

Node.js - Socket.io repeats the 'io.on('connection') over and over

寵の児 提交于 2020-05-17 06:58:05
问题 So, I am still in the experimental phase of Socket.io, but I just can't figure out why my code is doing this. So, I have the code below and when I console.log the code, it repeats the the connection even when there is only one connection. Do you know a solution? io.on('connnection', (socket) => { console.log("A new user is connected.") }) Client side: <script src="/socket.io/socket.io.js"></script> <script> var socket = io() </script> Node.js Console: A new user is connected. A new user is

Keep socket connection when new page is loaded

喜欢而已 提交于 2020-05-17 03:02:10
问题 I have a small project with socket.io and node.js. Basically the landing page (index.html) is a waiting room for players, who can agree to play with each other. In that case, I want to redirect them to a different html (game.html, which is in the same folder as index.html). I want to keep the socket connection, since during the game there has to be communication with the server. I have tried two ways, but both fail. In each case, I change the client-side window.location (as described here). 1

Keep socket connection when new page is loaded

放肆的年华 提交于 2020-05-17 03:00:38
问题 I have a small project with socket.io and node.js. Basically the landing page (index.html) is a waiting room for players, who can agree to play with each other. In that case, I want to redirect them to a different html (game.html, which is in the same folder as index.html). I want to keep the socket connection, since during the game there has to be communication with the server. I have tried two ways, but both fail. In each case, I change the client-side window.location (as described here). 1

Not understanding why I am not receiving any rssi data from my raspberry pi 3 to my server

*爱你&永不变心* 提交于 2020-05-16 06:32:25
问题 I am having problems trying to display the RSSI values from my raspberry pi 3 to show on my server. Connection Success as you can see by the picture I have been able to successfully connect my client and server but no rssi data are showing. The following code is what I executed from the pi: var noble = require('noble'); //replace localhost with your server's IP; var socket = require('socket.io-client')('http://localhost:3000/scanner'); //replace with your hardware address var addressToTrack =

Socket.io - Is the “socket ID” considered sensitive information?

馋奶兔 提交于 2020-05-16 05:04:07
问题 I'm realizing a simple chat application with Node.js and socket.io and wonder if sharing the socket IDs of all the clients throughout Objects is considered a good practice? To explain, each of my users are represented so : { nick : 'John Doe', dateJoined : Date.now(), rank : 0, id : socket.id } A list of all my clients is stored on the server const usersList = [ {...}, {...}, ... ] All of my clients needs to see who's connected, so this usersList should be shared to all clients. And if a

How to mock socket.io-client using jest/react-testing-library

北战南征 提交于 2020-05-16 03:11:30
问题 I am building a chat app and would like to write integration tests using react-testing-library and can not figure out how to mock socket.io-client 's socket.on , socket.emit , etc. I tried follow this article and tried using mock-socket.io and socket.io-mock all with no luck. This is the component I am trying to test: import React, { useEffect, useState } from 'react'; import io from 'socket.io-client'; import 'dotenv/config'; import ChatInput from './ChatInput'; import Messages from '.

How to mock socket.io-client using jest/react-testing-library

杀马特。学长 韩版系。学妹 提交于 2020-05-16 03:10:21
问题 I am building a chat app and would like to write integration tests using react-testing-library and can not figure out how to mock socket.io-client 's socket.on , socket.emit , etc. I tried follow this article and tried using mock-socket.io and socket.io-mock all with no luck. This is the component I am trying to test: import React, { useEffect, useState } from 'react'; import io from 'socket.io-client'; import 'dotenv/config'; import ChatInput from './ChatInput'; import Messages from '.

Send cookies with socket.io-client

梦想与她 提交于 2020-05-15 05:33:19
问题 I am trying to connect to a websocket. I would like to add cookies from the actual website login, so the server (which is NOT mine), knows who I am (events are account specific). var opts = { extraHeaders: { 'Cookie': "_ga=GA1.2.17432343994.1475611967; _gat=1; __cfduid=dc232334gwdsd23434542342342342475611928" }, } function socket() { var socket = io(websiteURL, opts); var patch = require('socketio-wildcard')(io.Manager); patch(socket); socket.on('connect', function () { console.log(" >

How to use socket.IO client type definitions for Typescript?

不羁岁月 提交于 2020-05-15 05:15:40
问题 I have installed the Typescript definitions for a SocketIO client using npm install @types/socket.io-client But in VS Code I still get type errors: let socket: SocketIOClientStatic = io() Type 'Socket' is missing the following properties from type 'SocketIOClientStatic': protocol, Socket, Manager, managersts(2739) All these properties are not mentioned as options in intellisense, or in he socketIO docs... they shouldn't be needed when creating an io() How can I use Typescript with the

Page becomes unresponsive when data added to amChart4 through socket

佐手、 提交于 2020-05-14 09:09:45
问题 I'm displaying 3 charts (Gauge chart, Pie chart, XYChart) -using amChart4 and I'm fetching data from backend (sqlite3). Here I'm using some real time data i.e., for every minute data is added in database and I'm fetching that data and displaying it in chart. In order to fetch regularly I'm using socket . After some time page becomes unresponsive (chrome alert msg). It crashes. Below is my code for the client-side (Front end). product.service.ts init() { this.getConfig(); this._todayWithSec =