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