flotype / now Goto Github PK
View Code? Open in Web Editor NEWNowJS makes it easy to build real-time web apps using JavaScript
Home Page: http://www.nowjs.com
License: MIT License
NowJS makes it easy to build real-time web apps using JavaScript
Home Page: http://www.nowjs.com
License: MIT License
I'm using firefox 4.0rc2. A warning "Resource interpreted as Script but transferred with MIME type text/plain." triggered when loading now.js.
People live off examples.
Would be great if you had a sample app which laid out all the patterns, with an easy step by step
<install node>
<install npm>
git clone nowjs
node server.js
to attract both newcomers to node and newcomers to nowjs and the ways it can be used.
on Mac, Safari - I run the Express chat demo - create two users, send no messages... and wait a few minutes... to see the following warning message
$ node app
Express server listening on port 8080
8 Apr 00:08:52 - Your node instance does not have root privileges. This means that the flash XML policy file will be served inline instead of on port 843. This will slow down initial connections slightly.
8 Apr 00:08:52 - socket.io ready - accepting connections
8 Apr 00:08:57 - Initializing client with transport "xhr-polling"
8 Apr 00:08:57 - Client 1566290301270783 connected
Joined: undefined
8 Apr 00:09:36 - Initializing client with transport "websocket"
8 Apr 00:09:36 - Client 3758795636240393 connected
Joined: user1
8 Apr 00:10:25 - Initializing client with transport "websocket"
8 Apr 00:10:25 - Client 6171762924641371 connected
Joined: user2
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket. (events.js:123:17)
at [object Object]. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:83:20)
at [object Object]._onConnect (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-polling.js:23:35)
at [object Object].check (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:77:12)
at HTTPServer. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:33:14)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:678:27)
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket. (events.js:123:17)
at [object Object]. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:70:19)
at [object Object]._onConnect (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-polling.js:23:35)
at [object Object].check (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:77:12)
at HTTPServer. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:33:14)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:678:27)
Hi!
Sorry if I missed this in the docu, but how do I unset variables/functions in client context?
delete this.now.foo
causes segfault, this.now.foo = undefined/null
causes bump at L208 of nowServerLib.js
update: this.now.foo = false
works, but still...
TIA,
--Vladimir
Hi!
L#181 nowServerLib.js -- bad things happen if theArgs[i] is null/undefined/non-object
--Vladimir
loading ext-base will cause callbacks not to be called
opening another ticket because I accidentally closed #17
I'm using node 0.4.3 (without https) and nowjs 0.3 on a virtualbox ubuntu. I get this error message when I try to send a message on the example chat:
22 Mar 01:27:02 - xhr-multipart message handler error - TypeError: Object #<Object> has no method 'receiveMessage'
at Object.<anonymous> (/home/john/local/node/lib/node/.npm/now/0.3.0/package/examples/helloworld_server.js:22:65)
at Object.remoteCall (/home/john/local/node/lib/node/.npm/now/0.3.0/package/lib/nowServerLib.js:187:15)
at [object Object].<anonymous> (/home/john/local/node/lib/node/.npm/now/0.3.0/package/lib/nowServerLib.js:127:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/home/john/local/node/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at IncomingMessage.<anonymous> (/home/john/local/node/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-multipart.js:48:16)
at IncomingMessage.emit (events.js:61:17)
at HTTPParser.onMessageComplete (http.js:132:23)
at Socket.ondata (http.js:1001:22)
at Socket._onReadable (net.js:675:27)
Nested variables fail to sync correctly in IE 6/7/8
If you include the /nowjs/now.js script in the HTML, everything works fine. The problem arises if you want to inject the script after the page has loaded for some reason.
Suggested fix in lib/nowServerLib.js at line 289
- if(request.url === "/nowjs/now.js") { + if(request.url.split('?')[0] === "/nowjs/now.js") {
Consider the following client code:
<script type="text/javascript" charset="utf-8">
now.listen = function(msg) {
alert(msg);
}
$(document).ready(function() {
now.send("Ha");
});
</script>
and the following server code:
everyone.now.send = (msg) ->
everyone.now.listen msg
Upon page load, I should see an alert box popup and display "Ha". Unfortunately, this does not happen, and I get the following error in the browser console:
Uncaught TypeError: Object #<Object> has no method 'send'
If I change the client side code to:
$(document).ready(function() {
setTimeout(function(){now.send("Ha");},1000)
});
The alert box successfully shows up and displays "Ha".
This means that nowjs does not (completely) initialize upon dom ready, requiring a few extra moments to work. This is a problem for applications that depend on nowjs behavior upon dom initialization, and setTimeout
seems too hacky a work'a'round.
Hi guys,
first of all congratulations for your work, this is really awesome! =)
We at my workplace are developing with a small chat and a map that can be edited and in Firefox 3.6.16 for Ubuntu I am getting an error that states:
now.ready is not a function.
The strange thing is that this is working in Google Chrome in the same machine and with the same server.
In Firefox 4 in Mac OSx it seems to be working alright.
Any idea of what might be wrong? Cheers!
In this test I've written
https://github.com/straps/nodejs-demos/tree/master/24-express-nowjs
I get an error loading http://IP:8080/client.html with Internet Explorer: io is not defined
Example works well on Chrome and Firefox...am I missing something?
Thanks
Hi All,
I can see how nowjs could easily be used to create a chat room. Talk about simple!
Context: I'm a complete node.js newbie. This is my first exposure to it, and perhaps that's where my confusion arises.
I don't see how to limit the recipients of a message. If you're building a web app, you usually don't want all your messages to go to every person. In fact, I'd go so far as to say that would be the norm: you want most messages to go to a single client, or at times a selection of clients.
I don't understand enough about the internals to see how to iterate over the clients and only send a message to client 'x', or send a message to clients that have some property (like belonging to a particular account).
Further, is there a way to make constants in the now pocket? I'd like to be able to set a value on the server, and for the client to be able to read it, but not to modify it.
Thanks,
-Ken
For a RIA to work, the server has to be aware of the variables of each client. Thus, the server should be the one instantiating the clients' variables of the magic synced pool.
Clients thus do not need the right to create new variables on the server. Also, the current implementation allows clients to create infinite amounts of variables causing memory problems on the server's side.
SERVER
everyone.now.getData = function(callback) {
callback(getData())
}
CLIENT
now.ready(function() {
now.getData(function(data) {
fillTree(treePanel.getRootNode(), data);
})
})
I took a wireshark trace and I see the instructions to call the callback (I think) but the callback never gets called. The documentation does not cover this well.
Hello,
I'm having this error every time I load a page, regardless of if I have included now.js script on client-side. My guess would be, it's because of latest version of Connect Middleware; since they have updated their APIs.
I'm on Mac OS, Google Chrome(though, the same error appears with Firefox as well).
I would really appreciate your help.
Thank You.
{ stack: [Getter/Setter],
arguments:
[ 'indexOf',
{ stack: [Object],
connections: 6,
allowHalfOpen: true,
watcher: [Object],
_events: [Object],
httpAllowHalfOpen: false,
match: [Object],
lookup: [Object],
settings: [Object],
redirects: {},
isCallbacks: {},
viewHelpers: [Object],
dynamicViewHelpers: [Object],
errorHandlers: [],
route: '/',
routes: [Object],
router: [Getter],
__usedRouter: true,
type: 'tcp4',
fd: 9 } ],
type: 'undefined_method',
message: [Getter/Setter] }
TypeError: Object #<HTTPServer> has no method 'indexOf'
at HTTPServer.<anonymous> (/Users/Me/Work/testing/app.coffee:11:19)
at HTTPServer.<anonymous> (/usr/local/lib/node/.npm/now/0.3.2/package/lib/nowServerLib.js:293:31)
at HTTPServer.<anonymous> (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:35:20)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:677:27)
at IOWatcher.onReadable [as callback] (net.js:177:10)
Hey guys, I was wondering if there's any way you can make a way to allow us to pass options to Socket.IO via Now? Basically, I just want to suppress Socket's logging and use my own, but currently, I can't do that without modifying NowJS or Socket.
Thanks!
Hey, this is probably a stupid question, but it seems like this would work wonderfully for what I am trying to do. My only question is, if I store a json object in now
, and I only update some of the values in it, is there some mechanism in place to only "send" (if that's even what happens) the changed values, or does it send everything again?
To provide context: I am writing a web interface for a command-line program, communicating through xml-rpc. I would like to have it auto-update data on the pages, and so the closest I could get to this due to the nature of the program is polling. I don't want to do this on the client-side as this would bombard the program (if each client polls at different times). I was thinking of writing a node back-end that would itself poll the command line program on an interval, and then if there were changes to the data, it would push them out.
The 'auto-syncing' feature of the now
namespace seemed really interesting for this application.
Basically the command-line app has a list of items each with its own properties, so the retrieved data by the node back-end would look roughly like this:
data = {
item-1: {
name: "first",
progress: "53%"
},
item-2: {
name: "second",
progress: "67%"
}
}
Something that might change from one poll interval to the next is item-2's progress, for example.
To repeat my question: If I were to simply re-assign the now.data variable each time with the new hash, is there a mechanism in place so that the client only has to download the changed part (item-2's progress)?
If not, can anyone provide any opinions/suggestions for what I'm trying to do?
I would really appreciate it.
this may be a duplicate of pbcomm's issue #36.
the following behaviour happens infrequently - i've not been able to establish what triggers it. i'm using 0.5.0 w Safari
if the bug is happening -
3) the "ho" message doesn't appear in user1's window
4) subsequent messages from both user1 and user2 appear twice in user1's window
In order to tie now clients to the browsing session, it would be nice to have access to the request object and thus to the client's cookies.
Hi!
https://github.com/Flotype/now/blob/master/lib/nowUtil.js#L86:
Sometimes causes the falsy negatives -- i.e. I pass a hash which surely is created from scratch (by literal notation) and the function returns false. When I change it to be Object.hasOwnProperty.call(currVar, prop)
the result is positive.
Notice, that in CoffeeScript (which compiles to a "least common denominator" JS code, which runs on every JS engine), they use namely the said signature -- Object.hasOwnProperty.call(obj, prop)
to determine whether a property is own.
I'd recommend to introduce a helper function __isOwnProp(obj, propName){return Object.hasOwnProperty.call(obj, propName)}
and rewrite all invocations of obj.hasOwnProperty(prop)
.
Sorry for being didactic, and TIA,
--Vladimir
Can you please add a license file, or mention on your website how the software is licensed?
I'd love to integrate Now.js into my project (which will be on a public website), but I don't dare until the licensing is explicit. I don't want to steal anything that I am not welcome to.
I see this is up on npm but there's no package.json all up in this dist.
Some developers will want a different priority of transport types.
Others will want to completely disable certain methods as they would be too laggy for the application to function or ask too much from the server.
Thus, it has to be possible to set this transport order and disable certain transports completely.
Hi!
How do I manage a client to call a server-side async function (the one that doesn't return the result but instead calls a given callback)?
TIA,
--Vladimir
I made a simple demo in express and it worked fine in two different web browsers on the same computer, but when I tested on another computer in the same network, it didn't work and the console said something about socket.io.js being undefined.
Hey, I unfortunately don't have a great deal of replication information around this but I did grab the stack trace from Node. I was running the chat demo (which is awesome) and I noticed every once in a while one of the clients would disconnect. It would continue to publish updates, but not receive them (which I found odd). It did occur at the same time as this stack trace:
{ stack: [Getter/Setter],
arguments: [ 'hasOwnProperty', undefined ],
type: 'non_object_property_call',
message: [Getter/Setter] }
TypeError: Cannot call method 'hasOwnProperty' of undefined
at Object.getVarFromFqn (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowUtil.js:86:18)
at Object.remoteCall (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:55:31)
at [object Object]. (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:273:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at Parser. (native)
at Parser.emit (events.js:64:17)
at Parser.parse (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:195:12)
at Parser.add (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:182:8)
at Socket. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:116:17)
{ stack: [Getter/Setter],
arguments: [ 'hasOwnProperty', undefined ],
type: 'non_object_property_call',
message: [Getter/Setter] }
TypeError: Cannot call method 'hasOwnProperty' of undefined
at Object.getVarFromFqn (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowUtil.js:86:18)
at Object.remoteCall (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:55:31)
at [object Object]. (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:273:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at Parser. (native)
at Parser.emit (events.js:64:17)
at Parser.parse (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:195:12)
at Parser.add (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:182:8)
at Socket. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:116:17)
{ stack: [Getter/Setter],
arguments: [ 'hasOwnProperty', undefined ],
type: 'non_object_property_call',
message: [Getter/Setter] }
TypeError: Cannot call method 'hasOwnProperty' of undefined
at Object.getVarFromFqn (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowUtil.js:86:18)
at Object.remoteCall (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:55:31)
at [object Object]. (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:273:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at Parser. (native)
at Parser.emit (events.js:64:17)
at Parser.parse (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:195:12)
at Parser.add (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:182:8)
at Socket. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:116:17)
Instead of everyone.connected(function() { }); use the node event system so that people can do everyone.on('connected') etc.
This has several advantages:
- consistent with node style
- allows unregistering event listeners
- allows multiple listeners
Hi!
At initial page load regardless of used socket.io transport an embedded flash object appears and then disappeares, causing unpleasant flashing. Wonder if this is pure socket.io issue?
TIA,
--Vladimir
Hi, is it intended to support Client-Server connections between multiple Node Instances in the future? this would really be a great feature for Clustering and alike :)
loading ext-base will cause callbacks not to be called
Hi,
is it possible to extend the sample with a list of people that are online? I am not very successful at creating my own sample with a shared list of available people. Would be nice to have this as an addition to the current sample. I guess you can create it in 20 minutes :-).
thanks
Hi,
Do you have an example of nowjs working with express js library. I see you the nowjs API takes a httpserver, but when i replaced it with the server object from express, it throws an exception....
Is it possible to get this working together with express js ?
I did a very basic test, but i will dig deep into this to see what can be done as well.
I had a security question.
I just read the nowjs docs. And it seems that it would be easy to sabatoge the server by passing up code that sets the server variables to null.
I guess it would be possible to avoid this if you never put anything in now that had a function attached to it. But it doesn't say this anywhere and it seem like a pretty big issue.
For example. Say I have now.name = {firstname: 'skile', lastname: 'sare', fullname= function(){return this.firstname + ' ' + this.lastname}};
And then maliciously change this.fullname = function(){app = 1'}; (via the chrome script window or some other method)
If the server calls this.now.fullname(), am I going to kill my node.js sever's app object?
If variables are nicely sandboxed and/or given a new context when passed across, I'd love an explanation on how this is done and why it is safe.
It seems like you are just begging folks to inject node.js code into the server that does malicious things.
Firefox mac 3.5.3.
steps to reproduce
the server still receives the messages and broadcasts them but it doesn't get passed to firefox. Firefox needs to be entirely quit and started again.
I realize this is probably a problem with firefox and sockets. it's pretty flimsy though.
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket. (events.js:123:17)
at [object Object]. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:83:20)
at [object Object]._onConnect (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-polling.js:23:35)
at [object Object].check (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:77:12)
at HTTPServer. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:33:14)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:677:27)
-- Modules --
[email protected]
nowjs 0.5.1
express
jade
----- app.js ------
var util = require('util');
var express = require('express');
var app = module.exports = express.createServer();
var users = {};
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', function(req, res){
res.render('index', {
pageTitle: 'Nadir'
});
});
// Only listen on $ node app.js
if (!module.parent) {
app.listen(80);
console.log("Express server listening on port %d", app.address().port);
var nowjs = require('now');
var everyone = nowjs.initialize(app);
everyone.now.distributeMessage = function(message){
everyone.now.receiveMessage(this.now.name, message);
};
everyone.now.userConnect = function(userName){
userConnected(this, userName);
};
everyone.now.Hello = function() {
}
everyone.connected(function(){
//userConnected(this);
});
everyone.disconnected(function(){
userDisconnected(this);
});
}
function userConnected(user, userName)
{
user.now.name = userName;
users[user.user.clientId] = user;
everyone.now.receiveStatusMessage( userName + " has connected.");
sendUserList();
}
function userDisconnected(user)
{
everyone.now.receiveStatusMessage( user.now.name + " has disconnected.");
delete users[user.user.clientId];
sendUserList();
}
function sendUserList()
{
var userDetailList = {};
for(var i in users)
{
userDetailList[users[i].user.clientId] =
{
clientId: users[i].user.clientId,
Name: users[i].now.name
};
}
for(var i in users)
{
users[i].now.updateUserList(userDetailList);
}
}
Any data that is to be used on the server (and all these variables are, because otherwise they should not be in a synced magic pool) should be verified.
For example, the current implementation allows clients to set huge amounts of data to a single variable, causing memory issues on the server side.
Thus, clients should only be able to change a synced variable by calling a setter on the server side. Eg.:
now.setUserName("new name");
rather than
now.userName = "new name";
This also makes sure that the new variable can be used immediately.
The server's setUserName method will be called, in which the server can validate the data and then set the actual variable on the server side:
this.now.userName = userName;
Hi!
The following chunk of code:
// ...
now.ready(function() {
console.log('NOW READY');
var operaSucksOrXHRPollingSucksOrWhat = false;
now.getContext(id, function(response) {
if (operaSucksOrXHRPollingSucksOrWhat) return;
operaSucksOrXHRPollingSucksOrWhat = true;
console.log('GOT CONTEXT', response);
// ...
illustrates the problem I previously described in #39
now.ready
indeed is called once, but without the fuser I get two GOT CONTEXT
lines in the console, which means the callback for my custom now.getContext
is called twice. This quirk I noticed only when testing in Opera which fallbacks to xhr-polling socket.io method.
Can anyone confirm this behavior?
TIA,
--Vladimir
The documentation lacks the new clientWrite and socketio options.
Hi!
Opera/9.80 (X11; Linux i686; U; ru) Presto/2.7.62 Version/11.01
Resulting now.js, L671 -- here can be ready == null
-- this causes exception.
If I try/catch
this line, now.ready
handler is called twice.
TIA,
--Vladimir
If a client calls a remote function on the server, there is no way to interrupt this stream of data from the client to the server.
In essence, a function call acts "synchronous" because the server waits for the clients to finish sending all parameters and then executes it on the server.
This means that a client can send huge piles of data within a function to a server, causing the stream to take up way too many resources and be too time intensive.
Thus, it has to be possible to validate incoming streams and be able to kill the connection if too much data is being send.
Test case:
https://gist.github.com/918288
Description:
Run this: sudo node uploadNowTest.js -> go to http://localhost:3000 in the browser. Select a semi-large file (eg. 3MB) --> upload. When removing the now.js broadcast, this is instant (as it should be, because this is localhost with 0 latency). When broadcasting the message with now.js, it takes about 5 seconds or so.
Expected behaviour:
This behaviour is seen when the now.js broadcast is removed.
However, when not removing the now.js broadcast it takes about 5 seconds. Please run the test case.
I just published a blog article where I built a simple chat application using NowJS and JQuery Mobile. I noticed it worked fine in Chrome and Firefox but doesn't work in the Android Web Browser (emulator). I then tried the example code from the nowjs repository and that didn't work either in the Android emulator (the initial prompt never shows up). I think this is tied into how the now.js file is sent (based upon warnings from Chrome) but I'm not sure.
You can see the code I used for the chat demo here: http://www.giantflyingsaucer.com/blog/?p=2535
Chad Lung
I'm in this situation: I have an incoming stream and receive a chunk. I wish to send this chunk to all now.js clients, but need to pause the stream until all clients have received the chunk.
I can do something like this:
client:
now.receiveFileChunk = function(id, chunk, cb) {
//on success
cb();
};
and on the server:
clientsCount = //somehow get ammount of clients here (is this possible?)
receivedCount = 0;
stream.pause();
everyone.now.receiveFileChunk(id, chunk, function() {
receivedCount++;
if (receivedCount == clientsCount) stream.resume();
});
But:
I'm not 100% sure, but it might be a good idea to add a callback to remote function calls for when all clients have received this method. I'm not sure of the implications and overhead involved though...
Maybe this exists and I couldn't find it, but ...
Also, apologies. This is a feature request without any code to go with it... Lemme know if you'd prefer code...
Whenever I use a Socket.IO-esque framework, I need the server to be able to address the client directly. In NowJS, it looks as though the server can speak directly to the client only in response to a client connection.
Maybe, Google Analytics Async style, the client could pre-declare 'now' with a client_id (I've also added a roomID since it's :
var now = {clientID : 'I-am-a-string-with-the-client-id',
roomID: 'I-am-a-string-with-the-room-id' };
// NowJS initializes and uses the existing 'now' var.
Now the server can directly communicate with that client:
everyone.client('I-am-a-string-with-the-client-id').directMessage(fromUser, message);
everyone.room('I-am-a-string-with-the-room-id').partyLine(fromUser, message);
This bug may be related to Flash.
When a client is connected to the server, it will disconnect when opening a Flash based file browser / file open dialog for more than about 5 seconds. This does not happen with a HTML5 file browser, only with the flash file browser.
This bug occurs every time to me on Chrome 10.0.648.133 (77742) with Ubuntu 10.10.
Preferred behavior: now.ready immediately calls the callback if now is already ready.
A very common scenario is where you'd want to broadcast to all clients in a group except for the client that sent the initial message.
For example, in a chat application, when a user sends a message he does not need to know from the server that he actually sent this message. Thus, the client can add this message locally. However, the server does have to send this message to all clients except for the originating client. This is just an example.
It would make no sense to copy all clients to a new group except for that originating client, thus I propose the following exclude style:
everyone.now.exclude([clientId1, clientId2]).someMethod
which would work exactly the same as:
everyone.now.someMethod
with the exception that clientId1 and clientId2 are excluded.
Thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.