Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Chrome Packaged Apps. Unload event is not supported #163

Closed
lylepratt opened this issue Mar 25, 2015 · 7 comments
Closed

Issue with Chrome Packaged Apps. Unload event is not supported #163

lylepratt opened this issue Mar 25, 2015 · 7 comments
Assignees

Comments

@lylepratt
Copy link

We're having trouble using SIP.js in a Chrome Packaged App. In Chrome Apps the unload event is not supported, and using it results in this error:
unload is not available in packaged apps.

I think this is the offending code in SIP.js:

  // Initialize registerContext
  this.registerContext = new SIP.RegisterContext(this);
  this.registerContext.on('failed', selfEmit('registrationFailed'));
  this.registerContext.on('registered', selfEmit('registered'));
  this.registerContext.on('unregistered', selfEmit('unregistered'));

  if(this.configuration.autostart) {
    this.start();
  }

  if (typeof global.addEventListener === 'function') {
    global.addEventListener('unload', this.stop.bind(this));
  }

Any Tips?

@josephfrazier josephfrazier self-assigned this Mar 25, 2015
@josephfrazier
Copy link
Contributor

Hey Lyle, it's nice to see SIP.js used in this context! We added that 'unload' listener so that navigating away from the page would cause SIP.js to automatically hang up any outstanding calls, instead of leaving the other end hanging.

I looked into this briefly, and it seems like attempting to add the listener in a Chrome App doesn't actually break anything, it just prints an error message (see also sockjs/sockjs-client#223). Nevertheless, it'd be nice if this didn't happen, so if you know a way for SIP.js to detect when it's being used in a Chrome App and then refrain from adding the listener, I think we'd be happy to take a Pull Request for it.

@caruizdiaz
Copy link
Contributor

Hi Joseph,

On Wed, Mar 25, 2015 at 9:18 AM, Joseph Frazier notifications@github.com
wrote:

Hey Lyle, it's nice to see SIP.js used in this context! We added that
'unload' listener so that navigating away from the page would cause SIP.js
to automatically hang up any outstanding calls, instead of leaving the
other end hanging.

Where is that function documented? Since when does it exist?

I looked into this briefly, and it seems like attempting to add the
listener in a Chrome App doesn't actually break anything, it just prints an
error message (see also sockjs/sockjs-client#223
sockjs/sockjs-client#223). Nevertheless, it'd
be nice if this didn't happen, so if you know a way for SIP.js to detect
when it's being used in a Chrome App and then refrain from adding the
listener, I think we'd be happy to take a Pull Request for it.


Reply to this email directly or view it on GitHub
#163 (comment).

Carlos
http://caruizdiaz.com

@josephfrazier
Copy link
Contributor

Where is that function documented?

I don't believe it's currently documented, unfortunately.

Since when does it exist?

According to git log -S"'unload'", it was introduced in 13667d5, which was then cherry-picked into versions 0.6.3 and 0.6.4

@lylepratt
Copy link
Author

Yep. Everything seems to be working even though the error is thrown.

You can detect if something is running as a Chrome app using this:

if(chrome && chrome.app && chrome.app.runtime) {
    return true;
}

@wakamoleguy
Copy link
Contributor

Out of curiosity, what happens if you try define unload as a custom event in your Chrome app?

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

@lylepratt
Copy link
Author

Seems to work if I declare it in debug console and manually dispatch.

@josephfrazier
Copy link
Contributor

Hmm, I can create and dispatch the event, but adding the event listener still doesn't work:

var event = new Event('unload');

// Listen for the event.
window.addEventListener('unload', console.log.bind(console, 'UNLOADED'), false);

// Dispatch the event.
window.dispatchEvent(event);
unload is not available in packaged apps.         extensions::platformApp:17
true

EDIT: I'm running this in the console of the sample Hello World app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants