Basic websocket server for foxql-peer
npm i @foxql/foxql-server
npm run dev
const foxql = require('@foxql/foxql-server');
const server = new foxql.server(connection, [
'https://foxql-bridge.herokuapp.com' // bridge server url
], '{YOUR_NODE_HOST}');
async function connection(socket)
{
console.log('New Connection');
}
server.open();
const foxql = require('@foxql/foxql-server');
const server = new foxql.server();
server.use('serverOptions',{
port : 3000,
host : '0.0.0.0',
protocol : 'http'
});
server.open();
const foxql = require('@foxql/foxql-server');
const server = new foxql.server(connection);
server.open();
async function connection(socket)
{
console.log('user connected!');
}
create a 'hello-word.js' and put this codes.
const name = 'hello-word';
exports.listener = (socket, server, data) => {
const id = socket.id;
console.log(`Hello ${id}`);
socket.emit('hello-world', `Your socketId is ${id}`);
}
exports.name = name;
and push your server! This example.
const foxql = require('../index.js');
const server = new foxql.server();
server.pushEvent(
require('./hello-world.js')
);
server.open();