mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Change message subject format and rename some messages
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
export default class Media {
|
export default class Media {
|
||||||
messageHandler (message) {
|
messageHandler (message) {
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "bridge:bridgemedia/sendMediaMessage": {
|
case "bridge:/media/sendMediaMessage": {
|
||||||
let error = false;
|
let error = false;
|
||||||
try {
|
try {
|
||||||
this.channel.send(message.data.message);
|
this.channel.send(message.data.message);
|
||||||
@@ -9,7 +9,7 @@ export default class Media {
|
|||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendMessage("shim:media/sendMediaMessageResponse", {
|
this.sendMessage("shim:/media/sendMediaMessageResponse", {
|
||||||
messageId: message.data.messageId
|
messageId: message.data.messageId
|
||||||
, error
|
, error
|
||||||
});
|
});
|
||||||
@@ -62,7 +62,7 @@ export default class Media {
|
|||||||
messageData.mediaSessionId = status.mediaSessionId;
|
messageData.mediaSessionId = status.mediaSessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendMessage("shim:media/update", messageData);
|
this.sendMessage("shim:/media/update", messageData);
|
||||||
|
|
||||||
// Update ID
|
// Update ID
|
||||||
if (status.mediaSessionId) {
|
if (status.mediaSessionId) {
|
||||||
|
|||||||
@@ -3,34 +3,34 @@ import { Client } from "castv2";
|
|||||||
export default class Session {
|
export default class Session {
|
||||||
messageHandler (message) {
|
messageHandler (message) {
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "bridge:bridgesession/close":
|
case "bridge:/session/close":
|
||||||
this.close();
|
this.close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bridge:bridgesession/impl_addMessageListener":
|
case "bridge:/session/impl_addMessageListener":
|
||||||
this._impl_addMessageListener(message.data.namespace);
|
this._impl_addMessageListener(message.data.namespace);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bridge:bridgesession/impl_sendMessage":
|
case "bridge:/session/impl_sendMessage":
|
||||||
this._impl_sendMessage(
|
this._impl_sendMessage(
|
||||||
message.data.namespace
|
message.data.namespace
|
||||||
, message.data.message
|
, message.data.message
|
||||||
, message.data.messageId)
|
, message.data.messageId)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bridge:bridgesession/impl_setReceiverMuted":
|
case "bridge:/session/impl_setReceiverMuted":
|
||||||
this._impl_setReceiverMuted(
|
this._impl_setReceiverMuted(
|
||||||
message.data.muted
|
message.data.muted
|
||||||
, message.data.volumeId);
|
, message.data.volumeId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bridge:bridgesession/impl_setReceiverVolumeLevel":
|
case "bridge:/session/impl_setReceiverVolumeLevel":
|
||||||
this._impl_setReceiverVolumeLevel(
|
this._impl_setReceiverVolumeLevel(
|
||||||
message.data.newLevel
|
message.data.newLevel
|
||||||
, message.data.volumeId);
|
, message.data.volumeId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bridge:bridgesession/impl_stop":
|
case "bridge:/session/impl_stop":
|
||||||
this._impl_stop(message.data.stopId);
|
this._impl_stop(message.data.stopId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ export default class Session {
|
|||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "RECEIVER_STATUS":
|
case "RECEIVER_STATUS":
|
||||||
|
|
||||||
this.sendMessage("shim:session/updateStatus", data.status);
|
this.sendMessage("shim:/session/updateStatus", data.status);
|
||||||
|
|
||||||
if (!data.status.applications) return;
|
if (!data.status.applications) return;
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ export default class Session {
|
|||||||
|
|
||||||
if (receiverAppId !== appId) {
|
if (receiverAppId !== appId) {
|
||||||
// Close session
|
// Close session
|
||||||
this.sendMessage("shim:session/stopped");
|
this.sendMessage("shim:/session/stopped");
|
||||||
this.client.close();
|
this.client.close();
|
||||||
clearInterval(this.clientHeartbeatInterval);
|
clearInterval(this.clientHeartbeatInterval);
|
||||||
return;
|
return;
|
||||||
@@ -129,7 +129,7 @@ export default class Session {
|
|||||||
|
|
||||||
this.sessionId = this.app.sessionId;
|
this.sessionId = this.app.sessionId;
|
||||||
|
|
||||||
this.sendMessage("shim:session/connected", {
|
this.sendMessage("shim:/session/connected", {
|
||||||
sessionId: this.app.sessionId
|
sessionId: this.app.sessionId
|
||||||
, namespaces: this.app.namespaces
|
, namespaces: this.app.namespaces
|
||||||
, displayName: this.app.displayName
|
, displayName: this.app.displayName
|
||||||
@@ -170,7 +170,7 @@ export default class Session {
|
|||||||
_impl_addMessageListener (namespace) {
|
_impl_addMessageListener (namespace) {
|
||||||
this.createChannel(namespace);
|
this.createChannel(namespace);
|
||||||
this.channelMap.get(namespace).on("message", data => {
|
this.channelMap.get(namespace).on("message", data => {
|
||||||
this.sendMessage("shim:session/impl_addMessageListener", {
|
this.sendMessage("shim:/session/impl_addMessageListener", {
|
||||||
namespace: namespace
|
namespace: namespace
|
||||||
, data: JSON.stringify(data)
|
, data: JSON.stringify(data)
|
||||||
});
|
});
|
||||||
@@ -187,7 +187,7 @@ export default class Session {
|
|||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendMessage("shim:session/impl_sendMessage", {
|
this.sendMessage("shim:/session/impl_sendMessage", {
|
||||||
messageId
|
messageId
|
||||||
, error
|
, error
|
||||||
});
|
});
|
||||||
@@ -206,7 +206,7 @@ export default class Session {
|
|||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendMessage("shim:session/impl_setReceiverMuted", {
|
this.sendMessage("shim:/session/impl_setReceiverMuted", {
|
||||||
volumeId
|
volumeId
|
||||||
, error
|
, error
|
||||||
});
|
});
|
||||||
@@ -225,7 +225,7 @@ export default class Session {
|
|||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendMessage("shim:session/impl_setReceiverVolumeLevel", {
|
this.sendMessage("shim:/session/impl_setReceiverVolumeLevel", {
|
||||||
volumeId
|
volumeId
|
||||||
, error
|
, error
|
||||||
});
|
});
|
||||||
@@ -247,7 +247,7 @@ export default class Session {
|
|||||||
this.client.close();
|
this.client.close();
|
||||||
clearInterval(this.clientHeartbeatInterval);
|
clearInterval(this.clientHeartbeatInterval);
|
||||||
|
|
||||||
this.sendMessage("shim:session/impl_stop", {
|
this.sendMessage("shim:/session/impl_stop", {
|
||||||
stopId
|
stopId
|
||||||
, error
|
, error
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const existingMedia = new Map();
|
|||||||
* for managing existing ones.
|
* for managing existing ones.
|
||||||
*/
|
*/
|
||||||
async function handleMessage (message) {
|
async function handleMessage (message) {
|
||||||
if (message.subject.startsWith("bridge:bridgemedia/")) {
|
if (message.subject.startsWith("bridge:/media/")) {
|
||||||
if (existingMedia.has(message._id)) {
|
if (existingMedia.has(message._id)) {
|
||||||
// Forward message to instance message handler
|
// Forward message to instance message handler
|
||||||
existingMedia.get(message._id).messageHandler(message);
|
existingMedia.get(message._id).messageHandler(message);
|
||||||
@@ -77,7 +77,7 @@ async function handleMessage (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.subject.startsWith("bridge:bridgesession/")) {
|
if (message.subject.startsWith("bridge:/session/")) {
|
||||||
if (existingSessions.has(message._id)) {
|
if (existingSessions.has(message._id)) {
|
||||||
// Forward message to instance message handler
|
// Forward message to instance message handler
|
||||||
existingSessions.get(message._id).messageHandler(message);
|
existingSessions.get(message._id).messageHandler(message);
|
||||||
@@ -96,22 +96,21 @@ async function handleMessage (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "bridge:getInfo": {
|
case "bridge:/getInfo": {
|
||||||
const extensionVersion = message.data;
|
const extensionVersion = message.data;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subject: "main:bridgeInfo"
|
subject: "main:/bridgeInfo"
|
||||||
, data: __applicationVersion
|
, data: __applicationVersion
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
case "bridge:discover":
|
case "bridge:/discover":
|
||||||
browser.start();
|
browser.start();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "bridge:startHttpServer": {
|
case "bridge:/startHttpServer": {
|
||||||
const { filePath, port } = message.data;
|
const { filePath, port } = message.data;
|
||||||
|
|
||||||
httpServer = http.createServer((req, res) => {
|
httpServer = http.createServer((req, res) => {
|
||||||
@@ -152,14 +151,14 @@ async function handleMessage (message) {
|
|||||||
|
|
||||||
httpServer.listen(port, () => {
|
httpServer.listen(port, () => {
|
||||||
sendMessage({
|
sendMessage({
|
||||||
subject: "mediaCast:httpServerStarted"
|
subject: "mediaCast:/httpServerStarted"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
case "bridge:stopHttpServer":
|
case "bridge:/stopHttpServer":
|
||||||
if (httpServer) httpServer.close();
|
if (httpServer) httpServer.close();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -168,7 +167,7 @@ async function handleMessage (message) {
|
|||||||
|
|
||||||
browser.on("serviceUp", service => {
|
browser.on("serviceUp", service => {
|
||||||
transforms.encode.write({
|
transforms.encode.write({
|
||||||
subject: "serviceUp"
|
subject: "shim:/serviceUp"
|
||||||
, data: {
|
, data: {
|
||||||
address: service.addresses[0]
|
address: service.addresses[0]
|
||||||
, port: service.port
|
, port: service.port
|
||||||
@@ -181,7 +180,7 @@ browser.on("serviceUp", service => {
|
|||||||
|
|
||||||
browser.on("serviceDown", service => {
|
browser.on("serviceDown", service => {
|
||||||
transforms.encode.write({
|
transforms.encode.write({
|
||||||
subject:"serviceDown"
|
subject:"shim:/serviceDown"
|
||||||
, data: {
|
, data: {
|
||||||
id: service.txt.id
|
id: service.txt.id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ browser.runtime.onConnect.addListener(port => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("__castMessageResponse", ev => {
|
document.addEventListener("__castMessageResponse", ev => {
|
||||||
if (ev.detail.destination === "popup") {
|
const [ destination ] = ev.detail.subject.split(":/");
|
||||||
|
if (destination === "popup") {
|
||||||
if (popupPort) {
|
if (popupPort) {
|
||||||
popupPort.postMessage(ev.detail);
|
popupPort.postMessage(ev.detail);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export default async function getBridgeInfo () {
|
|||||||
try {
|
try {
|
||||||
const response = await browser.runtime.sendNativeMessage(
|
const response = await browser.runtime.sendNativeMessage(
|
||||||
APPLICATION_NAME
|
APPLICATION_NAME
|
||||||
, { subject: "bridge:getInfo"
|
, { subject: "bridge:/getInfo"
|
||||||
, data: EXTENSION_VERSION });
|
, data: EXTENSION_VERSION });
|
||||||
|
|
||||||
applicationVersion = response.data;
|
applicationVersion = response.data;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import defaultOptions from "./options/defaultOptions";
|
import defaultOptions from "./options/defaultOptions";
|
||||||
import messageRouter from "./messageRouter";
|
|
||||||
import getBridgeInfo from "./lib/getBridgeInfo";
|
import getBridgeInfo from "./lib/getBridgeInfo";
|
||||||
|
import messageRouter from "./lib/messageRouter";
|
||||||
|
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ async function openPopup (shimId) {
|
|||||||
browser.windows.onRemoved.addListener(id => {
|
browser.windows.onRemoved.addListener(id => {
|
||||||
if (id === popupWinId) {
|
if (id === popupWinId) {
|
||||||
shimMap.get(popupShimId).port.postMessage({
|
shimMap.get(popupShimId).port.postMessage({
|
||||||
subject: "popupClosed"
|
subject: "shim:/popupClosed"
|
||||||
});
|
});
|
||||||
|
|
||||||
popupWinId = null;
|
popupWinId = null;
|
||||||
@@ -448,12 +448,16 @@ async function onConnectShim (port) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
port.onMessage.addListener(async message => {
|
port.onMessage.addListener(async message => {
|
||||||
if (message.subject.startsWith("bridge")) {
|
const [ destination ] = message.subject.split(":/");
|
||||||
|
switch (destination) {
|
||||||
|
case "bridge": {
|
||||||
bridgePort.postMessage(message);
|
bridgePort.postMessage(message);
|
||||||
|
break;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "openPopup": {
|
case "main:/openPopup": {
|
||||||
/**
|
/**
|
||||||
* If popup already open, reassign to new shim,
|
* If popup already open, reassign to new shim,
|
||||||
* otherwise create a new popup.
|
* otherwise create a new popup.
|
||||||
@@ -462,7 +466,7 @@ async function onConnectShim (port) {
|
|||||||
|
|
||||||
// Reassign popup to new shim
|
// Reassign popup to new shim
|
||||||
popupPort.postMessage({
|
popupPort.postMessage({
|
||||||
subject: "assignPopup"
|
subject: "popup:/assignShim"
|
||||||
, data: {
|
, data: {
|
||||||
tabId
|
tabId
|
||||||
, frameId
|
, frameId
|
||||||
@@ -473,8 +477,8 @@ async function onConnectShim (port) {
|
|||||||
* Notify shim that existing popup has closed and
|
* Notify shim that existing popup has closed and
|
||||||
* to re-populate receiver list for new popup.
|
* to re-populate receiver list for new popup.
|
||||||
*/
|
*/
|
||||||
port.postMessage({ subject: "popupClosed" });
|
port.postMessage({ subject: "shim:/popupClosed" });
|
||||||
port.postMessage({ subject: "popupReady" });
|
port.postMessage({ subject: "shim:/popupReady" });
|
||||||
} else {
|
} else {
|
||||||
await openPopup(shimId);
|
await openPopup(shimId);
|
||||||
}
|
}
|
||||||
@@ -482,14 +486,6 @@ async function onConnectShim (port) {
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
case "discover": {
|
|
||||||
bridgePort.postMessage({
|
|
||||||
subject: "bridge:discover"
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
// TODO: Remove need for this
|
// TODO: Remove need for this
|
||||||
messageRouter.handleMessage(message);
|
messageRouter.handleMessage(message);
|
||||||
@@ -499,7 +495,7 @@ async function onConnectShim (port) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
subject: "shimInitialized"
|
subject: "shim:/initialized"
|
||||||
, data: bridgeInfo
|
, data: bridgeInfo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -513,7 +509,7 @@ function onConnectPopup (port) {
|
|||||||
|
|
||||||
const { tabId, frameId } = shimMap.get(popupShimId);
|
const { tabId, frameId } = shimMap.get(popupShimId);
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
subject: "assignPopup"
|
subject: "popup:/assignShim"
|
||||||
, data: {
|
, data: {
|
||||||
tabId
|
tabId
|
||||||
, frameId
|
, frameId
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const mediaElement = browser.menus.getTargetElement(targetElementId);
|
|||||||
|
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
subject: "bridge:stopHttpServer"
|
subject: "bridge:/stopHttpServer"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.mediaStopOnUnload) {
|
if (options.mediaStopOnUnload) {
|
||||||
@@ -58,7 +58,7 @@ async function onRequestSessionSuccess (session_) {
|
|||||||
if (isLocalFile) {
|
if (isLocalFile) {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
subject: "bridge:startHttpServer"
|
subject: "bridge:/startHttpServer"
|
||||||
, data: {
|
, data: {
|
||||||
filePath: decodeURI(mediaUrl.pathname)
|
filePath: decodeURI(mediaUrl.pathname)
|
||||||
, port
|
, port
|
||||||
@@ -66,7 +66,7 @@ async function onRequestSessionSuccess (session_) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(function onMessage (message) {
|
browser.runtime.onMessage.addListener(function onMessage (message) {
|
||||||
if (message.subject === "mediaCast:httpServerStarted") {
|
if (message.subject === "mediaCast:/httpServerStarted") {
|
||||||
browser.runtime.onMessage.removeListener(onMessage);
|
browser.runtime.onMessage.removeListener(onMessage);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.port.postMessage({
|
this.port.postMessage({
|
||||||
subject: "popupReady"
|
subject: "shim:/popupReady"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.port.onMessage.addListener(message => {
|
this.port.onMessage.addListener(message => {
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "populateReceiverList": {
|
case "popup:/populateReceiverList": {
|
||||||
this.setState({
|
this.setState({
|
||||||
receivers: message.data.receivers
|
receivers: message.data.receivers
|
||||||
, selectedMedia: message.data.selectedMedia
|
, selectedMedia: message.data.selectedMedia
|
||||||
@@ -75,7 +75,7 @@ class App extends Component {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "close": {
|
case "popup:/close": {
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -90,7 +90,7 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
backgroundPort.onMessage.addListener(message => {
|
backgroundPort.onMessage.addListener(message => {
|
||||||
if (message.subject === "assignPopup") {
|
if (message.subject === "popup:/assignShim") {
|
||||||
this.setPort(message.data.tabId
|
this.setPort(message.data.tabId
|
||||||
, message.data.frameId);
|
, message.data.frameId);
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.port.postMessage({
|
this.port.postMessage({
|
||||||
subject: "selectReceiver"
|
subject: "shim:/selectReceiver"
|
||||||
, data: {
|
, data: {
|
||||||
receiver
|
receiver
|
||||||
, selectedMedia: this.state.selectedMedia
|
, selectedMedia: this.state.selectedMedia
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export default class Session {
|
|||||||
this.statusText = null;
|
this.statusText = null;
|
||||||
|
|
||||||
if (receiver) {
|
if (receiver) {
|
||||||
this._sendMessage("bridge:bridgesession/initialize", {
|
this._sendMessage("bridge:/session/initialize", {
|
||||||
address: receiver._address
|
address: receiver._address
|
||||||
, port: receiver._port
|
, port: receiver._port
|
||||||
, appId
|
, appId
|
||||||
@@ -60,12 +60,14 @@ export default class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "shim:session/stopped":
|
case "shim:/session/stopped": {
|
||||||
this.status = SessionStatus.STOPPED;
|
this.status = SessionStatus.STOPPED;
|
||||||
this._updateListeners.forEach(listener => listener());
|
this._updateListeners.forEach(listener => listener());
|
||||||
break;
|
|
||||||
|
|
||||||
case "shim:session/connected":
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
case "shim:/session/connected": {
|
||||||
this.status = SessionStatus.CONNECTED;
|
this.status = SessionStatus.CONNECTED;
|
||||||
this.sessionId = message.data.sessionId;
|
this.sessionId = message.data.sessionId;
|
||||||
this.namespaces = message.data.namespaces;
|
this.namespaces = message.data.namespaces;
|
||||||
@@ -77,8 +79,9 @@ export default class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
case "shim:session/updateStatus":
|
case "shim:/session/updateStatus": {
|
||||||
if (message.data.volume) {
|
if (message.data.volume) {
|
||||||
if (!this.receiver.volume) {
|
if (!this.receiver.volume) {
|
||||||
const receiverVolume = new Volume(
|
const receiverVolume = new Volume(
|
||||||
@@ -94,17 +97,19 @@ export default class Session {
|
|||||||
this.receiver.volume.muted = message.data.volume.muted;
|
this.receiver.volume.muted = message.data.volume.muted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
case "shim:session/impl_addMessageListener": {
|
case "shim:/session/impl_addMessageListener": {
|
||||||
const { namespace, data } = message.data;
|
const { namespace, data } = message.data;
|
||||||
this._messageListeners.get(namespace).forEach(
|
this._messageListeners.get(namespace).forEach(
|
||||||
listener => listener(namespace, data));
|
listener => listener(namespace, data));
|
||||||
break;
|
break;
|
||||||
}
|
};
|
||||||
|
|
||||||
case "shim:session/impl_sendMessage": {
|
case "shim:/session/impl_sendMessage": {
|
||||||
const { messageId, error } = message.data;
|
const { messageId, error } = message.data;
|
||||||
const [ successCallback, errorCallback ]
|
const [ successCallback, errorCallback ]
|
||||||
= this._sendMessageCallbacks.get(messageId)
|
= this._sendMessageCallbacks.get(messageId)
|
||||||
@@ -114,11 +119,13 @@ export default class Session {
|
|||||||
} else if (successCallback) {
|
} else if (successCallback) {
|
||||||
successCallback();
|
successCallback();
|
||||||
}
|
}
|
||||||
this._sendMessageCallbacks.delete(messageId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "shim:session/impl_setReceiverMuted": {
|
this._sendMessageCallbacks.delete(messageId);
|
||||||
|
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
case "shim:/session/impl_setReceiverMuted": {
|
||||||
const { volumeId, error } = message.data;
|
const { volumeId, error } = message.data;
|
||||||
const [ successCallback, errorCallback ]
|
const [ successCallback, errorCallback ]
|
||||||
= this._setReceiverMutedCallbacks.get(volumeId);
|
= this._setReceiverMutedCallbacks.get(volumeId);
|
||||||
@@ -128,11 +135,13 @@ export default class Session {
|
|||||||
} else if (successCallback) {
|
} else if (successCallback) {
|
||||||
successCallback();
|
successCallback();
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
this._setReceiverMutedCallbacks.delete(volumeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
case "shim:session/impl_setReceiverVolumeLevel": {
|
this._setReceiverMutedCallbacks.delete(volumeId);
|
||||||
|
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
case "shim:/session/impl_setReceiverVolumeLevel": {
|
||||||
const { volumeId, error } = message.data;
|
const { volumeId, error } = message.data;
|
||||||
const [ successCallback, errorCallback ]
|
const [ successCallback, errorCallback ]
|
||||||
= this._setReceiverVolumeLevelCallbacks.get(volumeId);
|
= this._setReceiverVolumeLevelCallbacks.get(volumeId);
|
||||||
@@ -142,11 +151,13 @@ export default class Session {
|
|||||||
} else if (successCallback) {
|
} else if (successCallback) {
|
||||||
successCallback();
|
successCallback();
|
||||||
}
|
}
|
||||||
this._setReceiverVolumeLevelCallbacks.delete(volumeId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "shim:session/impl_stop": {
|
this._setReceiverVolumeLevelCallbacks.delete(volumeId);
|
||||||
|
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
case "shim:/session/impl_stop": {
|
||||||
const { stopId, error } = message.data;
|
const { stopId, error } = message.data;
|
||||||
const [ successCallback, errorCallback ]
|
const [ successCallback, errorCallback ]
|
||||||
= this._stopCallbacks.get(stopId);
|
= this._stopCallbacks.get(stopId);
|
||||||
@@ -161,10 +172,11 @@ export default class Session {
|
|||||||
successCallback();
|
successCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._stopCallbacks.delete(stopId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this._stopCallbacks.delete(stopId);
|
||||||
|
|
||||||
|
break;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -187,7 +199,7 @@ export default class Session {
|
|||||||
this._messageListeners.set(namespace, new Set());
|
this._messageListeners.set(namespace, new Set());
|
||||||
}
|
}
|
||||||
this._messageListeners.get(namespace).add(listener);
|
this._messageListeners.get(namespace).add(listener);
|
||||||
this._sendMessage("bridge:bridgesession/impl_addMessageListener", {
|
this._sendMessage("bridge:/session/impl_addMessageListener", {
|
||||||
namespace
|
namespace
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -199,7 +211,7 @@ export default class Session {
|
|||||||
leave (successCallback, errorCallback) {
|
leave (successCallback, errorCallback) {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
|
|
||||||
this._sendMessage("bridge:bridgesession/impl_leave", { id });
|
this._sendMessage("bridge:/session/impl_leave", { id });
|
||||||
|
|
||||||
this._leaveCallbacks.set(id, [
|
this._leaveCallbacks.set(id, [
|
||||||
successCallback
|
successCallback
|
||||||
@@ -270,7 +282,7 @@ export default class Session {
|
|||||||
sendMessage (namespace, message, successCallback, errorCallback) {
|
sendMessage (namespace, message, successCallback, errorCallback) {
|
||||||
const messageId = uuid();
|
const messageId = uuid();
|
||||||
|
|
||||||
this._sendMessage("bridge:bridgesession/impl_sendMessage", {
|
this._sendMessage("bridge:/session/impl_sendMessage", {
|
||||||
namespace
|
namespace
|
||||||
, message
|
, message
|
||||||
, messageId
|
, messageId
|
||||||
@@ -285,7 +297,7 @@ export default class Session {
|
|||||||
setReceiverMuted (muted, successCallback, errorCallback) {
|
setReceiverMuted (muted, successCallback, errorCallback) {
|
||||||
const volumeId = uuid();
|
const volumeId = uuid();
|
||||||
|
|
||||||
this._sendMessage("bridge:bridgesession/impl_setReceiverMuted", {
|
this._sendMessage("bridge:/session/impl_setReceiverMuted", {
|
||||||
muted
|
muted
|
||||||
, volumeId
|
, volumeId
|
||||||
});
|
});
|
||||||
@@ -298,7 +310,7 @@ export default class Session {
|
|||||||
|
|
||||||
setReceiverVolumeLevel (newLevel, successCallback, errorCallback) {
|
setReceiverVolumeLevel (newLevel, successCallback, errorCallback) {
|
||||||
const volumeId = uuid();
|
const volumeId = uuid();
|
||||||
this._sendMessage("bridge:bridgesession/impl_setReceiverVolumeLevel", {
|
this._sendMessage("bridge:/session/impl_setReceiverVolumeLevel", {
|
||||||
newLevel
|
newLevel
|
||||||
, volumeId
|
, volumeId
|
||||||
});
|
});
|
||||||
@@ -311,7 +323,7 @@ export default class Session {
|
|||||||
|
|
||||||
stop (successCallback, errorCallback) {
|
stop (successCallback, errorCallback) {
|
||||||
const stopId = uuid();
|
const stopId = uuid();
|
||||||
this._sendMessage("bridge:bridgesession/impl_stop", { stopId });
|
this._sendMessage("bridge:/session/impl_stop", { stopId });
|
||||||
|
|
||||||
this._stopCallbacks.set(stopId, [
|
this._stopCallbacks.set(stopId, [
|
||||||
successCallback
|
successCallback
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ cast.initialize = (
|
|||||||
state.apiConfig = apiConfig;
|
state.apiConfig = apiConfig;
|
||||||
|
|
||||||
sendMessage({
|
sendMessage({
|
||||||
subject: "discover"
|
subject: "bridge:/discover"
|
||||||
});
|
});
|
||||||
|
|
||||||
apiConfig.receiverListener(state.receiverList.length
|
apiConfig.receiverListener(state.receiverList.length
|
||||||
@@ -146,7 +146,7 @@ cast.requestSession = (
|
|||||||
|
|
||||||
// Open destination chooser
|
// Open destination chooser
|
||||||
sendMessage({
|
sendMessage({
|
||||||
subject: "openPopup"
|
subject: "main:/openPopup"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ onMessage(message => {
|
|||||||
* Cast destination found (serviceUp). Set the API availability
|
* Cast destination found (serviceUp). Set the API availability
|
||||||
* property and call the page event function (__onGCastApiAvailable).
|
* property and call the page event function (__onGCastApiAvailable).
|
||||||
*/
|
*/
|
||||||
case "serviceUp": {
|
case "shim:/serviceUp": {
|
||||||
const receiver = message.data;
|
const receiver = message.data;
|
||||||
|
|
||||||
if (state.receiverList.find(r => r.id === receiver.id)) {
|
if (state.receiverList.find(r => r.id === receiver.id)) {
|
||||||
@@ -194,7 +194,7 @@ onMessage(message => {
|
|||||||
* Cast destination lost (serviceDown). Remove from the receiver list
|
* Cast destination lost (serviceDown). Remove from the receiver list
|
||||||
* and update availability state.
|
* and update availability state.
|
||||||
*/
|
*/
|
||||||
case "serviceDown": {
|
case "shim:/serviceDown": {
|
||||||
state.receiverList = state.receiverList.filter(
|
state.receiverList = state.receiverList.filter(
|
||||||
receiver => receiver.id !== message.data.id);
|
receiver => receiver.id !== message.data.id);
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ onMessage(message => {
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
case "selectReceiver": {
|
case "shim:/selectReceiver": {
|
||||||
console.info("Caster (Debug): Selected receiver");
|
console.info("Caster (Debug): Selected receiver");
|
||||||
|
|
||||||
const selectedReceiver = new Receiver(
|
const selectedReceiver = new Receiver(
|
||||||
@@ -224,8 +224,7 @@ onMessage(message => {
|
|||||||
, selectedReceiver // receiver
|
, selectedReceiver // receiver
|
||||||
, (session) => {
|
, (session) => {
|
||||||
sendMessage({
|
sendMessage({
|
||||||
subject: "close"
|
subject: "popup:/close"
|
||||||
, destination: "popup"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
state.apiConfig.sessionListener(session);
|
state.apiConfig.sessionListener(session);
|
||||||
@@ -257,10 +256,9 @@ onMessage(message => {
|
|||||||
* Popup is ready to receive data to populate the cast destination
|
* Popup is ready to receive data to populate the cast destination
|
||||||
* chooser.
|
* chooser.
|
||||||
*/
|
*/
|
||||||
case "popupReady": {
|
case "shim:/popupReady": {
|
||||||
sendMessage({
|
sendMessage({
|
||||||
subject: "populateReceiverList"
|
subject: "popup:/populateReceiverList"
|
||||||
, destination: "popup"
|
|
||||||
, data: {
|
, data: {
|
||||||
receivers: state.receiverList
|
receivers: state.receiverList
|
||||||
, selectedMedia: state.apiConfig._selectedMedia
|
, selectedMedia: state.apiConfig._selectedMedia
|
||||||
@@ -273,7 +271,7 @@ onMessage(message => {
|
|||||||
/**
|
/**
|
||||||
* Popup closed before session established.
|
* Popup closed before session established.
|
||||||
*/
|
*/
|
||||||
case "popupClosed": {
|
case "shim:/popupClosed": {
|
||||||
if (state.sessionRequestInProgress) {
|
if (state.sessionRequestInProgress) {
|
||||||
state.sessionRequestInProgress = false;
|
state.sessionRequestInProgress = false;
|
||||||
sessionErrorCallback(new Error_(ErrorCode.CANCEL));
|
sessionErrorCallback(new Error_(ErrorCode.CANCEL));
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ window.chrome.cast.media = media;
|
|||||||
|
|
||||||
onMessage(message => {
|
onMessage(message => {
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "shimInitialized": {
|
case "shim:/initialized": {
|
||||||
const bridgeInfo = message.data;
|
const bridgeInfo = message.data;
|
||||||
|
|
||||||
// Call page's API loaded function if defined
|
// Call page's API loaded function if defined
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export default class Media {
|
|||||||
this.supportedMediaCommands = [];
|
this.supportedMediaCommands = [];
|
||||||
this.volume = new Volume();
|
this.volume = new Volume();
|
||||||
|
|
||||||
this._sendMessage("bridge:bridgemedia/initialize", {
|
this._sendMessage("bridge:/media/initialize", {
|
||||||
sessionId
|
sessionId
|
||||||
, mediaSessionId
|
, mediaSessionId
|
||||||
, _internalSessionId
|
, _internalSessionId
|
||||||
@@ -48,7 +48,7 @@ export default class Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "shim:media/update":
|
case "shim:/media/update":
|
||||||
const status = message.data;
|
const status = message.data;
|
||||||
this.currentTime = status.currentTime;
|
this.currentTime = status.currentTime;
|
||||||
this._lastCurrentTime = status._lastCurrentTime;
|
this._lastCurrentTime = status._lastCurrentTime;
|
||||||
@@ -72,7 +72,7 @@ export default class Media {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "shim:media/sendMediaMessageResponse":
|
case "shim:/media/sendMediaMessageResponse":
|
||||||
const { messageId, error } = message.data;
|
const { messageId, error } = message.data;
|
||||||
const [ successCallback, errorCallback ]
|
const [ successCallback, errorCallback ]
|
||||||
= this._sendMediaMessageCallbacks.get(messageId);
|
= this._sendMediaMessageCallbacks.get(messageId);
|
||||||
@@ -113,7 +113,7 @@ export default class Media {
|
|||||||
, errorCallback
|
, errorCallback
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this._sendMessage("bridge:bridgemedia/sendMediaMessage", {
|
this._sendMessage("bridge:/media/sendMediaMessage", {
|
||||||
message
|
message
|
||||||
, messageId
|
, messageId
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ module.exports = (env) => ({
|
|||||||
, "contentSetup" : `${env.includePath}/contentSetup.js`
|
, "contentSetup" : `${env.includePath}/contentSetup.js`
|
||||||
, "mediaCast" : `${env.includePath}/mediaCast.js`
|
, "mediaCast" : `${env.includePath}/mediaCast.js`
|
||||||
, "mirroringCast" : `${env.includePath}/mirroringCast.js`
|
, "mirroringCast" : `${env.includePath}/mirroringCast.js`
|
||||||
, "messageRouter" : `${env.includePath}/messageRouter.js`
|
|
||||||
, "compat/youtube" : `${env.includePath}/compat/youtube.js`
|
, "compat/youtube" : `${env.includePath}/compat/youtube.js`
|
||||||
}
|
}
|
||||||
, output: {
|
, output: {
|
||||||
|
|||||||
Reference in New Issue
Block a user