Restructure shim/bridge initialization steps

This commit is contained in:
hensm
2019-02-10 06:31:31 +00:00
parent a1101d6cf6
commit 1c55b67922
8 changed files with 181 additions and 139 deletions

View File

@@ -44,7 +44,7 @@ export default class Session {
this.status = SessionStatus.CONNECTED;
this.statusText = null;
if (receiver) {
if (receiver) {
this._sendMessage("bridge:bridgesession/initialize", {
address: receiver._address
, port: receiver._port

View File

@@ -91,7 +91,7 @@ cast.initialize = (
state.apiConfig = apiConfig;
sendMessage({
subject: "bridge:discover"
subject: "discover"
});
apiConfig.receiverListener(state.receiverList.length
@@ -146,7 +146,7 @@ cast.requestSession = (
// Open destination chooser
sendMessage({
subject: "main:openPopup"
subject: "openPopup"
});
};
@@ -175,11 +175,9 @@ onMessage(message => {
* Cast destination found (serviceUp). Set the API availability
* property and call the page event function (__onGCastApiAvailable).
*/
case "shim:serviceUp": {
case "serviceUp": {
const receiver = message.data;
console.log(receiver);
if (state.receiverList.find(r => r.id === receiver.id)) {
break;
}
@@ -196,7 +194,7 @@ onMessage(message => {
* Cast destination lost (serviceDown). Remove from the receiver list
* and update availability state.
*/
case "shim:serviceDown": {
case "serviceDown": {
state.receiverList = state.receiverList.filter(
receiver => receiver.id !== message.data.id);
@@ -208,7 +206,7 @@ onMessage(message => {
break;
};
case "shim:selectReceiver": {
case "selectReceiver": {
console.info("Caster (Debug): Selected receiver");
const selectedReceiver = new Receiver(
@@ -226,7 +224,8 @@ onMessage(message => {
, selectedReceiver // receiver
, (session) => {
sendMessage({
subject: "popup:close"
subject: "close"
, destination: "popup"
});
state.apiConfig.sessionListener(session);
@@ -258,9 +257,10 @@ onMessage(message => {
* Popup is ready to receive data to populate the cast destination
* chooser.
*/
case "shim:popupReady": {
case "popupReady": {
sendMessage({
subject: "popup:populate"
subject: "populateReceiverList"
, destination: "popup"
, data: {
receivers: state.receiverList
, selectedMedia: state.apiConfig._selectedMedia
@@ -273,7 +273,7 @@ onMessage(message => {
/**
* Popup closed before session established.
*/
case "shim:popupClosed": {
case "popupClosed": {
if (state.sessionRequestInProgress) {
state.sessionRequestInProgress = false;
sessionErrorCallback(new Error_(ErrorCode.CANCEL));

View File

@@ -16,7 +16,7 @@ window.chrome.cast.media = media;
onMessage(message => {
switch (message.subject) {
case "shim:initialized": {
case "shimInitialized": {
const bridgeInfo = message.data;
// Call page's API loaded function if defined
@@ -28,8 +28,3 @@ onMessage(message => {
};
}
});
// Trigger bridge mDNS discovery
sendMessage({
subject: "main:initialize"
});