@flashphoner/websdk (英语)
闪存电话机 WebCallServer JavaScript API (Web SDK)
闪光机 网络呼叫服务器 JavaScript API (Web SDK) 执行.
安装
npm 安装 @ flashphoner/ websdk
在浏览器中使用预建 Javascript 捆绑
双向流转. html:
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="node_modules/@flashphoner/websdk/flashphoner.js"></script>
<script type="text/javascript" src="two-way-streaming.js"></script>
</head>
<body onload="init_api()">
<div id="publish" style="width:320px;height:240px;border: solid 1px"></div>
<br/><button id="publishBtn">Publish</button><br/>
<br/>
<div id="play" style="width:320px;height:240px;border: solid 1px"></div>
<br/><button id="playBtn">Play</button><br/>
<br/>
<br/><button id="stopBtn">Stop</button><br/>
</body>
</html>
双向流式. js:
//Constants
var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;
var session;
var stream;
//Init Flashphoner API on page load
function init_api() {
Flashphoner.init({});
publishBtn.onclick = connect;
playBtn.onclick = playStream;
stopBtn.onclick = stopPublish;
}
//Connect to WCS server over websockets
function connect() {
session = Flashphoner.createSession({
urlServer: "wss://demo.flashphoner.com"
}).on(SESSION_STATUS.ESTABLISHED, function(session) {
publishStream(session);
});
}
//Publish stream
function publishStream(session) {
stream = session.createStream({
name: "stream",
display: document.getElementById("publish"),
});
stream.publish();
}
//Playing stream
function playStream() {
session.createStream({
name: "stream",
display: document.getElementById("play"),
}).play();
}
//Stopping stream
function stopPublish() {
stream.stop();
}
更多实例
文档
已知问题
WebSDK 正在以 webrtc/调整器 库版本不低于7.2.6. 在这方面,应避免直接使用这个图书馆和WebSDK.