|
| 1 | +function _castSender(dispatch, props) { |
| 2 | + var applicationID = '05C10F57'; |
| 3 | + var session = null; |
| 4 | + |
| 5 | + function bail(e) { |
| 6 | + console.log("cast error", e); |
| 7 | + dispatch((state) => ({...state, casting: false})); |
| 8 | + } |
| 9 | + |
| 10 | + var apiConfig = new chrome.cast.ApiConfig( |
| 11 | + new chrome.cast.SessionRequest(applicationID), |
| 12 | + function (s) { console.log("session", s); }, // session listener |
| 13 | + function (r) { console.log("receiver", r); }, // receiver listener |
| 14 | + ); |
| 15 | + chrome.cast.initialize( |
| 16 | + apiConfig, |
| 17 | + function () { }, // ok |
| 18 | + function (e) { bail(e); }, // err |
| 19 | + ); |
| 20 | + chrome.cast.requestSession( |
| 21 | + function (s) { |
| 22 | + session = s; |
| 23 | + session.setReceiverMuted(false); |
| 24 | + session.setReceiverVolumeLevel(1.00); |
| 25 | + session.sendMessage('urn:x-cast:uk.karakara', { |
| 26 | + "command": "join", |
| 27 | + "room_name": props.room_name, |
| 28 | + "room_password": props.room_password, |
| 29 | + }); |
| 30 | + }, |
| 31 | + function (e) {bail(e);} |
| 32 | + ); |
| 33 | + |
| 34 | + return function () { |
| 35 | + if (session) { |
| 36 | + session.stop( |
| 37 | + function () { session = null; }, |
| 38 | + function (e) { console.log("session stop err", e); }, |
| 39 | + ); |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +export function CastSender(name, pass): Subscription { |
| 45 | + return [_castSender, { room_name: name, room_password: pass }]; |
| 46 | +} |
0 commit comments