atvoe = window.atvoe || {}; atvoe.TVSet = class extends bricks.HBox { constructor(opts){ super(opts); this.tv_icon = new bricks.Icon({ url:'/imgs/tv.png', rate:5 }); this.txt_w = new bricks.Text({text:opts.name || opts.id}); this.add_widget(this.tv_icon); this.add_widget(this.txt_w); } } atvoe.RTCBox = class extends bricks.VBox { constructor(opts){ super(opts); this.tvs_w = new bricks.HBox({cheight:5}); this.tvs_w.set_style('scroll', 'auto'); this.ctrl_w = new bricks.HBox({cheight:2}); this.channels_w = new bricks.Filler({}); this.add_widget(this.tvs_w); this.add_widget(this.ctrl_w); this.add_widget(this.channels_w); schedule_once(this.connect_wss.bind(this), 0.2); } loseWSSconnect(){ var w = new bricks.Error({ title:'Error', message:'websocket connection lose', timeout:5 }) w.open(); } async dc_msg(dc, msg){ console.log('dc_msg(), msg:', msg); } async connect_wss(){ this.deviceid = bricks.deviceid('atvoe'); this.info = await bricks.jc.get(this.info_url, { params:{ id:this.deviceid } }); this.signaling = new bricks.Signaling({ signaling_url:'wss://atvoe.com/wss/ws/rtc_signaling.ws', info:this.info, onlogin:this.show_tvs.bind(this), onclose:this.loseWSSconnect.bind(this), connect_opts:{ on_dc_open:this.rc_tvset.bind(this), on_dc_message:this.dc_msg.bind(this), on_pc_connected:this.pc_connected.bind(this), on_pc_disconnected:this.pc_disconnected.bind(this), data_connect:true, media_options:{ video:true, audio:true }, ice_servers:[ { "urls":"stun:stun.open-computing.cn:13478" }, { "urls":"turn:stun.open-computing.cn:13479", "username":"turn", "credential":"server" } ] } }); this.signaling.add_sessionhandler('p2p', bricks.RTCP2PConnect); } async pc_connected(peer){ console.log('-----connected to peer'); } async pc_disconnected(peer){ console.log('-----disconnected from peer'); } async show_tvs(peers){ console.log('online peers=', peers); this.tvs_w.clear_widgets(); peers.forEach(p => { var tv = new atvoe.TVSet(p); tv.bind('click', this.connect_tvset.bind(this, p)) this.tvs_w.add_widget(tv); }); } connect_tvset(peer){ this.remote_tv = peer; this.signaling.new_session('p2p', peer); } async rc_tvset(dc){ console.log('rc_tvset() called ....', arguments); this.pc_dc = dc; this.build_controller(); } build_controller(){ } } bricks.Factory.register('RTCBox', atvoe.RTCBox);