diff --git a/ext/src/shim/cast/classes/Session.js b/ext/src/shim/cast/classes/Session.js index fd30632..f1bbc15 100755 --- a/ext/src/shim/cast/classes/Session.js +++ b/ext/src/shim/cast/classes/Session.js @@ -32,7 +32,7 @@ export default class Session { this._stopCallbacks = new Map(); this.sessionId = sessionId; - this.transportId = sessionId; + this.transportId = sessionId || ""; this.appId = appId; this.appImages = appImages; this.displayName = displayName; @@ -41,16 +41,17 @@ export default class Session { this.media = []; this.namespaces = []; this.senderApps = []; - this.status = SessionStatus.DISCONNECTED; + this.status = SessionStatus.CONNECTED; this.statusText = null; - this._sendMessage("bridge:bridgesession/initialize", { - address: receiver._address - , port: receiver._port - , appId - , sessionId - }); - + if (receiver) { + this._sendMessage("bridge:bridgesession/initialize", { + address: receiver._address + , port: receiver._port + , appId + , sessionId + }); + } onMessage(message => { // Filter other session messages diff --git a/ext/src/shim/cast/classes/SessionRequest.js b/ext/src/shim/cast/classes/SessionRequest.js index 69cc3eb..f9ce68b 100755 --- a/ext/src/shim/cast/classes/SessionRequest.js +++ b/ext/src/shim/cast/classes/SessionRequest.js @@ -1,20 +1,21 @@ -"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 = null) { - - this.appId = appId; - this.capabilities = opt_capabilities; - this.language = null; - this.requestSessionTimeout = requestSessionTimeout; - } -}; +"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; + } +}; diff --git a/test/spec/shim/cast/ReceiverDisplayStatus.spec.js b/test/spec/shim/cast/ReceiverDisplayStatus.spec.js index 93efd0f..125bff5 100644 --- a/test/spec/shim/cast/ReceiverDisplayStatus.spec.js +++ b/test/spec/shim/cast/ReceiverDisplayStatus.spec.js @@ -1,6 +1,6 @@ "use strict"; -describe("chrome.cast.Receiver", () => { +describe("chrome.cast.ReceiverDisplayStatus", () => { it("should have all properties", async () => { const receiverDisplayStatus = new chrome.cast.ReceiverDisplayStatus(); diff --git a/test/spec/shim/cast/SenderApplication.spec.js b/test/spec/shim/cast/SenderApplication.spec.js index e69de29..efe8ef8 100644 --- a/test/spec/shim/cast/SenderApplication.spec.js +++ b/test/spec/shim/cast/SenderApplication.spec.js @@ -0,0 +1,18 @@ +"use strict"; + +describe("chrome.cast.SenderApplication", () => { + it("should have all properties", async () => { + const senderApplication = new chrome.cast.SenderApplication(); + + expect(senderApplication.platform).toBe(undefined); + expect(senderApplication.url).toBe(null); + expect(senderApplication.packageId).toBe(null); + }); + + it("should have expected assigned properties", async () => { + const senderApplication = new chrome.cast.SenderApplication( + chrome.cast.SenderPlatform.CHROME); + + expect(senderApplication.platform).toBe("chrome"); + }); +}); diff --git a/test/spec/shim/cast/Session.spec.js b/test/spec/shim/cast/Session.spec.js index e69de29..2cdf9e8 100644 --- a/test/spec/shim/cast/Session.spec.js +++ b/test/spec/shim/cast/Session.spec.js @@ -0,0 +1,36 @@ +"use strict"; + +describe("chrome.cast.Session", () => { + it("should have all properties", async () => { + const session = new chrome.cast.Session(); + + expect(session.appId).toBe(undefined); + expect(session.appImages).toBe(undefined); + expect(session.displayName).toBe(undefined); + expect(session.media).toEqual([]); + expect(session.namespaces).toEqual([]); + expect(session.receiver).toBe(undefined); + expect(session.senderApps).toEqual([]); + expect(session.sessionId).toBe(undefined); + expect(session.status).toBe("connected"); + expect(session.statusText).toBe(null); + expect(session.transportId).toBe(""); + }); + + it("should have expected assigned properties", async () => { + const session = new chrome.cast.Session( + "__sessionId" + , "__appId" + , "__displayName" + , [ new chrome.cast.Image("http://example.com") ] + , new chrome.cast.Receiver("__label", "__friendlyName")); + + expect(session.appId).toBe("__appId"); + expect(session.appImages).toEqual(jasmine.arrayContaining([ + jasmine.objectContaining({ url: "http://example.com" }) + ])); + expect(session.displayName).toBe("__displayName"); + expect(session.receiver).toEqual(jasmine.any(chrome.cast.Receiver)); + expect(session.sessionId).toBe("__sessionId"); + }); +}); diff --git a/test/spec/shim/cast/SessionRequest.spec.js b/test/spec/shim/cast/SessionRequest.spec.js index e69de29..af41ff4 100644 --- a/test/spec/shim/cast/SessionRequest.spec.js +++ b/test/spec/shim/cast/SessionRequest.spec.js @@ -0,0 +1,25 @@ +"use strict"; + +describe("chrome.cast.SessionRequest", () => { + it("should have all properties", async () => { + const sessionRequest = new chrome.cast.SessionRequest(); + + expect(sessionRequest.appId).toBe(undefined); + expect(sessionRequest.capabilities).toEqual([ "video_out", "audio_out" ]); + expect(sessionRequest.dialRequest).toBe(null); + expect(sessionRequest.language).toBe(null); + expect(sessionRequest.requestSessionTimeout).toBe(60000); + }); + + it("should have expected assigned properties", async () => { + const sessionRequest = new chrome.cast.SessionRequest( + "__appId" + , [ chrome.cast.Capability.VIDEO_OUT + , chrome.cast.Capability.AUDIO_IN ] + , 5000); + + expect(sessionRequest.appId).toBe("__appId"); + expect(sessionRequest.capabilities).toEqual([ "video_out", "audio_in" ]); + expect(sessionRequest.requestSessionTimeout).toBe(5000); + }); +}); diff --git a/test/spec/shim/cast/Timeout.spec.js b/test/spec/shim/cast/Timeout.spec.js index e69de29..b449c6c 100644 --- a/test/spec/shim/cast/Timeout.spec.js +++ b/test/spec/shim/cast/Timeout.spec.js @@ -0,0 +1,13 @@ +"use strict"; + +describe("chrome.cast.Timeout", () => { + it("should have all properties", async () => { + const timeout = new chrome.cast.Timeout(); + + expect(timeout.leaveSession).toBe(3000); + expect(timeout.requestSession).toBe(60000); + expect(timeout.sendCustomMessage).toBe(3000); + expect(timeout.setReceiverVolume).toBe(3000); + expect(timeout.stopSession).toBe(3000); + }); +}); diff --git a/test/spec/shim/cast/Volume.spec.js b/test/spec/shim/cast/Volume.spec.js index e69de29..e0b4eb1 100644 --- a/test/spec/shim/cast/Volume.spec.js +++ b/test/spec/shim/cast/Volume.spec.js @@ -0,0 +1,17 @@ +"use strict"; + +describe("chrome.cast.Volume", () => { + it("should have all properties", async () => { + const volume = new chrome.cast.Volume(); + + expect(volume.level).toBe(null); + expect(volume.muted).toBe(null); + }); + + it("should have expected assigned properties", async () => { + const volume = new chrome.cast.Volume(0.5, false); + + expect(volume.level).toBe(0.5); + expect(volume.muted).toBe(false); + }); +});