mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Convert shim to Typescript (#32)
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import { AutoJoinPolicy
|
||||
, DefaultActionPolicy } from "../enums";
|
||||
|
||||
export default class ApiConfig {
|
||||
constructor (
|
||||
sessionRequest
|
||||
, sessionListener
|
||||
, receiverListener
|
||||
, opt_autoJoinPolicy = AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED
|
||||
, opt_defaultActionPolicy = DefaultActionPolicy.CREATE_SESSION
|
||||
// TODO: Remove awful hack for mirror casting
|
||||
, selectedMedia = "app") {
|
||||
|
||||
this.autoJoinPolicy = opt_autoJoinPolicy;
|
||||
this.defaultActionPolicy = opt_defaultActionPolicy;
|
||||
this.receiverListener = receiverListener;
|
||||
this.sessionListener = sessionListener;
|
||||
this.sessionRequest = sessionRequest;
|
||||
|
||||
this.additionalSessionRequests = [];
|
||||
this.customDialLaunchCallback = null;
|
||||
this.invisibleSender = false;
|
||||
|
||||
this._selectedMedia = selectedMedia;
|
||||
}
|
||||
};
|
||||
25
ext/src/shim/cast/classes/ApiConfig.ts
Executable file
25
ext/src/shim/cast/classes/ApiConfig.ts
Executable file
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
import Session from "./Session";
|
||||
import SessionRequest from "./SessionRequest";
|
||||
|
||||
import { AutoJoinPolicy
|
||||
, DefaultActionPolicy } from "../enums";
|
||||
|
||||
|
||||
export default class ApiConfig {
|
||||
public additionalSessionRequests: any[] = [];
|
||||
public customDialLaunchCallback: any = null;
|
||||
public invisibleSender = false;
|
||||
|
||||
constructor (
|
||||
public sessionRequest: SessionRequest
|
||||
, public sessionListener: (session: Session) => void
|
||||
, public receiverListener: (availability: string) => void
|
||||
, public autoJoinPolicy: string = AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED
|
||||
, public defaultActionPolicy: string = DefaultActionPolicy.CREATE_SESSION
|
||||
|
||||
// TODO: Remove awful hack for mirror casting
|
||||
, public _selectedMedia: string = "app") {
|
||||
}
|
||||
};
|
||||
@@ -1,12 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.DialRequest
|
||||
export default class DialRequest {
|
||||
constructor (
|
||||
appName
|
||||
, opt_launchParameter = null) {
|
||||
|
||||
this.appName = appName;
|
||||
this.launchParameter = opt_launchParameter;
|
||||
}
|
||||
};
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.DialRequest
|
||||
export default class DialRequest {
|
||||
constructor (
|
||||
public appName: string
|
||||
, public launchParameter: string = null) {
|
||||
}
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Error
|
||||
export default class Error {
|
||||
constructor (
|
||||
code
|
||||
, opt_description = null
|
||||
, opt_details = null) {
|
||||
|
||||
this.code = code;
|
||||
this.description = opt_description;
|
||||
this.details = opt_details;
|
||||
}
|
||||
};
|
||||
10
ext/src/shim/cast/classes/Error.ts
Executable file
10
ext/src/shim/cast/classes/Error.ts
Executable file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Error
|
||||
export default class Error {
|
||||
constructor (
|
||||
public code: string
|
||||
, public description: string = null
|
||||
, public details: any = null) {
|
||||
}
|
||||
};
|
||||
@@ -1,11 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Image
|
||||
export default class Image {
|
||||
width = null;
|
||||
height = null;
|
||||
|
||||
constructor (url) {
|
||||
this.url = url;
|
||||
}
|
||||
};
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Image
|
||||
export default class Image {
|
||||
public width: number = null;
|
||||
public height: number = null;
|
||||
|
||||
constructor (public url: string) {}
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import { Capability
|
||||
, ReceiverType } from "../enums";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Receiver
|
||||
export default class Receiver {
|
||||
constructor (
|
||||
label
|
||||
, friendlyName
|
||||
, opt_capabilities = []
|
||||
, opt_volume = null) {
|
||||
|
||||
this.capabilities = opt_capabilities;
|
||||
this.displayStatus = null;
|
||||
this.friendlyName = friendlyName;
|
||||
this.isActiveInput = null;
|
||||
this.label = label;
|
||||
this.receiverType = ReceiverType.CAST;
|
||||
this.volume = opt_volume;
|
||||
}
|
||||
};
|
||||
21
ext/src/shim/cast/classes/Receiver.ts
Executable file
21
ext/src/shim/cast/classes/Receiver.ts
Executable file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
import ReceiverDisplayStatus from "./ReceiverDisplayStatus";
|
||||
import Volume from "./Volume";
|
||||
|
||||
import { ReceiverType } from "../enums";
|
||||
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Receiver
|
||||
export default class Receiver {
|
||||
public displayStatus: ReceiverDisplayStatus = null;
|
||||
public isActiveInput: boolean = null;
|
||||
public receiverType: string = ReceiverType.CAST;
|
||||
|
||||
constructor (
|
||||
public label: string
|
||||
, public friendlyName: string
|
||||
, public capabilities: string[] = []
|
||||
, public volume: Volume = null) {
|
||||
}
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.ReceiverDisplayStatus
|
||||
export default class ReceiverDisplayStatus {
|
||||
constructor (statusText, appImages) {
|
||||
this.appImages = appImages;
|
||||
this.showStop = null;
|
||||
this.statusText = statusText;
|
||||
}
|
||||
};
|
||||
13
ext/src/shim/cast/classes/ReceiverDisplayStatus.ts
Executable file
13
ext/src/shim/cast/classes/ReceiverDisplayStatus.ts
Executable file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
import Image from "./Image";
|
||||
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.ReceiverDisplayStatus
|
||||
export default class ReceiverDisplayStatus {
|
||||
public showStop: boolean = null;
|
||||
|
||||
constructor (
|
||||
public statusText: string
|
||||
, public appImages: Image[]) {}
|
||||
};
|
||||
@@ -1,10 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SenderApplication
|
||||
export default class SenderApplication {
|
||||
constructor (platform) {
|
||||
this.packageId = null;
|
||||
this.platform = platform;
|
||||
this.url = null;
|
||||
}
|
||||
};
|
||||
"use strict";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SenderApplication
|
||||
export default class SenderApplication {
|
||||
public packageId: string = null;
|
||||
public url: string = null;
|
||||
|
||||
constructor (public platform: string) {}
|
||||
};
|
||||
@@ -1,8 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
import _Error from "./Error";
|
||||
import Volume from "./Volume";
|
||||
import Media from "../../media/classes/Media";
|
||||
import uuid from "uuid/v1";
|
||||
|
||||
import _Error from "./Error";
|
||||
import Image from "./Image";
|
||||
import Receiver from "./Receiver";
|
||||
import SenderApplication from "./SenderApplication";
|
||||
import Volume from "./Volume";
|
||||
|
||||
import LoadRequest from "../../media/classes/LoadRequest";
|
||||
import Media from "../../media/classes/Media";
|
||||
import QueueLoadRequest from "../../media/classes/QueueLoadRequest";
|
||||
|
||||
import { SessionStatus
|
||||
, ErrorCode
|
||||
@@ -10,44 +18,53 @@ import { SessionStatus
|
||||
|
||||
import { onMessage, sendMessageResponse } from "../../messageBridge";
|
||||
|
||||
import uuid from "uuid/v1";
|
||||
import { SuccessCallback
|
||||
, ErrorCallback
|
||||
, MediaListener
|
||||
, MessageListener
|
||||
, UpdateListener
|
||||
, LoadSuccessCallback
|
||||
, Callbacks
|
||||
, CallbacksMap } from "../../types";
|
||||
|
||||
|
||||
export default class Session {
|
||||
private _id: string = uuid();
|
||||
private _messageListeners = new Map<string, Set<MessageListener>>();
|
||||
private _updateListeners = new Set<UpdateListener>();
|
||||
|
||||
private _leaveCallbacks: CallbacksMap = new Map();
|
||||
private _sendMessageCallbacks: CallbacksMap = new Map();
|
||||
private _setReceiverMutedCallbacks: CallbacksMap = new Map();
|
||||
private _setReceiverVolumeLevelCallbacks: CallbacksMap = new Map();
|
||||
private _stopCallbacks: CallbacksMap = new Map();
|
||||
|
||||
public media: Media[];
|
||||
public namespaces: { name: "string" }[];
|
||||
public senderApps: SenderApplication[];
|
||||
public status: string;
|
||||
public statusText: string;
|
||||
public transportId: string;
|
||||
|
||||
constructor (
|
||||
sessionId
|
||||
, appId
|
||||
, displayName
|
||||
, appImages
|
||||
, receiver
|
||||
, successCallback) {
|
||||
|
||||
this._id = uuid();
|
||||
this._messageListeners = new Map();
|
||||
this._updateListeners = new Set();
|
||||
|
||||
this._sendMessageCallbacks = new Map();
|
||||
this._setReceiverMutedCallbacks = new Map();
|
||||
this._setReceiverVolumeLevelCallbacks = new Map();
|
||||
this._stopCallbacks = new Map();
|
||||
|
||||
this.sessionId = sessionId;
|
||||
this.transportId = sessionId || "";
|
||||
this.appId = appId;
|
||||
this.appImages = appImages;
|
||||
this.displayName = displayName;
|
||||
this.receiver = receiver;
|
||||
public sessionId: string
|
||||
, public appId: string
|
||||
, public displayName: string
|
||||
, public appImages: Image[]
|
||||
, public receiver: Receiver
|
||||
, successCallback: (session: Session) => void) {
|
||||
|
||||
this.media = [];
|
||||
this.namespaces = [];
|
||||
this.senderApps = [];
|
||||
this.status = SessionStatus.CONNECTED;
|
||||
this.statusText = null;
|
||||
this.transportId = sessionId || "";
|
||||
|
||||
if (receiver) {
|
||||
this._sendMessage("bridge:/session/initialize", {
|
||||
address: receiver._address
|
||||
, port: receiver._port
|
||||
address: (receiver as any)._address
|
||||
, port: (receiver as any)._port
|
||||
, appId
|
||||
, sessionId
|
||||
});
|
||||
@@ -62,7 +79,10 @@ export default class Session {
|
||||
switch (message.subject) {
|
||||
case "shim:/session/stopped": {
|
||||
this.status = SessionStatus.STOPPED;
|
||||
this._updateListeners.forEach(listener => listener());
|
||||
|
||||
for (const listener of this._updateListeners) {
|
||||
listener(false);
|
||||
}
|
||||
|
||||
break;
|
||||
};
|
||||
@@ -82,19 +102,21 @@ export default class Session {
|
||||
};
|
||||
|
||||
case "shim:/session/updateStatus": {
|
||||
if (message.data.volume) {
|
||||
const volume: Volume = message.data.volume;
|
||||
|
||||
if (volume) {
|
||||
if (!this.receiver.volume) {
|
||||
const receiverVolume = new Volume(
|
||||
message.data.volume.level
|
||||
, message.data.volume.muted);
|
||||
volume.level
|
||||
, volume.muted);
|
||||
|
||||
receiverVolume.controlType = message.data.volume.controlType;
|
||||
receiverVolume.stepInterval = message.data.volume.stepInterval;
|
||||
receiverVolume.controlType = volume.controlType;
|
||||
receiverVolume.stepInterval = volume.stepInterval;
|
||||
|
||||
this.receiver.volume = receiverVolume;
|
||||
} else {
|
||||
this.receiver.volume.level = message.data.volume.level;
|
||||
this.receiver.volume.muted = message.data.volume.muted;
|
||||
this.receiver.volume.level = volume.level;
|
||||
this.receiver.volume.muted = volume.muted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +126,10 @@ export default class Session {
|
||||
|
||||
case "shim:/session/impl_addMessageListener": {
|
||||
const { namespace, data } = message.data;
|
||||
this._messageListeners.get(namespace).forEach(
|
||||
listener => listener(namespace, data));
|
||||
for (const listener of this._messageListeners.get(namespace)) {
|
||||
listener(namespace, data);
|
||||
}
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
@@ -166,7 +190,10 @@ export default class Session {
|
||||
errorCallback(new _Error(ErrorCode.SESSION_ERROR));
|
||||
} else {
|
||||
this.status = SessionStatus.STOPPED;
|
||||
this._updateListeners.forEach(listener => listener());
|
||||
|
||||
for (const listener of this._updateListeners) {
|
||||
listener(false);
|
||||
}
|
||||
|
||||
if (successCallback) {
|
||||
successCallback();
|
||||
@@ -181,20 +208,12 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
_sendMessage (subject, data = {}) {
|
||||
sendMessageResponse({
|
||||
subject
|
||||
, data
|
||||
, _id: this._id
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
addMediaListener (listener) {
|
||||
public addMediaListener (listener: MediaListener) {
|
||||
console.info("STUB :: Session#addMediaListener")
|
||||
}
|
||||
|
||||
addMessageListener (namespace, listener) {
|
||||
public addMessageListener (namespace: string, listener: MessageListener) {
|
||||
if (!this._messageListeners.has(namespace)) {
|
||||
this._messageListeners.set(namespace, new Set());
|
||||
}
|
||||
@@ -204,11 +223,14 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
addUpdateListener (listener) {
|
||||
public addUpdateListener (listener: UpdateListener) {
|
||||
this._updateListeners.add(listener);
|
||||
}
|
||||
|
||||
leave (successCallback, errorCallback) {
|
||||
public leave (
|
||||
successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback): void {
|
||||
|
||||
const id = uuid();
|
||||
|
||||
this._sendMessage("bridge:/session/impl_leave", { id });
|
||||
@@ -219,8 +241,12 @@ export default class Session {
|
||||
]);
|
||||
}
|
||||
|
||||
loadMedia (loadRequest, successCallback, errorCallback) {
|
||||
this.sendMediaMessage({
|
||||
public loadMedia (
|
||||
loadRequest: LoadRequest
|
||||
, successCallback: LoadSuccessCallback
|
||||
, errorCallback: ErrorCallback): void {
|
||||
|
||||
this._sendMediaMessage({
|
||||
type: "LOAD"
|
||||
, requestId: 0
|
||||
, media: loadRequest.media
|
||||
@@ -233,8 +259,10 @@ export default class Session {
|
||||
|
||||
let hasResponded = false;
|
||||
|
||||
this.addMessageListener("urn:x-cast:com.google.cast.media"
|
||||
this.addMessageListener(
|
||||
"urn:x-cast:com.google.cast.media"
|
||||
, (namespace, data) => {
|
||||
|
||||
if (hasResponded) return;
|
||||
|
||||
const mediaObject = JSON.parse(data);
|
||||
@@ -258,28 +286,38 @@ export default class Session {
|
||||
})
|
||||
}
|
||||
|
||||
queueLoad () {
|
||||
public queueLoad (
|
||||
queueLoadRequest: QueueLoadRequest
|
||||
, successCallback: LoadSuccessCallback
|
||||
, errorCallback: ErrorCallback): void {
|
||||
|
||||
console.info("STUB :: Session#queueLoad");
|
||||
}
|
||||
removeMediaListener (listener) {
|
||||
|
||||
public removeMediaListener (listener: MediaListener): void {
|
||||
console.info("STUB :: Session#removeMediaListener");
|
||||
}
|
||||
removeMessageListener (namespace, listener) {
|
||||
|
||||
public removeMessageListener (
|
||||
namespace: string
|
||||
, listener: MessageListener): void {
|
||||
|
||||
this._messageListeners.get(namespace).delete(listener);
|
||||
}
|
||||
removeUpdateListener (namespace, listener) {
|
||||
|
||||
public removeUpdateListener (
|
||||
namespace: string
|
||||
, listener: UpdateListener): void {
|
||||
|
||||
this._updateListeners.delete(listener);
|
||||
}
|
||||
|
||||
sendMediaMessage (message) {
|
||||
this.sendMessage(
|
||||
"urn:x-cast:com.google.cast.media"
|
||||
, message
|
||||
, () => {}
|
||||
, () => {});
|
||||
}
|
||||
public sendMessage (
|
||||
namespace: string
|
||||
, message: {} | string
|
||||
, successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback): void {
|
||||
|
||||
sendMessage (namespace, message, successCallback, errorCallback) {
|
||||
const messageId = uuid();
|
||||
|
||||
this._sendMessage("bridge:/session/impl_sendMessage", {
|
||||
@@ -294,7 +332,11 @@ export default class Session {
|
||||
]);
|
||||
}
|
||||
|
||||
setReceiverMuted (muted, successCallback, errorCallback) {
|
||||
public setReceiverMuted (
|
||||
muted: boolean
|
||||
, successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback) {
|
||||
|
||||
const volumeId = uuid();
|
||||
|
||||
this._sendMessage("bridge:/session/impl_setReceiverMuted", {
|
||||
@@ -308,7 +350,11 @@ export default class Session {
|
||||
]);
|
||||
}
|
||||
|
||||
setReceiverVolumeLevel (newLevel, successCallback, errorCallback) {
|
||||
public setReceiverVolumeLevel (
|
||||
newLevel: number
|
||||
, successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback): void {
|
||||
|
||||
const volumeId = uuid();
|
||||
this._sendMessage("bridge:/session/impl_setReceiverVolumeLevel", {
|
||||
newLevel
|
||||
@@ -321,7 +367,10 @@ export default class Session {
|
||||
]);
|
||||
}
|
||||
|
||||
stop (successCallback, errorCallback) {
|
||||
public stop (
|
||||
successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback): void {
|
||||
|
||||
const stopId = uuid();
|
||||
this._sendMessage("bridge:/session/impl_stop", { stopId });
|
||||
|
||||
@@ -330,4 +379,20 @@ export default class Session {
|
||||
, errorCallback
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private _sendMessage (subject: string, data = {}) {
|
||||
sendMessageResponse({
|
||||
subject
|
||||
, data
|
||||
, _id: this._id
|
||||
});
|
||||
}
|
||||
|
||||
private _sendMediaMessage (message: string | {}) {
|
||||
this.sendMessage(
|
||||
"urn:x-cast:com.google.cast.media"
|
||||
, message
|
||||
, null, null);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import { Capability } from "../enums";
|
||||
import { requestSession as requestSessionTimeout } from "../../timeout.js";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SessionRequest
|
||||
export default class SessionRequest {
|
||||
constructor (
|
||||
appId
|
||||
, opt_capabilities = [
|
||||
Capability.VIDEO_OUT
|
||||
, Capability.AUDIO_OUT ]
|
||||
, opt_timeout = requestSessionTimeout) {
|
||||
|
||||
this.appId = appId;
|
||||
this.capabilities = opt_capabilities;
|
||||
this.dialRequest = null;
|
||||
this.language = null;
|
||||
this.requestSessionTimeout = opt_timeout;
|
||||
}
|
||||
};
|
||||
17
ext/src/shim/cast/classes/SessionRequest.ts
Executable file
17
ext/src/shim/cast/classes/SessionRequest.ts
Executable file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
import { Capability } from "../enums";
|
||||
import { requestSession } from "../../timeout";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SessionRequest
|
||||
export default class SessionRequest {
|
||||
public language: string = null;
|
||||
public dialRequest: any = null;
|
||||
|
||||
constructor (
|
||||
public appId: string
|
||||
, public capabilities = [
|
||||
Capability.VIDEO_OUT
|
||||
, Capability.AUDIO_OUT ]
|
||||
, public requestSessionTimeout: number = requestSession) {}
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
import * as timeouts from "../../timeout.js";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Timeout
|
||||
export default class Timeout {
|
||||
constructor () {
|
||||
Object.assign(this, timeouts);
|
||||
}
|
||||
};
|
||||
"use strict";
|
||||
|
||||
import * as timeouts from "../../timeout";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Timeout
|
||||
export default class Timeout {
|
||||
constructor () {
|
||||
Object.assign(this, timeouts);
|
||||
}
|
||||
};
|
||||
@@ -1,13 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
import { VolumeControlType } from "../enums";
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Volume
|
||||
export default class Volume {
|
||||
constructor (
|
||||
opt_level = null
|
||||
, opt_muted = null) {
|
||||
this.level = opt_level;
|
||||
this.muted = opt_muted;
|
||||
}
|
||||
};
|
||||
"use strict";
|
||||
|
||||
import { VolumeControlType } from "../enums";
|
||||
|
||||
|
||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Volume
|
||||
export default class Volume {
|
||||
public controlType: string;
|
||||
public stepInterval: number;
|
||||
|
||||
constructor (
|
||||
public level: number = null
|
||||
, public muted: boolean = null) {
|
||||
}
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import ApiConfig from "./ApiConfig";
|
||||
import DialRequest from "./DialRequest";
|
||||
import Error_ from "./Error";
|
||||
import Image_ from "./Image";
|
||||
import Receiver from "./Receiver";
|
||||
import ReceiverDisplayStatus from "./ReceiverDisplayStatus";
|
||||
import SenderApplication from "./SenderApplication";
|
||||
import Session from "./Session";
|
||||
import SessionRequest from "./SessionRequest";
|
||||
import Timeout from "./Timeout";
|
||||
import Volume from "./Volume";
|
||||
|
||||
|
||||
export default {
|
||||
AutoJoinPolicy
|
||||
, Capability
|
||||
, DefaultActionPolicy
|
||||
, DialAppState
|
||||
, ErrorCode
|
||||
, ReceiverAction
|
||||
, ReceiverAvailability
|
||||
, ReceiverType
|
||||
, SenderPlatform
|
||||
, SessionStatus
|
||||
, VolumeControlType
|
||||
};
|
||||
@@ -1,75 +1,75 @@
|
||||
"use strict";
|
||||
|
||||
export const AutoJoinPolicy = {
|
||||
TAB_AND_ORIGIN_SCOPED: "tab_and_origin_scoped"
|
||||
, ORIGIN_SCOPED: "origin_scoped"
|
||||
, PAGE_SCOPED: "page_scoped"
|
||||
, CUSTOM_CONTROLLER_SCOPED: "custom_controller_scoped"
|
||||
};
|
||||
|
||||
export const Capability = {
|
||||
VIDEO_OUT: "video_out"
|
||||
, AUDIO_OUT: "audio_out"
|
||||
, VIDEO_IN: "video_in"
|
||||
, AUDIO_IN: "audio_in"
|
||||
, MULTIZONE_GROUP: "multizone_group"
|
||||
};
|
||||
|
||||
export const DefaultActionPolicy = {
|
||||
CREATE_SESSION: "create_session"
|
||||
, CAST_THIS_TAB: "cast_this_tab"
|
||||
};
|
||||
|
||||
export const DialAppState = {
|
||||
RUNNING: "running"
|
||||
, STOPPED: "stopped"
|
||||
, ERROR: "error"
|
||||
};
|
||||
|
||||
export const ErrorCode = {
|
||||
CANCEL: "cancel"
|
||||
, TIMEOUT: "timeout"
|
||||
, API_NOT_INITIALIZED: "api_not_initialized"
|
||||
, INVALID_PARAMETER: "invalid_parameter"
|
||||
, EXTENSION_NOT_COMPATIBLE: "extension_not_compatible"
|
||||
, EXTENSION_MISSING: "extension_missing"
|
||||
, RECEIVER_UNAVAILABLE: "receiver_unavailable"
|
||||
, SESSION_ERROR: "session_error"
|
||||
, CHANNEL_ERROR: "channel_error"
|
||||
, LOAD_MEDIA_FAILED: "load_media_failed"
|
||||
};
|
||||
|
||||
export const ReceiverAction = {
|
||||
CAST: "cast"
|
||||
, STOP: "stop"
|
||||
};
|
||||
|
||||
export const ReceiverAvailability = {
|
||||
AVAILABLE: "available"
|
||||
, UNAVAILABLE: "unavailable"
|
||||
};
|
||||
|
||||
export const ReceiverType = {
|
||||
CAST: "cast"
|
||||
, DIAL: "dial"
|
||||
, HANGOUT: "hangout"
|
||||
, CUSTOM: "custom"
|
||||
};
|
||||
|
||||
export const SenderPlatform = {
|
||||
CHROME: "chrome"
|
||||
, IOS: "ios"
|
||||
, ANDROID: "android"
|
||||
};
|
||||
|
||||
export const SessionStatus = {
|
||||
CONNECTED: "connected"
|
||||
, DISCONNECTED: "disconnected"
|
||||
, STOPPED: "stopped"
|
||||
};
|
||||
|
||||
export const VolumeControlType = {
|
||||
ATTENUATION: "attenuation"
|
||||
, FIXED: "fixed"
|
||||
, MASTER: "master"
|
||||
};
|
||||
"use strict";
|
||||
|
||||
export const AutoJoinPolicy = {
|
||||
TAB_AND_ORIGIN_SCOPED: "tab_and_origin_scoped"
|
||||
, ORIGIN_SCOPED: "origin_scoped"
|
||||
, PAGE_SCOPED: "page_scoped"
|
||||
, CUSTOM_CONTROLLER_SCOPED: "custom_controller_scoped"
|
||||
};
|
||||
|
||||
export const Capability = {
|
||||
VIDEO_OUT: "video_out"
|
||||
, AUDIO_OUT: "audio_out"
|
||||
, VIDEO_IN: "video_in"
|
||||
, AUDIO_IN: "audio_in"
|
||||
, MULTIZONE_GROUP: "multizone_group"
|
||||
};
|
||||
|
||||
export const DefaultActionPolicy = {
|
||||
CREATE_SESSION: "create_session"
|
||||
, CAST_THIS_TAB: "cast_this_tab"
|
||||
};
|
||||
|
||||
export const DialAppState = {
|
||||
RUNNING: "running"
|
||||
, STOPPED: "stopped"
|
||||
, ERROR: "error"
|
||||
};
|
||||
|
||||
export const ErrorCode = {
|
||||
CANCEL: "cancel"
|
||||
, TIMEOUT: "timeout"
|
||||
, API_NOT_INITIALIZED: "api_not_initialized"
|
||||
, INVALID_PARAMETER: "invalid_parameter"
|
||||
, EXTENSION_NOT_COMPATIBLE: "extension_not_compatible"
|
||||
, EXTENSION_MISSING: "extension_missing"
|
||||
, RECEIVER_UNAVAILABLE: "receiver_unavailable"
|
||||
, SESSION_ERROR: "session_error"
|
||||
, CHANNEL_ERROR: "channel_error"
|
||||
, LOAD_MEDIA_FAILED: "load_media_failed"
|
||||
};
|
||||
|
||||
export const ReceiverAction = {
|
||||
CAST: "cast"
|
||||
, STOP: "stop"
|
||||
};
|
||||
|
||||
export const ReceiverAvailability = {
|
||||
AVAILABLE: "available"
|
||||
, UNAVAILABLE: "unavailable"
|
||||
};
|
||||
|
||||
export const ReceiverType = {
|
||||
CAST: "cast"
|
||||
, DIAL: "dial"
|
||||
, HANGOUT: "hangout"
|
||||
, CUSTOM: "custom"
|
||||
};
|
||||
|
||||
export const SenderPlatform = {
|
||||
CHROME: "chrome"
|
||||
, IOS: "ios"
|
||||
, ANDROID: "android"
|
||||
};
|
||||
|
||||
export const SessionStatus = {
|
||||
CONNECTED: "connected"
|
||||
, DISCONNECTED: "disconnected"
|
||||
, STOPPED: "stopped"
|
||||
};
|
||||
|
||||
export const VolumeControlType = {
|
||||
ATTENUATION: "attenuation"
|
||||
, FIXED: "fixed"
|
||||
, MASTER: "master"
|
||||
};
|
||||
@@ -1,285 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import ApiConfig from "./classes/ApiConfig";
|
||||
import DialRequest from "./classes/DialRequest";
|
||||
import Error_ from "./classes/Error";
|
||||
import Image_ from "./classes/Image";
|
||||
import Receiver from "./classes/Receiver";
|
||||
import ReceiverDisplayStatus from "./classes/ReceiverDisplayStatus";
|
||||
import SenderApplication from "./classes/SenderApplication";
|
||||
import Session from "./classes/Session";
|
||||
import SessionRequest from "./classes/SessionRequest";
|
||||
import Timeout from "./classes/Timeout";
|
||||
import Volume from "./classes/Volume";
|
||||
|
||||
import { AutoJoinPolicy
|
||||
, Capability
|
||||
, DefaultActionPolicy
|
||||
, DialAppState
|
||||
, ErrorCode
|
||||
, ReceiverAction
|
||||
, ReceiverAvailability
|
||||
, ReceiverType
|
||||
, SenderPlatform
|
||||
, SessionStatus
|
||||
, VolumeControlType } from "./enums";
|
||||
|
||||
import { requestSession as requestSessionTimeout } from "../timeout";
|
||||
|
||||
import state from "../state";
|
||||
|
||||
import { onMessage, sendMessageResponse } from "../messageBridge";
|
||||
|
||||
|
||||
const cast = {
|
||||
// Enums
|
||||
AutoJoinPolicy
|
||||
, Capability
|
||||
, DefaultActionPolicy
|
||||
, DialAppState
|
||||
, ErrorCode
|
||||
, ReceiverAction
|
||||
, ReceiverAvailability
|
||||
, ReceiverType
|
||||
, SenderPlatform
|
||||
, SessionStatus
|
||||
, VolumeControlType
|
||||
|
||||
// Classes
|
||||
, ApiConfig
|
||||
, DialRequest
|
||||
, Error: Error_
|
||||
, Image: Image_
|
||||
, Receiver
|
||||
, ReceiverDisplayStatus
|
||||
, SenderApplication
|
||||
, Session
|
||||
, SessionRequest
|
||||
, Timeout
|
||||
, Volume
|
||||
|
||||
, timeout: new Timeout()
|
||||
, isAvailable: true
|
||||
, VERSION: [ 1, 2 ]
|
||||
};
|
||||
|
||||
|
||||
const receiverListeners = new Set();
|
||||
|
||||
let sessionSuccessCallback;
|
||||
let sessionErrorCallback;
|
||||
|
||||
|
||||
cast.addReceiverActionListener = (listener) => {
|
||||
console.info("fx_cast (Debug): cast.addReceiverActionListener");
|
||||
receiverListeners.add(listener);
|
||||
};
|
||||
|
||||
cast.initialize = (
|
||||
apiConfig
|
||||
, successCallback
|
||||
, errorCallback) => {
|
||||
|
||||
console.info("fx_cast (Debug): cast.initialize");
|
||||
|
||||
// Already initialized
|
||||
if (state.apiConfig) {
|
||||
errorCallback(new Error_(ErrorCode.RECEIVER_UNAVAILABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
state.apiConfig = apiConfig;
|
||||
|
||||
sendMessageResponse({
|
||||
subject: "bridge:/startDiscovery"
|
||||
});
|
||||
|
||||
apiConfig.receiverListener(state.receiverList.length
|
||||
? ReceiverAvailability.AVAILABLE
|
||||
: ReceiverAvailability.UNAVAILABLE);
|
||||
|
||||
successCallback();
|
||||
};
|
||||
|
||||
cast.logMessage = (message) => {
|
||||
console.log("CAST MSG:", message);
|
||||
};
|
||||
|
||||
cast.precache = (data) => {
|
||||
console.info("STUB :: cast.precache");
|
||||
};
|
||||
|
||||
cast.removeReceiverActionListener = (listener) => {
|
||||
receiverListeners.delete(listener);
|
||||
}
|
||||
|
||||
cast.requestSession = (
|
||||
successCallback
|
||||
, errorCallback
|
||||
, opt_sessionRequest = state.apiConfig.sessionRequest) => {
|
||||
|
||||
console.info("fx_cast (Debug): cast.requestSession");
|
||||
|
||||
// Called before initialization
|
||||
if (!state.apiConfig) {
|
||||
errorCallback(new Error_(ErrorCode.API_NOT_INITIALIZED));
|
||||
return;
|
||||
}
|
||||
|
||||
// Already requesting session
|
||||
if (state.sessionRequestInProgress) {
|
||||
errorCallback(new Error_(ErrorCode.INVALID_PARAMETER
|
||||
, "Session request already in progress."));
|
||||
return;
|
||||
}
|
||||
|
||||
// No available receivers
|
||||
if (!state.receiverList.length) {
|
||||
errorCallback(new Error_(ErrorCode.RECEIVER_UNAVAILABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
state.sessionRequestInProgress = true;
|
||||
|
||||
sessionSuccessCallback = successCallback;
|
||||
sessionErrorCallback = errorCallback;
|
||||
|
||||
// Open destination chooser
|
||||
sendMessageResponse({
|
||||
subject: "main:/openPopup"
|
||||
});
|
||||
};
|
||||
|
||||
cast.requestSessionById = (sessionId) => {
|
||||
console.info("STUB :: cast.requestSessionById");
|
||||
};
|
||||
|
||||
cast.setCustomReceivers = (receivers, successCallback, errorCallback) => {
|
||||
console.info("STUB :: cast.setCustomReceivers");
|
||||
};
|
||||
|
||||
cast.setPageContext = (win) => {
|
||||
console.info("STUB :: cast.setPageContext");
|
||||
};
|
||||
|
||||
cast.setReceiverDisplayStatus = (sessionId) => {
|
||||
console.info("STUB :: cast.setReceiverDisplayStatus");
|
||||
};
|
||||
|
||||
cast.unescape = (escaped) => unescape(escaped);
|
||||
|
||||
|
||||
onMessage(message => {
|
||||
switch (message.subject) {
|
||||
/**
|
||||
* Cast destination found (serviceUp). Set the API availability
|
||||
* property and call the page event function (__onGCastApiAvailable).
|
||||
*/
|
||||
case "shim:/serviceUp": {
|
||||
const receiver = message.data;
|
||||
|
||||
if (state.receiverList.find(r => r.id === receiver.id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
state.receiverList.push(receiver);
|
||||
|
||||
// Notify listeners of new cast destination
|
||||
state.apiConfig.receiverListener(ReceiverAvailability.AVAILABLE);
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cast destination lost (serviceDown). Remove from the receiver list
|
||||
* and update availability state.
|
||||
*/
|
||||
case "shim:/serviceDown": {
|
||||
state.receiverList = state.receiverList.filter(
|
||||
receiver => receiver.id !== message.data.id);
|
||||
|
||||
if (state.receiverList.length === 0) {
|
||||
state.apiConfig.receiverListener(
|
||||
ReceiverAvailability.UNAVAILABLE);
|
||||
}
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
case "shim:/selectReceiver": {
|
||||
console.info("fx_cast (Debug): Selected receiver");
|
||||
|
||||
const selectedReceiver = new Receiver(
|
||||
message.data.receiver.id
|
||||
, message.data.receiver.friendlyName);
|
||||
|
||||
selectedReceiver._address = message.data.receiver.address;
|
||||
selectedReceiver._port = message.data.receiver.port;
|
||||
|
||||
const sessionConstructorArgs = [
|
||||
state.sessionList.length // sessionId
|
||||
, state.apiConfig.sessionRequest.appId // appId
|
||||
, selectedReceiver.friendlyName // displayName
|
||||
, [] // appImages
|
||||
, selectedReceiver // receiver
|
||||
, (session) => {
|
||||
sendMessageResponse({
|
||||
subject: "popup:/close"
|
||||
});
|
||||
|
||||
state.apiConfig.sessionListener(session);
|
||||
state.sessionRequestInProgress = false;
|
||||
sessionSuccessCallback(session, message.data.selectedMedia);
|
||||
}
|
||||
];
|
||||
|
||||
// If existing session active, stop it and start new one
|
||||
if (state.sessionList.length) {
|
||||
const lastSession
|
||||
= state.sessionList[state.sessionList.length - 1];
|
||||
|
||||
if (lastSession.status !== SessionStatus.STOPPED) {
|
||||
lastSession.stop(() => {
|
||||
state.sessionList.push(new Session(
|
||||
...sessionConstructorArgs));
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
state.sessionList.push(new Session(...sessionConstructorArgs));
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
/**
|
||||
* Popup is ready to receive data to populate the cast destination
|
||||
* chooser.
|
||||
*/
|
||||
case "shim:/popupReady": {
|
||||
sendMessageResponse({
|
||||
subject: "popup:/populateReceiverList"
|
||||
, data: {
|
||||
receivers: state.receiverList
|
||||
, selectedMedia: state.apiConfig._selectedMedia
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
/**
|
||||
* Popup closed before session established.
|
||||
*/
|
||||
case "shim:/popupClosed": {
|
||||
if (state.sessionRequestInProgress) {
|
||||
state.sessionRequestInProgress = false;
|
||||
sessionErrorCallback(new Error_(ErrorCode.CANCEL));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default cast;
|
||||
288
ext/src/shim/cast/index.ts
Executable file
288
ext/src/shim/cast/index.ts
Executable file
@@ -0,0 +1,288 @@
|
||||
"use strict";
|
||||
|
||||
import ApiConfig from "./classes/ApiConfig";
|
||||
import DialRequest from "./classes/DialRequest";
|
||||
import Error_ from "./classes/Error";
|
||||
import Image_ from "./classes/Image";
|
||||
import Receiver from "./classes/Receiver";
|
||||
import ReceiverDisplayStatus from "./classes/ReceiverDisplayStatus";
|
||||
import SenderApplication from "./classes/SenderApplication";
|
||||
import Session from "./classes/Session";
|
||||
import SessionRequest from "./classes/SessionRequest";
|
||||
import Timeout from "./classes/Timeout";
|
||||
import Volume from "./classes/Volume";
|
||||
|
||||
import { AutoJoinPolicy
|
||||
, Capability
|
||||
, DefaultActionPolicy
|
||||
, DialAppState
|
||||
, ErrorCode
|
||||
, ReceiverAction
|
||||
, ReceiverAvailability
|
||||
, ReceiverType
|
||||
, SenderPlatform
|
||||
, SessionStatus
|
||||
, VolumeControlType } from "./enums";
|
||||
|
||||
|
||||
import { requestSession as requestSessionTimeout } from "../timeout";
|
||||
|
||||
import { onMessage, sendMessageResponse } from "../messageBridge";
|
||||
|
||||
|
||||
|
||||
type ReceiverActionListener = (
|
||||
receiver: Receiver
|
||||
, receiverAction: typeof ReceiverAction) => void;
|
||||
|
||||
type RequestSessionSuccessCallback = (session: Session, selectedMedia: string) => void;
|
||||
|
||||
type SuccessCallback = () => void;
|
||||
type ErrorCallback = (err: Error_) => void;
|
||||
|
||||
|
||||
let apiConfig: ApiConfig;
|
||||
let receiverList: any[] = [];
|
||||
let sessionList: Session[] = [];
|
||||
let sessionRequestInProgress = false;
|
||||
|
||||
let receiverListeners = new Set<ReceiverActionListener>();
|
||||
|
||||
let sessionSuccessCallback: RequestSessionSuccessCallback;
|
||||
let sessionErrorCallback: ErrorCallback;
|
||||
|
||||
export default {
|
||||
// Enums
|
||||
AutoJoinPolicy, Capability, DefaultActionPolicy, DialAppState
|
||||
, ErrorCode, ReceiverAction, ReceiverAvailability, ReceiverType
|
||||
, SenderPlatform, SessionStatus, VolumeControlType
|
||||
|
||||
// Classes
|
||||
, ApiConfig, DialRequest, Error: Error_, Image: Image_
|
||||
, Receiver, ReceiverDisplayStatus, SenderApplication, Session
|
||||
, SessionRequest, Timeout, Volume
|
||||
|
||||
, VERSION: [1, 2]
|
||||
, isAvailable: false
|
||||
, timeout: new Timeout()
|
||||
|
||||
|
||||
, addReceiverActionListener: (
|
||||
listener: ReceiverActionListener): void => {
|
||||
|
||||
console.info("fx_cast (Debug): cast.addReceiverActionListener");
|
||||
receiverListeners.add(listener);
|
||||
}
|
||||
|
||||
, initialize: (
|
||||
newApiConfig: ApiConfig
|
||||
, successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback): void => {
|
||||
|
||||
console.info("fx_cast (Debug): cast.initialize");
|
||||
|
||||
// Already initialized
|
||||
if (apiConfig) {
|
||||
errorCallback(new Error_(ErrorCode.RECEIVER_UNAVAILABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
apiConfig = newApiConfig;
|
||||
|
||||
sendMessageResponse({
|
||||
subject: "bridge:/startDiscovery"
|
||||
});
|
||||
|
||||
console.log(receiverList.length)
|
||||
|
||||
apiConfig.receiverListener(receiverList.length
|
||||
? ReceiverAvailability.AVAILABLE
|
||||
: ReceiverAvailability.UNAVAILABLE);
|
||||
|
||||
successCallback();
|
||||
}
|
||||
|
||||
, logMessage: (message: string): void => {
|
||||
console.log("CAST MSG:", message);
|
||||
}
|
||||
|
||||
, precache: (data: string): void => {
|
||||
console.info("STUB :: cast.precache");
|
||||
}
|
||||
|
||||
, removeReceiverActionListener: (
|
||||
listener: ReceiverActionListener): void => {
|
||||
|
||||
receiverListeners.delete(listener);
|
||||
}
|
||||
|
||||
, requestSession: (
|
||||
successCallback: RequestSessionSuccessCallback
|
||||
, errorCallback: ErrorCallback
|
||||
, sessionRequest: SessionRequest = apiConfig.sessionRequest): void => {
|
||||
|
||||
console.info("fx_cast (Debug): cast.requestSession");
|
||||
|
||||
// Called before initialization
|
||||
if (!apiConfig) {
|
||||
errorCallback(new Error_(ErrorCode.API_NOT_INITIALIZED));
|
||||
return;
|
||||
}
|
||||
|
||||
// Already requesting session
|
||||
if (sessionRequestInProgress) {
|
||||
errorCallback(new Error_(ErrorCode.INVALID_PARAMETER
|
||||
, "Session request already in progress."));
|
||||
return;
|
||||
}
|
||||
|
||||
// No available receivers
|
||||
if (!receiverList.length) {
|
||||
errorCallback(new Error_(ErrorCode.RECEIVER_UNAVAILABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
sessionRequestInProgress = true;
|
||||
|
||||
sessionSuccessCallback = successCallback;
|
||||
sessionErrorCallback = errorCallback;
|
||||
|
||||
// Open destination chooser
|
||||
sendMessageResponse({
|
||||
subject: "main:/openPopup"
|
||||
});
|
||||
}
|
||||
|
||||
, requestSessionById: (sessionId: string): void => {
|
||||
console.info("STUB :: cast.requestSessionById");
|
||||
}
|
||||
|
||||
, setCustomReceivers: (
|
||||
receivers: Receiver[]
|
||||
, successCallback: SuccessCallback
|
||||
, errorCallback: ErrorCallback): void => {
|
||||
|
||||
console.info("STUB :: cast.setCustomReceivers");
|
||||
}
|
||||
|
||||
, setPageContext: (win: Window): void => {
|
||||
console.info("STUB :: cast.setPageContext");
|
||||
}
|
||||
|
||||
, setReceiverDisplayStatus: (sessionId: string): void => {
|
||||
console.info("STUB :: cast.setReceiverDisplayStatus");
|
||||
}
|
||||
|
||||
, unescape: (escaped: string): string => {
|
||||
return unescape(escaped);
|
||||
}
|
||||
}
|
||||
|
||||
onMessage(message => {
|
||||
switch (message.subject) {
|
||||
/**
|
||||
* Cast destination found (serviceUp). Set the API availability
|
||||
* property and call the page event function (__onGCastApiAvailable).
|
||||
*/
|
||||
case "shim:/serviceUp": {
|
||||
const receiver = message.data;
|
||||
|
||||
if (receiverList.find(r => r.id === receiver.id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
receiverList.push(receiver);
|
||||
|
||||
// Notify listeners of new cast destination
|
||||
apiConfig.receiverListener(ReceiverAvailability.AVAILABLE);
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cast destination lost (serviceDown). Remove from the receiver list
|
||||
* and update availability state.
|
||||
*/
|
||||
case "shim:/serviceDown": {
|
||||
receiverList = receiverList.filter(
|
||||
receiver => receiver.id !== message.data.id);
|
||||
|
||||
if (receiverList.length === 0) {
|
||||
apiConfig.receiverListener(
|
||||
ReceiverAvailability.UNAVAILABLE);
|
||||
}
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
case "shim:/selectReceiver": {
|
||||
console.info("fx_cast (Debug): Selected receiver");
|
||||
|
||||
const selectedReceiver = new Receiver(
|
||||
message.data.receiver.id
|
||||
, message.data.receiver.friendlyName);
|
||||
|
||||
(selectedReceiver as any)._address = message.data.receiver.address;
|
||||
(selectedReceiver as any)._port = message.data.receiver.port;
|
||||
|
||||
function createSession () {
|
||||
sessionList.push(new Session(
|
||||
sessionList.length.toString() // sessionId
|
||||
, apiConfig.sessionRequest.appId // appId
|
||||
, selectedReceiver.friendlyName // displayName
|
||||
, [] // appImages
|
||||
, selectedReceiver // receiver
|
||||
, (session: Session) => {
|
||||
sendMessageResponse({
|
||||
subject: "popup:/close"
|
||||
});
|
||||
|
||||
apiConfig.sessionListener(session);
|
||||
sessionRequestInProgress = false;
|
||||
sessionSuccessCallback(session, message.data.selectedMedia);
|
||||
}));
|
||||
}
|
||||
|
||||
// If an existing session is active, stop it and start new one
|
||||
if (sessionList.length) {
|
||||
const lastSession = sessionList[sessionList.length - 1];
|
||||
|
||||
if (lastSession.status !== SessionStatus.STOPPED) {
|
||||
lastSession.stop(createSession, null);
|
||||
}
|
||||
} else {
|
||||
createSession();
|
||||
}
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
/**
|
||||
* Popup is ready to receive data to populate the cast destination
|
||||
* chooser.
|
||||
*/
|
||||
case "shim:/popupReady": {
|
||||
sendMessageResponse({
|
||||
subject: "popup:/populateReceiverList"
|
||||
, data: {
|
||||
receivers: receiverList
|
||||
, selectedMedia: apiConfig._selectedMedia
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
/**
|
||||
* Popup closed before session established.
|
||||
*/
|
||||
case "shim:/popupClosed": {
|
||||
if (sessionRequestInProgress) {
|
||||
sessionRequestInProgress = false;
|
||||
sessionErrorCallback(new Error_(ErrorCode.CANCEL));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user