-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from SonicCloudOrg/v1.3.1-release
V1.3.1 release
- Loading branch information
Showing
12 changed files
with
669 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* 音频接受处理器 | ||
*/ | ||
import JMuxer from 'jmuxer'; | ||
import Socket from './socket'; | ||
|
||
const DEFAULT_WS_URL = 'ws://localhost:8080'; | ||
|
||
export default class AudioProcessor { | ||
constructor(options) { | ||
const wsUrl = options.wsUrl || DEFAULT_WS_URL | ||
/** | ||
* node: 'player', | ||
* mode: 'audio', | ||
* debug: true, | ||
* flushingTime: 0, | ||
* wsUrl | ||
*/ | ||
this.jmuxer = new JMuxer({ | ||
mode: 'audio', | ||
flushingTime: 0, | ||
// onReady() { | ||
// console.log('Jmuxer audio init onReady!'); | ||
// }, | ||
// onError(data) { | ||
// console.error('Buffer error encountered', data); | ||
// }, | ||
...options | ||
}); | ||
this.audioDom = document.getElementById(options.node) | ||
this.initWebSocket(wsUrl) | ||
} | ||
|
||
initWebSocket(url) { | ||
const that = this | ||
this.ws = new Socket({ | ||
url, | ||
binaryType: 'arraybuffer', | ||
isErrorReconnect: false, | ||
onmessage: function(event) { | ||
var data = that.parse(event.data); | ||
data && that.jmuxer.feed(data); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* 音频解析 | ||
* @param {*} data AAC Buffer 视频流 | ||
* @returns | ||
*/ | ||
parse(data) { | ||
let input = new Uint8Array(data) | ||
|
||
return { | ||
audio: input | ||
}; | ||
} | ||
|
||
onPlay() { | ||
this.audioDom.load() | ||
const playPromise = this.audioDom.play() | ||
if (playPromise !== undefined) { | ||
playPromise.then(() => { | ||
this.audioDom.play() | ||
}) | ||
} | ||
} | ||
|
||
onPause() { | ||
this.audioDom.pause() | ||
} | ||
|
||
onReload() { | ||
this.audioDom.load() | ||
} | ||
|
||
onDestroy() { | ||
this.ws.handleClose() | ||
this.audioDom.pause() | ||
this.jmuxer.destroy() | ||
} | ||
} |
Oops, something went wrong.