player.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import WebSocketServer from './websocketServer.js';
  2. class Player {
  3. constructor(option) {
  4. this.ws = null;
  5. this.options = option;
  6. this.events = {
  7. error: ()=>{}
  8. };
  9. }
  10. init() {
  11. //console.log('init');
  12. this.ws = new WebSocketServer(this.options);
  13. this.ws.init();
  14. }
  15. connect() {
  16. for(let i in this.events) {
  17. this.ws.setCallBack(i, this.events[i]);
  18. }
  19. this.ws.connect();
  20. }
  21. play() {
  22. //console.log('player')
  23. }
  24. pause() {
  25. //console.log('pause')
  26. }
  27. close() {
  28. this.ws.close();
  29. //console.log('close1')
  30. }
  31. /**
  32. * 绘制额外信息
  33. * @param obj
  34. */
  35. updateInfo(obj) {
  36. this.ws.updateInfo(obj);
  37. }
  38. setROI(data) {
  39. this.ws.setROI(data);
  40. }
  41. resetROI() {
  42. this.ws.resetROI();
  43. }
  44. getROIData() {
  45. return this.ws.getROIData();
  46. }
  47. setPolygonNum(num) {
  48. return this.ws.setPolygonNum(num);
  49. }
  50. /**
  51. * 自定义事件
  52. * 目前支持如下事件
  53. * [error] websocket连接失败
  54. * [noStream] 收不到码流
  55. * [canplay] 视频能够播放时触发
  56. * [initialCompleted] 视频初始化完成, 首次canplay
  57. * [ROIFinished] 手动绘制ROI完成时触发
  58. *
  59. * @param event 事件名
  60. * @param callback 事件响应函数
  61. */
  62. on(event, callback) {
  63. this.events[event] = callback;
  64. }
  65. }
  66. export default Player;