@ -9,6 +9,7 @@ import {
CONNECTION _DISCONNECTED ,
CONNECTION _ESTABLISHED ,
CONNECTION _FAILED ,
CONNECTION _WILL _CONNECT ,
SET _LOCATION _URL
} from './actionTypes' ;
@ -49,6 +50,8 @@ export function connect() {
jwt && issuer && issuer !== 'anonymous' ? jwt : undefined ,
options ) ;
dispatch ( _connectionWillConnect ( connection ) ) ;
connection . addEventListener (
JitsiConnectionEvents . CONNECTION _DISCONNECTED ,
_onConnectionDisconnected ) ;
@ -138,6 +141,23 @@ function _connectionDisconnected(connection: Object, message: string) {
} ;
}
/ * *
* Create an action for when a connection will connect .
*
* @ param { JitsiConnection } connection - The JitsiConnection which will connect .
* @ private
* @ returns { {
* type : CONNECTION _WILL _CONNECT ,
* connection : JitsiConnection
* } }
* /
function _connectionWillConnect ( connection ) {
return {
type : CONNECTION _WILL _CONNECT ,
connection
} ;
}
/ * *
* Create an action for when the signaling connection has been established .
*
@ -190,27 +210,35 @@ export function connectionFailed(
export function disconnect ( ) {
return ( dispatch : Dispatch < * > , getState : Function ) => {
const state = getState ( ) ;
const { conference } = state [ 'features/base/conference' ] ;
const { connection } = state [ 'features/base/connection' ] ;
const { conference , joining } = state [ 'features/base/conference' ] ;
const { connection , connecting } = state [ 'features/base/connection' ] ;
// The conference we are joining or have already joined.
const _conference = joining || conference ;
// The connection we are connecting or have already connected.
const _connection = connecting || connection ;
// Promise which completes when the conference has been left and the
// connection has been disconnected.
let promise ;
// Leave the conference.
if ( conference ) {
if ( _ conference) {
// In a fashion similar to JitsiConference's CONFERENCE_LEFT event
// (and the respective Redux action) which is fired after the
// conference has been left, notify the application about the
// intention to leave the conference.
dispatch ( conferenceWillLeave ( conference ) ) ;
dispatch ( conferenceWillLeave ( _ conference) ) ;
promise = conference . leave ( ) ;
promise = _ conference. leave ( ) ;
} else {
promise = Promise . resolve ( ) ;
}
// Disconnect the connection.
if ( connection ) {
promise = promise . then ( ( ) => connection . disconnect ( ) ) ;
if ( _ connection) {
promise = promise . then ( ( ) => _ connection. disconnect ( ) ) ;
}
return promise ;