feat(watchos): emit app context
(cherry picked from commit 6ad851b)
This commit is contained in:
parent
0ef4be6e9e
commit
ea4cd420fa
|
@ -70,4 +70,27 @@ class ExtensionDelegate: NSObject, WCSessionDelegate, WKExtensionDelegate {
|
||||||
print("WC Session activated with state: \(activationState.rawValue)")
|
print("WC Session activated with state: \(activationState.rawValue)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
|
||||||
|
|
||||||
|
print("WC SESSION DID RECEIVE APP CONTEXT");
|
||||||
|
|
||||||
|
let conferenceURL = applicationContext["conferenceURL"] as? NSString ?? "NULL";
|
||||||
|
print("CONFERENCE URL \(conferenceURL)");
|
||||||
|
|
||||||
|
let micMuted = applicationContext["micMuted"] as? NSNumber ?? -1;
|
||||||
|
print("MIC MUTED \(micMuted)");
|
||||||
|
|
||||||
|
let recentURLs = applicationContext["recentURLs"];
|
||||||
|
if let recentURLsArray = recentURLs as? NSArray {
|
||||||
|
for entry in recentURLsArray {
|
||||||
|
// FIXME possible runtime exception
|
||||||
|
let entryDict = entry as! NSDictionary;
|
||||||
|
let roomURL = entryDict["roomURL"] as? NSString ?? "NULL";
|
||||||
|
let timestamp = entryDict["timestamp"] as? NSNumber ?? -1;
|
||||||
|
print("roomURL: \(roomURL) ts: \(timestamp)");
|
||||||
|
//print("entry \(type(of: entry)) \(type(of: roomURL)) \(type(of: timestamp))");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* type: ADD_RECENT_URL,
|
||||||
|
* recentURLs: Array
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
export const SET_RECENT_URLS = Symbol('SET_RECENT_URLS');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* type: SET_MIC_MUTED,
|
||||||
|
* micMuted: boolean
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
export const SET_MIC_MUTED = Symbol('SET_MIC_MUTED');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* type: SET_CONFERENCE_URL,
|
||||||
|
* conferenceURL: String?
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
export const SET_CONFERENCE_URL = Symbol('SET_CONFERENCE_URL');
|
|
@ -1 +1,2 @@
|
||||||
import './middleware';
|
import './middleware';
|
||||||
|
import './reducer';
|
||||||
|
|
|
@ -3,16 +3,30 @@
|
||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import * as watch from 'react-native-watch-connectivity';
|
import * as watch from 'react-native-watch-connectivity';
|
||||||
|
|
||||||
|
import {
|
||||||
|
SET_CONFERENCE_URL,
|
||||||
|
SET_MIC_MUTED,
|
||||||
|
SET_RECENT_URLS
|
||||||
|
} from './actionTypes';
|
||||||
|
import { ADD_RECENT_URL, LOADED_RECENT_URLS } from '../../recent';
|
||||||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT, appNavigate } from '../../app';
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT, appNavigate } from '../../app';
|
||||||
import {
|
import {
|
||||||
CONFERENCE_FAILED,
|
CONFERENCE_FAILED,
|
||||||
CONFERENCE_LEFT,
|
CONFERENCE_JOINED,
|
||||||
CONFERENCE_WILL_JOIN
|
CONFERENCE_LEFT
|
||||||
} from '../../base/conference';
|
} from '../../base/conference';
|
||||||
import {
|
import {
|
||||||
|
MEDIA_TYPE as MediaType,
|
||||||
toggleAudioMuted
|
toggleAudioMuted
|
||||||
} from '../../base/media';
|
} from '../../base/media';
|
||||||
import { MiddlewareRegistry } from '../../base/redux';
|
import { MiddlewareRegistry } from '../../base/redux';
|
||||||
|
import { getInviteURL } from '../../base/connection/functions';
|
||||||
|
import {
|
||||||
|
isLocalTrackMuted,
|
||||||
|
TRACK_ADDED,
|
||||||
|
TRACK_REMOVED,
|
||||||
|
TRACK_UPDATED
|
||||||
|
} from '../../base/tracks';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,6 +49,11 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
||||||
watch.subscribeToWatchState((err, watchState) => {
|
watch.subscribeToWatchState((err, watchState) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
console.log('watchState', watchState);
|
console.log('watchState', watchState);
|
||||||
|
|
||||||
|
// FIXME that does not seem to help with the initial sync up
|
||||||
|
// if (watchState === 'Activated') {
|
||||||
|
// _updateApplicationContext(getState);
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
console.log('ERROR getting watchState');
|
console.log('ERROR getting watchState');
|
||||||
}
|
}
|
||||||
|
@ -60,14 +79,61 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case APP_WILL_UNMOUNT:
|
case ADD_RECENT_URL:
|
||||||
|
case LOADED_RECENT_URLS: {
|
||||||
|
dispatch({
|
||||||
|
type: SET_RECENT_URLS,
|
||||||
|
recentURLs: getState()['features/recent'].entries
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case TRACK_ADDED:
|
||||||
|
case TRACK_REMOVED:
|
||||||
|
case TRACK_UPDATED: {
|
||||||
|
// FIXME Note sure how this will be accurate before the tracks are
|
||||||
|
// created. If no tracks I guess we should use /base/media state.
|
||||||
|
const tracks = getState()['features/base/tracks'];
|
||||||
|
const micMuted = isLocalTrackMuted(tracks, MediaType.AUDIO);
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: SET_MIC_MUTED,
|
||||||
|
micMuted
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CONFERENCE_JOINED:
|
||||||
case CONFERENCE_FAILED:
|
case CONFERENCE_FAILED:
|
||||||
case CONFERENCE_LEFT:
|
case CONFERENCE_LEFT: {
|
||||||
|
const { conference } = getState()['features/base/conference'];
|
||||||
|
|
||||||
|
// NOTE for some reason 'null' does not update context - must be string
|
||||||
|
const conferenceURL = conference ? getInviteURL(getState) : 'NULL';
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: SET_CONFERENCE_URL,
|
||||||
|
conferenceURL
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case CONFERENCE_WILL_JOIN:
|
}
|
||||||
|
|
||||||
|
// Here list all actions that affect the watch OS application context.
|
||||||
|
// The reducer should form all those actions into our context structure.
|
||||||
|
case SET_CONFERENCE_URL:
|
||||||
|
case SET_MIC_MUTED:
|
||||||
|
case SET_RECENT_URLS: {
|
||||||
|
_updateApplicationContext(getState);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case APP_WILL_UNMOUNT:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function _updateApplicationContext(getState) {
|
||||||
|
const context = getState()['features/mobile/watchos'];
|
||||||
|
|
||||||
|
console.info('UPDATING WATCH CONTEXT', context);
|
||||||
|
watch.updateApplicationContext(context);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { ReducerRegistry, set } from '../../base/redux';
|
||||||
|
import {
|
||||||
|
SET_CONFERENCE_URL, SET_MIC_MUTED,
|
||||||
|
SET_RECENT_URLS
|
||||||
|
} from './actionTypes';
|
||||||
|
|
||||||
|
const INITIAL_STATE = {
|
||||||
|
// NOTE for some reason 'null' does not update context
|
||||||
|
conferenceURL: 'NULL',
|
||||||
|
micMuted: false,
|
||||||
|
recentURLs: []
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reduces the Redux actions of the feature features/recording.
|
||||||
|
*/
|
||||||
|
ReducerRegistry.register(
|
||||||
|
'features/mobile/watchos', (state = INITIAL_STATE, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case SET_CONFERENCE_URL: {
|
||||||
|
return set(state, 'conferenceURL', action.conferenceURL);
|
||||||
|
}
|
||||||
|
case SET_MIC_MUTED: {
|
||||||
|
return set(state, 'micMuted', action.micMuted);
|
||||||
|
}
|
||||||
|
case SET_RECENT_URLS: {
|
||||||
|
return set(state, 'recentURLs', action.recentURLs);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
});
|
|
@ -20,6 +20,7 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case LIB_LOAD_STORAGE_DONE: {
|
case LIB_LOAD_STORAGE_DONE: {
|
||||||
|
// FIXME this appears to be called when a conference is left
|
||||||
let entries = [];
|
let entries = [];
|
||||||
const recentURLs = window.localStorage.getItem('recentURLs');
|
const recentURLs = window.localStorage.getItem('recentURLs');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue