// @ts-nocheck // import { RCRLaunch, Keyboard, Launcher } from '../dist/ecloud-rcr.esm.min'; import { RCRLaunch, Keyboard, Launcher } from '../src/index' import $ from 'jquery' const KEY_CODE = { left: 37, up: 38, right: 39, down: 40 } const bootstrap = async () => { try { const { appKey, rdHost, ctHost, address, liveStartUrl } = env const { appId, sa, sas } = env const launch: Launcher = await RCRLaunch({ // appId, sa, sas, // ctHost, appKey, rdHost, // address, baseOptions: { startType: 1, webrtcEnable: true, // 默认为true }, extendOptions: { onPlay: () => { // 开始推流 launch.liveStart(liveStartUrl) // 按下和弹起 $('#direction').on('mousedown', e => { if (KEY_CODE.hasOwnProperty(e.target.id)) window.connection.send( new Keyboard(KEY_CODE[e.target.id], false, false, false, false, false, false, true).dumps() ) }) $('#direction').on('mouseup', e => { if (KEY_CODE.hasOwnProperty(e.target.id)) window.connection.send( new Keyboard(KEY_CODE[e.target.id], false, false, false, false, false, false, false).dumps() ) }) $('#info').on('click', () => { window.connection.send(new Keyboard(186, false, false, false, false, false, false, true).dumps()) // ;键按下 window.connection.send(new Keyboard(186, false, false, false, false, false, false, false).dumps()) // ;键弹起 }) $('#debug').on('click', () => { window.connection.send(new Keyboard(222, false, false, false, false, false, false, true).dumps()) // '键按下 window.connection.send(new Keyboard(222, false, false, false, false, false, false, false).dumps()) // '键弹起 }) $('#console').on('click', () => { window.connection.send(new Keyboard(192, false, false, false, false, false, false, true).dumps()) // ~键按下 window.connection.send(new Keyboard(192, false, false, false, false, false, false, false).dumps()) // ~键弹起 }) $('#ctrl-tilde').on('click', () => { window.connection.send(new Keyboard(192, false, false, true, false, false, false, true).dumps()) // ctrl+tilde键按下 window.connection.send(new Keyboard(192, false, false, true, false, false, false, false).dumps()) // ctrl+tilde键弹起 }) $('#ctrl-tab').on('click', () => { window.connection.send(new Keyboard(9, false, false, true, false, false, false, true).dumps()) // ctrl+tab键按下 window.connection.send(new Keyboard(9, false, false, true, false, false, false, false).dumps()) // ctrl+tab键弹起 }) $('#tab').on('click', () => { window.connection.send(new Keyboard(9, false, false, false, false, false, false, true).dumps()) // tab键按下 window.connection.send(new Keyboard(9, false, false, false, false, false, false, false).dumps()) // tab键弹起 }) $('#send-text').on('click', () => { const text = $('#text-input').val() window.connection.emitUIInteraction(text) // 发送消息 }) }, }, }) const container = $('#container')[0] await launch.automata(container) const connection = launch.getConnection() const livePlayer = launch.getPlayer() window.launch = launch window.connection = connection window.livePlayer = livePlayer // 当webrtcEnable为false时 if (!launch.option.baseOptions.webrtcEnable) { connection.event.dataChannelConnected.on(() => { // 开始推流 setTimeout(() => { launch.liveStart(liveStartUrl) }, 2000) }) } //监听连接状态 connection.event.close.on(() => console.log('断开连接')) } catch (error) { console.error(error) } } window.addEventListener('DOMContentLoaded', () => { if (navigator.userAgent.includes('miniProgram') || navigator.userAgent.includes('MicroMessenger')) { //微信浏览器/微信小程序环境 document.addEventListener('WeixinJSBridgeReady', bootstrap, false) } else { bootstrap() } })