Opentok Javascript: On self session/connection disconnect? - opentok

Opentok Javascript: On self session/connection disconnect?
I tried all the possible events, following code logs into the console when other deivces disconnects, but it never logs anything when it, itself, disconnects. Please point toward the even which is fired when the session is disconnected. I have tried sessionDisconnect as well without any luck.
this.session.on("connectionDestroyed", function(event) {
console.log(event);
});
Thanks in advance.

TokBox Developer Evangelist here.
The Session object dispatches SessionDisconnectEvent object when a session has disconnected. You mentioned that you tried, sessionDisconnect, but the event is actually sessionDisconnected.
You can listen to the event as such:
this.session.on("sessionDisconnected", function(event) {
console.log(event);
});
The connectionDestroyed event is dispatched when other connections leave the session.

Related

Make requests on chromecast receiver shutdown event

I'm developing a chromecast custom receiver, and I need to send a request to the server once the sender disconnects from receiver. When I use ios or android senders, I can see that the 'sender disconnect' event is triggered, but when I use the browser, that event is not triggered.
Because of that, I'm trying to use the 'shutdown' event, to send that request, once the sender is disconnected.
I tried to pass an 'async/await' function as callback to the shutdown event, and tried to force an 'await' on the request, but I get the ' Application should not send requests before the system is ready (they will be ignored)'
I also tried to use the window 'beforeunload' event, but with no success.
Is there any way to send a request, once the 'shutdown' event is triggered?
Cheers
For us the Dispatching Shutdown event occurred in both cases. Web and Mobile senders. So I'm not sure what's happening on your end but will definitely need more information regarding what you're doing in order to look further into it.
Anyhow, if you are setting addEventListeners on your end like this:
context.addEventListener(cast.framework.system.ShutdownEvent,
()=>{
console.log("ShutdownEvent Called");
});
context.addEventListener(cast.framework.system.SenderDisconnectedEvent,
()=>{
console.log("SenderDisconnectedEvent called");
});
Which will result in your calls not firing. You should instead be doing:
context.addEventListener(cast.framework.system.EventType.SHUTDOWN,
()=>{
console.log("ShutdownEvent Called");
});
context.addEventListener(cast.framework.system.EventType.SENDER_DISCONNECTED,
()=>{ console.log("SenderDisconnectedEvent called"); });
Here's the docs for their reference: https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.system#.EventType

How to configure my sails app with https socket connection?

I have a sails backend API. And I already have an https connection.
(https://myapp.com/api)
How do I connect to a sails socket with my client side (Android and iOS) having an https connection? I dont have any problem connecting to a non HTTPS server. Hope there is a help.
all you have to do is open config/bootstrap.js, and made following changes there
module.exports.bootstrap = function(cb) {
// handle connect socket first event executes after logged in
sails.io.on('connect', function (socket){
socket.emit("connected",{ data: "here am i!" })
});
// handle custom listener for other stuff
sails.io.on('ping', function (socket){
socket.emit("pong",{ data: "send to android/ios/web client" })
});
cb();
};
here you can listen for multiple events as well as you can emit multiple private/broadcast messages as well and also all socket.io listeners will work here

SocketIO - Does a browser refresh cause "on disconnect" to fire?

I'm using SocketIO and I need to disconnect a socket on the server side if the user presses refresh. I've tried implementing this like so:
io.on('disconnect', function(socket) {
socket.close();
})
But the disconnect event isn't firing. Is this intended behaviour and if so is there any way to disconnect a socket when a page is refreshed?
Yes, when implemented properly a browser refresh causes a disconnect event on the server. I just confirmed this with a simple test app.
The disconnect event is a socket event, not an io event. So, you need to register for it on the socket, not at the io level.
This is my event handler that works just fine on my test server:
io.on('connection', function(socket) {
socket.on('disconnect', function() {
console.log("disconnect: ", socket.id);
});
});
FYI, you do not need to close the socket yourself. That will happen automatically as all webSocket/socket.io connections are automatically closed whenever a page is refreshed or navigated away from.

Detecting client disconnect with PushStreamContent in Web API

Although HTTP is a stateless protocol, there's this PushStreamContent class that facilitates server-sent events, as you can read here. A Web API implementation may store client streams and periodically send push updates. However, it's a bit of a problem to detect when the client disconnects.
In this discussion, Henrik Nielsen states that:
Detecting that the TCP connection has been reset is something that the Host (ASP, WCF, etc.) monitors but in .NET 4 neither ASP nor WCF tells us (the Web API layer) about it. This means that the only reliable manner to detect a broken connection is to actually write data to it. This is why we have the try/catch around the write operation in the sample. That is, responses will get cleaned up when they fail and not before.
In .NET 4.5 there is a mechanism for detecting client disconnect but I haven't tried it out.
Fast forward two and a half years to today. Does anyone have any idea what this mechanism is, and whether it works?
An interesting response was post on this link : link to the article
this is a part of the answer
In .NET 4.5 there is a mechanism for detecting client disconnect but I haven't tried it out.
This (simplified) code works for me:
public HttpResponseMessage Get(HttpRequestMessage request)
{
// Register for client disconnect notifications
object clientId = ...; // this is the object passed to the callback
System.Web.HttpContext.Current.Response.ClientDisconnectedToken.Register(
delegate (object obj)
{
// Client has cleanly disconnected
// obj is the clientId passed in to the register
// handle client disconnection
//...
}
, clientId );
// Normal code from the sample continues
response.Content = new PushStreamContent(...);
}
The ClientDisconnect callback is called back if e.g. you close the client browser page cleanly, but if you pull the network cable out, it does not get notified. So for this unclean disconnection, we still need some other way of detecting this, such as monitoring failures during the timer callback.

DevExpress Aspxcallbackpanel Client Side Timeout?

I've read plenty about how to handle Server-Side timeouts & errors during a Callback...
but what about Client Side timeouts?
here's the example.
Guy fills out a web form. Hits submit & the ASPXCallbackPanel does a PerformCallback.
But right then... his internet drops or his router burps.
In my app, the Callback panel never returns control back to the Webpage.. and the callback never completes.
Anybody know a Timeout settings on the Client side? or a way to abort a callback through Javascript?
thanks
If I were you, I would start a timer everytime a callback is sent to the server and refresh the page when the timer ticks. If the callback returns earlier, the timer should be stopped. This can be easily done using the ASPxGlobalEvents control.

Resources