const createSession = options => new Promise((resolve, reject) => { const setActiveSession = (session) => { activeSession = session; return Promise.resolve(session); }; options = (typeof options === 'undefined') ? defaultSessionOptions : options; OT.createSessionAsync(options) .then(setActiveSession) .then(resolve) .catch(reject); })