react-chromecast-caf 0.0.3 → 0.0.4
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/dist/index.d.ts +1 -0
- package/dist/index.js +76 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/useChromecastCafReceiver.js +0 -42
- package/dist/useChromecastCafReceiver.js.map +0 -1
- package/dist/useChromecastCafSender.js +0 -39
- package/dist/useChromecastCafSender.js.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const load$1 = (() => {
|
|
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({
|
|
31
|
+
cast: null,
|
|
32
|
+
});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
load$1().then((sender) => {
|
|
35
|
+
setReceiver(sender);
|
|
36
|
+
});
|
|
37
|
+
}, []);
|
|
38
|
+
return receiver;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const load = (() => {
|
|
42
|
+
let promise = null;
|
|
43
|
+
return () => {
|
|
44
|
+
if (promise === null) {
|
|
45
|
+
promise = new Promise((resolve) => {
|
|
46
|
+
const script = document.createElement('script');
|
|
47
|
+
script.src =
|
|
48
|
+
'https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1';
|
|
49
|
+
window.__onGCastApiAvailable = (isAvailable) => {
|
|
50
|
+
if (isAvailable) {
|
|
51
|
+
resolve({
|
|
52
|
+
chrome,
|
|
53
|
+
cast,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
document.body.appendChild(script);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return promise;
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
const useChromecastCafSender = () => {
|
|
64
|
+
const [sender, setSender] = useState({
|
|
65
|
+
chrome: null,
|
|
66
|
+
cast: null,
|
|
67
|
+
});
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
load().then((sender) => {
|
|
70
|
+
setSender(sender);
|
|
71
|
+
});
|
|
72
|
+
}, []);
|
|
73
|
+
return sender;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { useChromecastCafReceiver, useChromecastCafSender };
|
|
3
77
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/useChromecastCafReceiver.ts","../src/useChromecastCafSender.ts"],"sourcesContent":["import { type Cast } from 'chromecast-caf-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 | { cast: null }>({\n\t\tcast: null,\n\t})\n\n\tuseEffect(() => {\n\t\tload().then((sender) => {\n\t\t\tsetReceiver(sender)\n\t\t})\n\t}, [])\n\n\treturn receiver\n}\n","import type { Cast, Chrome } from 'chromecast-caf-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<\n\t\t| Sender\n\t\t| {\n\t\t\t\tchrome: null\n\t\t\t\tcast: null\n\t\t }\n\t>({\n\t\tchrome: null,\n\t\tcast: null,\n\t})\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":["load"],"mappings":";;AAOA,MAAMA,MAAI,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;AAC5C,IAAA,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAA4B;AACnE,QAAA,IAAI,EAAE,IAAI;AACV,KAAA,CAAC;IAEF,SAAS,CAAC,MAAK;AACd,QAAAA,MAAI,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;;ACxCA,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;AAC1C,IAAA,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAMlC;AACD,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,IAAI,EAAE,IAAI;AACV,KAAA,CAAC;IAEF,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
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
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({
|
|
31
|
-
cast: null,
|
|
32
|
-
});
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
load().then((sender) => {
|
|
35
|
-
setReceiver(sender);
|
|
36
|
-
});
|
|
37
|
-
}, []);
|
|
38
|
-
return receiver;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { useChromecastCafReceiver };
|
|
42
|
-
//# sourceMappingURL=useChromecastCafReceiver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useChromecastCafReceiver.js","sources":["../src/useChromecastCafReceiver.ts"],"sourcesContent":["import { type Cast } from 'chromecast-caf-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 | { cast: null }>({\n\t\tcast: null,\n\t})\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;AAC5C,IAAA,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAA4B;AACnE,QAAA,IAAI,EAAE,IAAI;AACV,KAAA,CAAC;IAEF,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;;;;"}
|
|
@@ -1,39 +0,0 @@
|
|
|
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({
|
|
27
|
-
chrome: null,
|
|
28
|
-
cast: null,
|
|
29
|
-
});
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
load().then((sender) => {
|
|
32
|
-
setSender(sender);
|
|
33
|
-
});
|
|
34
|
-
}, []);
|
|
35
|
-
return sender;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export { useChromecastCafSender };
|
|
39
|
-
//# sourceMappingURL=useChromecastCafSender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useChromecastCafSender.js","sources":["../src/useChromecastCafSender.ts"],"sourcesContent":["import type { Cast, Chrome } from 'chromecast-caf-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<\n\t\t| Sender\n\t\t| {\n\t\t\t\tchrome: null\n\t\t\t\tcast: null\n\t\t }\n\t>({\n\t\tchrome: null,\n\t\tcast: null,\n\t})\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;AAC1C,IAAA,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAMlC;AACD,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,IAAI,EAAE,IAAI;AACV,KAAA,CAAC;IAEF,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;;;;"}
|