diff --git a/examples/chat/index.html b/examples/chat/index.html index d5afd1b6..4df3d917 100644 --- a/examples/chat/index.html +++ b/examples/chat/index.html @@ -1,6 +1,7 @@ + Converse @@ -49,7 +50,7 @@ margin-bottom: 0.5em; } - .send { + .say { margin: 0 0 0.4em 0.4em; padding: 0.2em 0.5em; } @@ -75,7 +76,7 @@
-
send
+
say

@@ -98,75 +99,62 @@ - + \ No newline at end of file diff --git a/examples/contact/index.html b/examples/contact/index.html index 5c42caa8..9d119274 100644 --- a/examples/contact/index.html +++ b/examples/contact/index.html @@ -4,12 +4,10 @@ - - +
Welcome,
@@ -212,10 +201,10 @@ c.tell("Passphrase needs to be longer than 9 characters."); return; } - but.addClass('loading'); + but.addClass('pulse'); data.alias = data.alias.toLowerCase(); user.create(data.alias, data.pass, function(ack){ - if(!ack.wait){ but.removeClass('loading') } + if(!ack.wait){ but.removeClass('pulse') } if(ack.err){ c.tell(ack.err); return } if(ack.pub){ gun.get('users').get(data.alias).put(gun.get('alias/'+data.alias)); @@ -237,10 +226,10 @@ return; } var but = form.find('button:first'); - but.addClass('loading'); + but.addClass('pulse'); data.alias = data.alias.toLowerCase(); user.auth(data.alias, data.pass, function(ack){ - if(!ack.wait){ but.removeClass('loading') } + if(!ack.wait){ but.removeClass('pulse') } if(ack.err){ c.tell(ack.err); return } session(data); }); diff --git a/examples/style.css b/examples/style.css index e79f4374..75fb451c 100644 --- a/examples/style.css +++ b/examples/style.css @@ -5,24 +5,33 @@ html, body { padding: 0; font-family: 'Oxygen', 'Trebuchet MS', arial; position: relative; + background: black; + color: white; } body { font-size: 18pt; } -div, ul, li, form, p, span, button, input, textarea { +div, ul, li, p, span, form, button, input, textarea { margin: 0; padding: 0; position: relative; overflow: hidden; + font-size: 1em; + line-height: 1.5em; -webkit-transition: all 0.3s; transition: all 0.3s; box-sizing: border-box; } +button, input, textarea { + background: white; + border: none; + color: black; +} + input, textarea { - border: none; width: 100%; } @@ -132,6 +141,17 @@ ul, li { color: white; } +.pulse { + animation: pulse 2s infinite; +} + +@keyframes pulse +{ + 0% {opacity: 1;} + 50% {opacity: 0.5;} + 100% {opacity: 1;} +} + .hue { background: #4D79D8; -webkit-animation: hue 900s infinite; diff --git a/examples/todo/index.html b/examples/todo/index.html index c513fa4e..a3d4e630 100644 --- a/examples/todo/index.html +++ b/examples/todo/index.html @@ -1,6 +1,7 @@ + Think @@ -50,7 +51,7 @@ // for how to build a simplified version // of this example: https://scrimba.com/c/cW2Vsa var gun = Gun(location.origin+'/gun'); - var think = gun.get('think'); + var think = gun.get('think/' + location.hash.slice(1)); var typing, throttle; $('.add').on('click', function(){ $('
  • ').attr('contenteditable', true).prependTo('ul'); diff --git a/examples/gps/index.html b/examples/where/index.html similarity index 91% rename from examples/gps/index.html rename to examples/where/index.html index 8c73ffcc..0c956b3a 100644 --- a/examples/gps/index.html +++ b/examples/where/index.html @@ -1,11 +1,11 @@ - GPS by GUN + Where - - + +
    @@ -68,7 +68,7 @@ word-wrap: break-word; } - + ')){ return } + file = file.replace('', + ""); + return file; + }); + }, {i: i += 1, config: config})); + }); + // NOW, this is very important: + // Do not proceed to the next test until + // every single server (in different machines/processes) + // have ALL successfully launched. + return Promise.all(tests); + }); + + it(config.browsers +" browser(s) have joined!", function(){ + console.log("PLEASE OPEN https://"+ config.IP +":"+ (config.port) +" IN "+ config.browsers +" BROWSER(S)!"); + return browsers.atLeast(config.browsers); + }); + + it("Browsers load SEA!", function(){ + var tests = [], i = 0; + browsers.each(function(client, id){ + tests.push(client.run(function(test){ + test.async(); + //console.log("load?"); + function load(src, cb){ + var script = document.createElement('script'); + script.onload = cb; script.src = src; + document.head.appendChild(script); + } + load('sea.js', function(){ + test.done(); + }); + }, {i: i += 1, config: config})); + }); + return Promise.all(tests); + }); + + it("Browsers initialized gun!", function(){ + var tests = [], ids = {}, i = 0; + // Let us create a list of all the browsers IDs connected. + // This will later let each browser check against every other browser. + browsers.each(function(client, id){ + ids[id] = 1; + }); + browsers.each(function(client, id){ + tests.push(client.run(function(test){ + localStorage.clear(); + var env = window.env = test.props; + var peers = [], i = env.config.servers; + while(i--){ + // For the total number of servers listed in the configuration + // Add their URL into an array. + peers.push('https://'+ env.config.IP + ':' + (env.config.port + (i + 1)) + '/gun'); + } + var gun = window.gun = Gun(peers); + var user = window.user = gun.user(); + var go = window.go = {num: 0, total: 0, users: {}, pub: {}}; + window.ID = env.id; + go.check = Gun.obj.map(env.ids, function(v,id,t){ + // for each browser ID + // they will be saving X number of messages each. + go.users[id] = true; // set an outstanding flag to check against. + var i = env.config.each; + while(i--){ + // So add a deterministic key we can check against. + t(id + (i + 1), 1); + // And count up the total number of messages we expect for all. + go.total += 1; + } + }); + + console.log(peers, go); + }, {i: i += 1, id: id, ids: ids, config: config})); + }); + return Promise.all(tests); + }); + + it("All users created!", function(){ + var tests = [], ids = {}, i = 0; + browsers.each(function(client, id){ + ids[id] = 1; + }); + browsers.each(function(client, id){ + tests.push(client.run(function(test){ + test.async(); + + gun.on('secure', function(at){ + /* enforce some rules about shared app level data */ + if(!at.put || !at.put.users){ return } + var no; + Gun.node.is(at.put.users, function(val, key){ + Gun.SEA.read(val, false, function(val){ + if('alias/'+key === Gun.val.rel.is(val)){ return } + no = true; + }) + if(no){ return no } + }); + if(no){ return } + this.to.next(at); + }); + + var unsafepassword = 'asdf'+ID; + console.log("sign in and up:", ID); + window.user.create(ID, unsafepassword, function(ack){ + if(ack.err || !ack.pub){ return } + window.pub = ack.pub; + gun.get('users').get(ID).put(gun.get('alias/'+ID)); + console.log("signed up", ack.pub); + console.debug.j = 1; + window.user.auth(ID, unsafepassword, function(ack){ + console.debug.j = 0; + console.log("signed in", ack); + if(ack.err || !ack.pub){ return } + test.done(); + }); + }); + + }, {i: i += 1, id: id, ids: ids, config: config})); + }); + return Promise.all(tests); + }); + + it("Start reading and sending messages!", function(){ + var tests = [], ids = {}, i = 0; + browsers.each(function(client, id){ + ids[id] = 1; + }); + browsers.each(function(client, id){ + tests.push(client.run(function(test){ + test.async(); + + gun.get('users').map().map() + .get('who').get('said').map().on(function(msg){ + check(msg); + }); + + var said = user.get('who').get('said'); + + function run(i){ + + var what = i +"|||"+ "Hello world!" +"|||"+ pub +"|||"+ ID; + said.set({ + what: what + });/*, function(ack){ + if(ack.err){ return } + test.done(); + });*/ + + } + /* TODO: sometimes sign in hangs */ + console.log("<<<<< START >>>>>"); + var i = 0, to = setInterval(function frame(a, b){ + if(!b && 2 <= (b = env.config.burst)){ + while(--b){ + frame(i, true); + } + return; + } + if(env.config.each <= i){ + clearTimeout(to); + return; + } + run(i += 1); + }, env.config.wait || 1); + + + var col = $("
    ").css({width: 250, position: 'relative', float: 'left', border: 'solid 1px black'}), cols = {}; + var report = $("
    ").css({position: 'fixed', top: 0, right: 0, background: 'white', padding: 10}).text(" / "+ go.total +" Verified").prependTo('body'); + var reportc = $('').text(0).prependTo(report); + var last = $("
    ").text("Processing: ").css({border: "solid 1px black"}).appendTo("body"); + last = $("").text(" ").appendTo(last); + + function check(data){ + data = data.what.split("|||"); + var msg = {num: data[0], what: data[0] +' '+ data[1], who: data[2], id: data[3]}; + var who; + if(!go.pub[msg.who]){ + go.pub[msg.who] = msg.id; + go.users[msg.id] = false; + //who = cols[msg.id] = col.clone(true).appendTo('body'); + //who.prepend(""); + //who.prepend(""); + } + if(!go.check[msg.id + msg.num]){ + return; + } + go.check[msg.id + msg.num] = false; + clearTimeout(end.to); end.to = setTimeout(end, 9); + reportc.text(++go.num); + last.text(msg.what); + //who = cols[msg.id]; + //$("
    ").css({border: 'solid 1px blue'}).text(msg.what).appendTo(who); + } + + function end(){ + var wait = Gun.obj.map(go.users, function(v){ if(v){ return true }}); + if(wait){ return } + var more = Gun.obj.map(go.check, function(v){ if(v){ return true }}); + if(more){ return } + test.done(); + } + + }, {i: i += 1, id: id, ids: ids, config: config})); + }); + return Promise.all(tests); + }); + + /* MODEL TEST + it("Browsers initialized gun!", function(){ + var tests = [], ids = {}, i = 0; + browsers.each(function(client, id){ + ids[id] = 1; + }); + browsers.each(function(client, id){ + tests.push(client.run(function(test){ + // code here + }, {i: i += 1, id: id, ids: ids, config: config})); + }); + return Promise.all(tests); + }); + */ + + it("All finished!", function(done){ + console.log("Done! Cleaning things up..."); + setTimeout(function(){ + done(); + }, 2000); + }); + + after("Everything shut down.", function(){ + browsers.run(function(){ + //location.reload(); + //setTimeout(function(){ + //}, 15 * 1000); + }); + return servers.run(function(){ + process.exit(); + }); + }); +}); \ No newline at end of file