One sender disconnecting causes all senders to disconnect - google-cast

I am experimenting with a modified version of the Cast-HelloText sample app, specifically having two senders connect to the app at the same time.
The castReceiverManager.onSenderConnected() callback is called, and I see I have 2 senders connected (using window.castReceiverManager.getSenders().length) and both can then send messages.
However, when either one disconnects the app is terminated. I have tried logging the number of senders connected in the castReceiverManager.onSenderDisconnected() callback (without success) and I have commented out the window.close() call.
It appears the app is closed (chromecast returns to home screen) on any sender disconnecting.
Any ideas on how to have an app with more than one sender that isn't ended when any sender disconnects?

Check on your sender to see what it does when a disconnect happens. The unmodified version on Github calls Cast.CastApi.stopApplication(mApiClient) when you disconnect your sender from the receiver and that call stops the app on the receiver. If you don't want that to happen, you should not call that method but then you need to make sure
it makes sense for your app to continue
make sure your receiver handles things correctly

Related

socket.io-redis not forwarding messages to sockets on a namespace

I have a solution where an application is emitting messages using socket.io-emitter and a socket server is handling the messages.
The socket server receives messages from the client browser without an issue however it does not pickup any messages from the other application which are sent over the redis adapter.
I've debugged the redis adapter and can see that the messages are being received and I can also see that they are associated with the correct namespace. They just appear to not be firing the socket.on() event
The server code has more going on however basically boils down to the following
io.adapter(redisIO({host: redisHost, port: redisPort}));
io.of('/mynamespace').on('connection',
function(socket) {
// This message never gets fired
socket.on('other-server-message',dosomething);
// This message works fine
socket.on('message-from-browser-client',dosomethingelse);
}
);
There isn't much documentation around so any help would be great
I eventually realised what the issue was. I was misunderstanding what the socket.io-emitter was doing.
I was sending a message from the emitter and then trying to capture it on the server and then push it out to the clients. The emitter is actually broadcasting directly to the clients in the web browser as if it was just another server socket (which is what I wanted).
Soon as i updated the client code to check for the message it worked perfectly

Cannot unsubscribe with PubNub

Im using PubNub, Phonegap, Backbone.js and Require.js to build twiiter-style chat rooms. Currently I'm testing on a desktop with chrome.
I have a Chat.js view and in the initialize() function, I subscribe to the channel with:
that.pubnub.subscribe({
channel: chatChannel,
message: that.handleSingleMessage,
});
This works fine and I can see with Chrome inspector that ajax requests are sent off. At the top of the app there is a "back" button. In here I call unsubscribe to unsubscribe the user:
that.pubnub.unsubscribe({
channel: chatChannel
});
However, I still see with Chrome inspector that ajax requests to PubNub are still being sent off, even though the user should be unsubscribed and is on a different part of the app. 2 ajax requests are repeatedly sent. They look like:
http://ps13.pubnub.com/time/0?uuid=tomsmith&auth=&pnsdk=PubNub%2DTS%2DWeb%2F3%2Y5%2E1
and
http://ps11.pubnub.com/time/0?uuid=4ea9bd1c%2D7652%2D410c%2Da2ba%2D17c5d263085d&auth=&pnsdk=PubNub%2DTS%2DWeb%2F3%2Y5%2E1
Any idea what's going on?
http://ps13.pubnub.com/time/0?uuid=tomsmith&auth=&pnsdk=PubNub%2DTS%2DWeb%2F3%2Y5%2E1
Are just 'time' calls. They are used to monitor the online/offline status of the client, and do not mean that you are still subscribed. Think of them just as "PubNub Pings"
If you still saw a URL with 'subscribe' in it, then that would mean you are still subscribed, for example:
http://ps2.pubnub.com/subscribe/demo/demoapp1%2Cdemoapp1-pnpres/0/13825545216910725?uuid=2f62d1c1-69c8-423c-9492-74e29f46a877&pnsdk=PubNub-JS-Web%2F3.5.47
but it looks like from your example, its just performing heartbeat logic here, after you've un-subbed.
geremy
Make sure that you're not re-subscribing to the same channel after you unsubscribe to it. PubNub automatically tries to re-connect to a channel if it looses the connection. You can see how I switch and unsubscribe to channels here: http://plnkr.co/edit/7JyS4H

Does sockets.io emit sometimes fail?

I have a web based multiplayer game. It happens from time to time that someone is kicked out because server did not get expected message from client. It seems from my logs that client did not disconnect, just did not send message or server did not receive it. My question here is "Does this things happen normally from time to time?" Should i use some kind of callback mechanism to ensure message is delivered and if not send it again or is there some issue that i am not aware?
socket.io already provides ACKs and message ID tracking, on top of TCP.
Also, socket.io uses pings to check the connection. So, if you say that the client is not disconnected, and the server tells that the client is not disconnected, then the connection is still there.
The problem must be situated elsewhere.
Are you sure there is not a bug in either part of the implementation? Showing some code snippets could help, as well as the environment you are using.

How do I completely destroy a socket.io connection?

I'm creating a browser chat from Socket.io and Node.js. Everything has been running smoothly, but I appear to be having a problem with disconnecting sockets. When I run socket.disconnet();, the server runs the socket.on("disconnect", event, but it doesn't actually remove the socket from internal listeners.
When I run socket.disconnect(); on a socket, the socket no longer recieves any new messages, but when the "disconnected" user sends a message, the server receives and sends it back to all clients. I want to create a proper /kick command but it's difficult when I have to restructure all of my code just to accomidate for a simple function.
Commands like socket.connection.destroy();, socket.end();, and socket.transport.destroy(); are invalid and undefined. Does anyone have any suggestions? I've been working on this problem for days and I haven't found any answer other than to set a shutup boolean to the socket and tell the message event to ignore specific sockets. Is this the best way? What happens if the user starts editing javascript code and I need a way from receiving other events from a client?
Well you can see if the socket is connected or not. If socket is connected you can emit the data and vice versa. :)
Hope it helps..!
YourProject.sockets.on('connection',function(socket){
setInterval(function(){
if(!socket.disconnected){
socket.emit('entrance',{message:'Hey Bro'});
}
},10000);
});
have you tried to interrupt thread ? That should end all I/O operations with an Exception.

Pusher disconnect & timeout

will my server be notified about disconnect on the client side?
I assume the answer is yes if the disconnect happens explictly like below.
pusher.disconnect()
however what happens if the user simply closes the browser?
Another thing is there a way to notify the server that a certain channel has not been in use by the client(s) for some while?
The connection states documentation shows how to bind to connection state changes.
however what happens if the user simply closes the browser?
This really depends on if the browser calls webSocketInstance.onclose so the Pusher JavaScript library is informed before the browser is closed. You could always detect this yourself using window.onbeforeunload, window.onunload or the addEventListener versions.
Another thing is there a way to notify the server that a certain channel has not been in use by the client(s) for some while?
You can use WebHooks so that when a channel becomes vacated your app server will be informed.

Resources