Chạy dạng service mode:
./mq-p2p-client update-config agentId hoặc ./mq-p2p-client generate-id
./mq-p2p-client update-config SERVER https://p2p.demo.mqsolutions.vn
./mq-p2p-client add-protocol <local_port>
Ví dụ:
./mq-p2p-client add-protocol camera01 127.0.0.1:22 8082
./mq-p2p-client startup
Chạy dạng sdk mode:
import PeerConnection from 'mq-p2p-client';
(async () => {
const client = new PeerConnection({
peerId: "<device_id>",
server: "<server_address>"
});
await client.createConnection();
client.dialWithPort({
port: <local_port>, //8082
protocol: "<protocol>" //157.245.159.219:22
})
client.dialWithPort({
port: 8283,
protocol: "192.168.6.84:22"
})
})();
chạy dạng javascript module:
const PeerConnection = require('PeerConnection'); //import PeerConnection from 'mq-p2p-client'
const peer = new PeerConnection({
agentId: "local-peer-id",
peerId: "remote-peer-id",
server: "https://p2p.demo.mqsolutions.vn"
});
const result = await peer.createConnection();
const stream = peer.dial("127.0.0.1:8082");
Lấy stream ở client:
const videoElement = document.getElementById("video");
const PeerMediaStream = require('PeerMediaStream'); //import {PeerMediaStream} from 'mq-p2p-client'
await PeerMediaStream.connect({
peer: peer, //peerConnection được khởi tạo ở bước trên.
streamServer: "127.0.0.1:6002" //địa chỉ stream server theo remote IP. Mặc định là 127.0.0.1:6002, Optional.
videoElement: videoElement, //video element
cameraId: cameraId //ID của camera tại server stream.
});