Monday 15 June 2015

javascript - I am trying to manage a small number of users control of a webpage -



javascript - I am trying to manage a small number of users control of a webpage -

so start off, have raspberry pi, running lighttp server on arch. have webpage have max of 10 people connected @ time. each user given tag "master," or "observer." webpage have controls "master," can use.

just heads up: learning of may making mistakes how accomplish this.

my original thought has follows. when user connects database ip address grabbed , inserted sqlite database, along user tag, , time of connection. there able query database users tag when tried execute various commands.

whatever utilize needs lightweight , not store cookies on users device.

here javascript have, isn't efficient, plan on getting working making nice.

this code supposed connect databases , insert user.

<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script> <script type="application/javascript"> var db = opendatabase('usercon.contbl.sqlite', '1.0', 'contbl', 1024); db.transaction(function(transaction) { var ip = myip; var constatus = "master" var date = new date(); console.log('inserting database ' + ip + ',' + constatus +',' + date); transaction.executesql('insert contbl(ipad, contype, lastactive) values (?,?,?,?)',[ip,constatus,date], function(transaction, results) { }, function (transaction, err){ console.log(err.message+":error"); // here error }); }); </script> <script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"> </script>

i unable connect sqlite database created on pi, after research may because sqlite supposed run locally , not on server.

is there sort of work around point sqlite database on pi, or there improve resource utilize type of task?

edit:

i guess original post not specific enough. basic thought need able pass tiny bit of info webpage, server hosting it. i.e. user connect server , sends ip server tags ip observer of controller. there server treat each person viewing webpage differently based on how user tagged.

my original plan utilize lite weight database sqlite, found out, sqlite local utilize only. need on sever lower 10 connections.

my hope has suggestion, or illustration solve problem.

the mutual way javascript running on web page talk server these days kind of restful web service.

you'll want find server-side programming language runs on pi. maybe node.js? it's javascript on server, see here: http://weworkweplay.com/play/raspberry-pi-nodejs/

you write whatever methods want in server-side language, methods talk database, have client-side javascript phone call methods. google "rest services node.js" , you'll find plenty of how-tos.

javascript sql-server database sqlite3 raspberry-pi

No comments:

Post a Comment