webapk.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. (function() {
  2. var e = {}.hasOwnProperty,
  3. t = function(t, r) {
  4. function o() {
  5. this.constructor = t
  6. }
  7. for(var n in r) e.call(r, n) && (t[n] = r[n]);
  8. return o.prototype = r.prototype, t.prototype = new o, t.__super__ = r.prototype, t
  9. };
  10. AV.WebSocketSource = function(e) {
  11. function r(e, t) {
  12. return this.serverUrl = e, this.fileName = t, "undefined" == typeof WebSocket || null === WebSocket ? this.emit("error", "This browser does not have WebSocket support.") : (this.socket = new WebSocket(this.serverUrl), null == this.socket.binaryType ? (this.socket.close(), this.emit("error", "This browser does not have binary WebSocket support.")) : (this.bytesLoaded = 0, this._setupSocket(), void 0))
  13. }
  14. return t(r, e), r.prototype.start = function() {
  15. // return this._send(JSON.stringify({
  16. // resume: !0
  17. // }))
  18. }, r.prototype.pause = function() {
  19. return
  20. }, r.prototype.reset = function() {
  21. return this._send(JSON.stringify({
  22. reset: !0
  23. }))
  24. }, r.prototype._send = function(e) {
  25. return this.open ? this.socket.send(e) : this._bufferMessage = e
  26. }, r.prototype._setupSocket = function() {
  27. var e = this;
  28. return this.socket.binaryType = "arraybuffer", this.socket.onopen = function() {
  29. return e.open = !0, e.fileName && e.socket.send(JSON.stringify({
  30. fileName: e.fileName
  31. })), e._bufferMessage ? (e.socket.send(e._bufferMessage), e._bufferMessage = null) : void 0
  32. }, this.socket.onmessage = function(t) {
  33. var r, o;
  34. r = new AV.Buffer(new Uint8Array(o))
  35. var se = t.data
  36. if(new Uint8Array(se)[0] == 0){
  37. // var messageData = new Uint8Array(se)
  38. // player.decode(messageData);
  39. // console.log('黄飞5')
  40. return
  41. }else{
  42. // console.log('黄飞6')
  43. // console.log('黄飞2',new Uint8Array(se)[0])
  44. return o = t.data, "string" != typeof o ? (r = new AV.Buffer(new Uint8Array(o)), e.bytesLoaded += r.length, e.length && e.emit("progress", 100 * (e.bytesLoaded / e.length)), e.emit("data", r)) : (o = JSON.parse(o), null != o.fileSize ? e.length = o.fileSize : null != o.error ? e.emit("error", o.error) : o.end ? e.socket.close() : void 0)
  45. }
  46. }, this.socket.onclose = function(t) {
  47. console.log('黄飞5')
  48. return e.open = !1, t.wasClean ? e.emit("end") : e.emit("error", "WebSocket closed uncleanly with code " + t.code + ".")
  49. }, this.socket.onerror = function(t) {
  50. console.log('黄飞6')
  51. return e.emit("error", t)
  52. }
  53. }, r
  54. }(AV.EventEmitter), AV.Asset.fromWebSocket = function(e, t) {
  55. var r;
  56. console.log('黄飞1')
  57. return r = new AV.WebSocketSource(e, t), new AV.Asset(r)
  58. }, AV.Player.fromWebSocket = function(e, t) {
  59. var r;
  60. console.log('黄飞2')
  61. return r = AV.Asset.fromWebSocket(e, t), new AV.Player(r)
  62. }
  63. }).call(this);