react-chromecast-caf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Use Chromecast sender [![npm](https://img.shields.io/npm/v/use-chromecast-caf-sender.svg)](https://www.npmjs.com/package/use-chromecast-caf-sender) ![npm type definitions](https://img.shields.io/npm/types/use-chromecast-caf-sender.svg)
2
+
3
+ React hook to use the [Chromecast sender SDK](https://developers.google.com/cast/docs/web_sender/integrate) in your project.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install use-chromecast-caf-sender
9
+ ```
10
+
11
+ ## How to use
12
+
13
+ ```jsx
14
+ import { useChromecastSender } from 'use-chromecast-caf-sender'
15
+
16
+ const Component = () => {
17
+ const { cast } = useChromecastSender()
18
+
19
+ return <div>{cast === null ? 'Loading' : 'Cast sender sdk is loaded'}</div>
20
+ }
21
+ ```
22
+
23
+ ## Development
24
+
25
+ - Install dependencies: `npm ci`
26
+ - Build the package: `npm run dev`
@@ -0,0 +1,2 @@
1
+ export * from './useChromecastCafReceiver';
2
+ export * from './useChromecastCafSender';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { useChromecastCafReceiver } from './useChromecastCafReceiver.js';
2
+ export { useChromecastCafSender } from './useChromecastCafSender.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,6 @@
1
+ import { type Cast } from 'cast-receiver-module';
2
+ type Receiver = {
3
+ cast: Cast;
4
+ };
5
+ export declare const useChromecastCafReceiver: () => Receiver | null;
6
+ export {};
@@ -0,0 +1,40 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ const load = (() => {
4
+ let promise = null;
5
+ return () => {
6
+ if (promise === null) {
7
+ promise = new Promise((resolve) => {
8
+ const script = document.createElement('script');
9
+ script.src =
10
+ 'https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js';
11
+ document.body.appendChild(script);
12
+ const loop = () => {
13
+ if ('cast' in window && 'framework' in cast) {
14
+ resolve({
15
+ cast,
16
+ });
17
+ return;
18
+ }
19
+ setTimeout(() => {
20
+ loop();
21
+ }, 100);
22
+ };
23
+ loop();
24
+ });
25
+ }
26
+ return promise;
27
+ };
28
+ })();
29
+ const useChromecastCafReceiver = () => {
30
+ const [receiver, setReceiver] = useState(null);
31
+ useEffect(() => {
32
+ load().then((sender) => {
33
+ setReceiver(sender);
34
+ });
35
+ }, []);
36
+ return receiver;
37
+ };
38
+
39
+ export { useChromecastCafReceiver };
40
+ //# sourceMappingURL=useChromecastCafReceiver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChromecastCafReceiver.js","sources":["../src/useChromecastCafReceiver.ts"],"sourcesContent":["import { type Cast } from 'cast-receiver-module'\nimport { useEffect, useState } from 'react'\n\ntype Receiver = {\n\tcast: Cast\n}\n\nconst load = (() => {\n\tlet promise: Promise<Receiver> | null = null\n\n\treturn () => {\n\t\tif (promise === null) {\n\t\t\tpromise = new Promise((resolve) => {\n\t\t\t\tconst script = document.createElement('script')\n\t\t\t\tscript.src =\n\t\t\t\t\t'https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js'\n\t\t\t\tdocument.body.appendChild(script)\n\n\t\t\t\tconst loop = () => {\n\t\t\t\t\tif ('cast' in window && 'framework' in cast) {\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tcast,\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tloop()\n\t\t\t\t\t}, 100)\n\t\t\t\t}\n\t\t\t\tloop()\n\t\t\t})\n\t\t}\n\t\treturn promise\n\t}\n})()\n\nexport const useChromecastCafReceiver = () => {\n\tconst [receiver, setReceiver] = useState<Receiver | null>(null)\n\n\tuseEffect(() => {\n\t\tload().then((sender) => {\n\t\t\tsetReceiver(sender)\n\t\t})\n\t}, [])\n\n\treturn receiver\n}\n"],"names":[],"mappings":";;AAOA,MAAM,IAAI,GAAG,CAAC,MAAK;IAClB,IAAI,OAAO,GAA6B,IAAI;AAE5C,IAAA,OAAO,MAAK;AACX,QAAA,IAAI,OAAO,KAAK,IAAI,EAAE;AACrB,YAAA,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;gBACjC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,gBAAA,MAAM,CAAC,GAAG;AACT,oBAAA,kFAAkF;AACnF,gBAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;gBAEjC,MAAM,IAAI,GAAG,MAAK;oBACjB,IAAI,MAAM,IAAI,MAAM,IAAI,WAAW,IAAI,IAAI,EAAE;AAC5C,wBAAA,OAAO,CAAC;4BACP,IAAI;AACJ,yBAAA,CAAC;wBACF;oBACD;oBACA,UAAU,CAAC,MAAK;AACf,wBAAA,IAAI,EAAE;oBACP,CAAC,EAAE,GAAG,CAAC;AACR,gBAAA,CAAC;AACD,gBAAA,IAAI,EAAE;AACP,YAAA,CAAC,CAAC;QACH;AACA,QAAA,OAAO,OAAO;AACf,IAAA,CAAC;AACF,CAAC,GAAG;AAEG,MAAM,wBAAwB,GAAG,MAAK;IAC5C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAkB,IAAI,CAAC;IAE/D,SAAS,CAAC,MAAK;AACd,QAAA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;YACtB,WAAW,CAAC,MAAM,CAAC;AACpB,QAAA,CAAC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,OAAO,QAAQ;AAChB;;;;"}
@@ -0,0 +1,7 @@
1
+ import type { Cast, Chrome } from 'cast-sender-module';
2
+ type Sender = {
3
+ chrome: Chrome;
4
+ cast: Cast;
5
+ };
6
+ export declare const useChromecastCafSender: () => Sender | null;
7
+ export {};
@@ -0,0 +1,36 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ const load = (() => {
4
+ let promise = null;
5
+ return () => {
6
+ if (promise === null) {
7
+ promise = new Promise((resolve) => {
8
+ const script = document.createElement('script');
9
+ script.src =
10
+ 'https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1';
11
+ window.__onGCastApiAvailable = (isAvailable) => {
12
+ if (isAvailable) {
13
+ resolve({
14
+ chrome,
15
+ cast,
16
+ });
17
+ }
18
+ };
19
+ document.body.appendChild(script);
20
+ });
21
+ }
22
+ return promise;
23
+ };
24
+ })();
25
+ const useChromecastCafSender = () => {
26
+ const [sender, setSender] = useState(null);
27
+ useEffect(() => {
28
+ load().then((sender) => {
29
+ setSender(sender);
30
+ });
31
+ }, []);
32
+ return sender;
33
+ };
34
+
35
+ export { useChromecastCafSender };
36
+ //# sourceMappingURL=useChromecastCafSender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChromecastCafSender.js","sources":["../src/useChromecastCafSender.ts"],"sourcesContent":["import type { Cast, Chrome } from 'cast-sender-module'\nimport { useEffect, useState } from 'react'\n\ntype Sender = {\n\tchrome: Chrome\n\tcast: Cast\n}\n\nconst load = (() => {\n\tlet promise: Promise<Sender> | null = null\n\n\treturn () => {\n\t\tif (promise === null) {\n\t\t\tpromise = new Promise((resolve) => {\n\t\t\t\tconst script = document.createElement('script')\n\t\t\t\tscript.src =\n\t\t\t\t\t'https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1'\n\t\t\t\twindow.__onGCastApiAvailable = (isAvailable) => {\n\t\t\t\t\tif (isAvailable) {\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tchrome,\n\t\t\t\t\t\t\tcast,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdocument.body.appendChild(script)\n\t\t\t})\n\t\t}\n\t\treturn promise\n\t}\n})()\n\nexport const useChromecastCafSender = () => {\n\tconst [sender, setSender] = useState<Sender | null>(null)\n\n\tuseEffect(() => {\n\t\tload().then((sender) => {\n\t\t\tsetSender(sender)\n\t\t})\n\t}, [])\n\n\treturn sender\n}\n"],"names":[],"mappings":";;AAQA,MAAM,IAAI,GAAG,CAAC,MAAK;IAClB,IAAI,OAAO,GAA2B,IAAI;AAE1C,IAAA,OAAO,MAAK;AACX,QAAA,IAAI,OAAO,KAAK,IAAI,EAAE;AACrB,YAAA,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;gBACjC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,gBAAA,MAAM,CAAC,GAAG;AACT,oBAAA,4EAA4E;AAC7E,gBAAA,MAAM,CAAC,qBAAqB,GAAG,CAAC,WAAW,KAAI;oBAC9C,IAAI,WAAW,EAAE;AAChB,wBAAA,OAAO,CAAC;4BACP,MAAM;4BACN,IAAI;AACJ,yBAAA,CAAC;oBACH;AACD,gBAAA,CAAC;AACD,gBAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;AAClC,YAAA,CAAC,CAAC;QACH;AACA,QAAA,OAAO,OAAO;AACf,IAAA,CAAC;AACF,CAAC,GAAG;AAEG,MAAM,sBAAsB,GAAG,MAAK;IAC1C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC;IAEzD,SAAS,CAAC,MAAK;AACd,QAAA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;YACtB,SAAS,CAAC,MAAM,CAAC;AAClB,QAAA,CAAC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,OAAO,MAAM;AACd;;;;"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "react-chromecast-caf",
3
+ "version": "0.0.1",
4
+ "description": "React hooks to use the Chromecast sender and receiver SDK in your project.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "start": "rollup -c -w",
16
+ "dev": "npm start",
17
+ "build": "rollup -c",
18
+ "prepare": "npm run build"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/FilipChalupa/react-chromecast-caf.git"
23
+ },
24
+ "keywords": [
25
+ "chromecast",
26
+ "sender",
27
+ "receiver",
28
+ "typescript",
29
+ "react"
30
+ ],
31
+ "author": {
32
+ "name": "Filip Chalupa",
33
+ "email": "chalupa.filip@gmail.com",
34
+ "url": "https://www.npmjs.com/~onset"
35
+ },
36
+ "license": "ISC",
37
+ "peerDependencies": {
38
+ "react": "18 || 19"
39
+ },
40
+ "files": [
41
+ "/dist/"
42
+ ],
43
+ "devDependencies": {
44
+ "@rollup/plugin-commonjs": "^25.0.8",
45
+ "@rollup/plugin-node-resolve": "^15.0.1",
46
+ "@types/react": "^18.0.26",
47
+ "react": "^18.2.0",
48
+ "rollup": "^4.59.0",
49
+ "rollup-plugin-delete": "^3.0.2",
50
+ "rollup-plugin-peer-deps-external": "^2.2.4",
51
+ "rollup-plugin-typescript2": "^0.36.0",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "dependencies": {
55
+ "@types/chromecast-caf-receiver": "^6.0.25",
56
+ "@types/chromecast-caf-sender": "^1.0.11",
57
+ "tslib": "^2.8.1"
58
+ }
59
+ }