我是React Native的新手,但对React非常熟悉.作为一个初学者,我正在寻找在云服务器之间建立连接并使用websockets建立反应原生,正如我在文档中看到的那样.不幸的是,没有像样的例子可以帮助我.这就是我到目前为止所做的一切:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button
} from 'react-native';
export default class raspberry extends Component {
constructor(props) {
super(props);
this.state = { open: false };
this.socket = new WebSocket('ws://127.0.0.1:3000');
this.emit = this.emit.bind(this);
}
emit() {
this.setState(prevState => ({ open: !prevState.open }))
this.socket.send("It worked!")
}
render() {
const LED = {
backgroundColor: this.state.open ? 'lightgreen' : 'red',
height: 30,
position: 'absolute',
flexDirection: 'row',
bottom: 0,
width: 100,
height: 100,
top: 120, …Run Code Online (Sandbox Code Playgroud) 如果可能的话,我希望获得原子的默认主题以将其导入 sublime text 3。我正在特别寻找配色方案,任何提示或源代码将不胜感激,ty!
我正在尝试取消订阅套接字并让它离开他所在的房间.我知道他的socket.id,为了让你更好理解,当房间的创造者离开时,一个特定的插座/所有套接字应该离开.泰!
我正在制作一个自定义的firebase验证方法,到目前为止,我设法制作一个表单,收集用户信息并将它们与socket.io一起发送到服务器,然后发送到firebase,如果验证正常.这是我到目前为止所得到的,但是当我开始插入firebase时,console.log()不止一次调用gets意味着firebase尝试插入超过需要的内容:
io.on("connection", socket => {
socket.on("register", user => {
console.log("Register") //gets called once, this is good!
let db = firebase.database();
let usersRef = db.ref("users").child(user.username);
firebase.database().ref("users").on("value", data => { //here we read from DB
console.log('Firebase begins here!') //this gets loged multiple times
let isValid = true; //simple var to check if validation is true/false
for (var el in data.val()) { //here we take user informations
if(data.val()[el]["name"]==user.username) { // check if username exists
console.log("Username already takken!") //gets fired more time …Run Code Online (Sandbox Code Playgroud) atom-editor ×1
firebase ×1
javascript ×1
node.js ×1
react-native ×1
reactjs ×1
socket.io ×1
sublimetext3 ×1
websocket ×1