如何解决基于Firebase功能的云通用角度超时
我在firebase上部署了Angular Universal项目,并使用firebase函数为服务器端提供服务,也使用云构建来触发构建,这个问题只是在角度通用的服务器构建命令中卡住了,尽管有时它会一直重试,它也可以在本地工作,但有时在云上有时无法通过
云构建YAML
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build','-t','gcr.io/$PROJECT_ID/firebase','./dockerfiles/firebase']
- name: 'gcr.io/$PROJECT_ID/firebase'
args: [ 'use','$_PROJECT_NAME','--token','${_FIREBASE_TOKEN}']
- name: 'node:12.18.3'
entrypoint: npm
args: ['install']
- name: 'node:12.18.3'
entrypoint: npm
args: ['install','--prefix','functions']
- name: 'node:12.18.3'
entrypoint: npm
args: ['link']
- name: 'node:12.18.3'
entrypoint: npm
dir: 'functions'
args: ['install','-g','firebase-tools@latest']
- name: 'node:12.18.3'
entrypoint: npm
args: ['run-script','stage-browser']
- name: 'node:12.18.3'
entrypoint: npm
args: ['run-script','--debug','stage-server']
- name: 'node:12.18.3'
entrypoint: npm
dir: 'functions'
args: ['run-script','copyAndRename']
- name: 'gcr.io/$PROJECT_ID/firebase'
args: [ 'deploy','${_FIREBASE_TOKEN}']
timeout: 2000s
Firebase docker文件
FROM node:carbon
RUN npm install -g firebase-tools@latest
ENTRYPOINT ["/usr/local/bin/firebase"]
建立日志的时间太长了,无法在此处添加
运行脚本命令
"stage-browser": "node --max_old_space_size=16384 ./node_modules/@angular/cli/bin/ng build --prod --configuration=stage --aot --vendor-chunk --common-chunk --delete-output-path","stage-server": "node --max_old_space_size=16384 ./node_modules/@angular/cli/bin/ng run sf-mini:server:stage","copyAndRename": "node cp-angular.js",
解决方法
根据错误消息,这可能是由于云构建所创建的VM内具有执行这些步骤的权限所致。
为避免出现这些权限问题,您可以做的是使用 let peerConnections = {};
let peerConnectionsShare = {};
let pc1,pc1Share ;
useEffect(() => {
_startScreenCapture().then((stream) => {
userVideoShare.current.srcObject = stream
userVideoShare.current.play();
socket.emit('share');
setlocalStream(stream);
}).catch((e) => { console.log(e) });
navigator.mediaDevices.getUserMedia({video: true,audio: true }).then((stream) => {
stream.getTracks()[1].enabled = false;
stream.getTracks()[0].enabled = false;
userVideo.current.srcObject = stream
userVideo.current.play();
socket.emit('ready');
setlocalStream(stream);
}
).catch((e) => { console.log(e) })
},[])
socket.off('ready').on('ready',function (id,name) {
if (!(userVideo.current instanceof HTMLVideoElement) || !(userVideo.current.srcObject)) {
return;
}
pc1 = new RTCPeerConnection(STUN_SERVER);
peerConnections[id] = pc1;
if (userVideo.current instanceof HTMLVideoElement) {
pc1.addStream(userVideo.current.srcObject);
}
pc1.createOffer()
.then(sdp => pc1.setLocalDescription(sdp))
.then(function () {
socket.emit('offer',id,pc1.localDescription,name);
},{
'mandatory': {
'OfferToReceiveAudio': true,'OfferToReceiveVideo': true,}
});
pc1.onaddstream = event => {
console.log(event.stream)
handleRemoteStreamAdded(event.stream,name,display_style,userIcon,micIcon);
}
pc1.onicecandidate = function (event) {
if (event.candidate) {
socket.emit('candidate',event.candidate);
}
};
});
socket.off('offer').on('offer',description,name) {
const peerConnection = new RTCPeerConnection(STUN_SERVER);
peerConnections[id] = peerConnection;
if (userVideo.current instanceof HTMLVideoElement) {
peerConnection.addStream(userVideo.current.srcObject);
}
peerConnection.setRemoteDescription(description)
.then(() => peerConnection.createAnswer())
.then(sdp => peerConnection.setLocalDescription(sdp))
.then(function () {
socket.emit('answer',peerConnection.localDescription);
});
peerConnection.onaddstream = event => handleRemoteStreamAdded(event.stream,micIcon);
peerConnection.onicecandidate = function (event) {
if (event.candidate) {
socket.emit('candidate',event.candidate);
}
};
});
socket.off('candidate').on('candidate',candidate) {
peerConnections[id].addIceCandidate(new RTCIceCandidate(candidate))
.catch(e => console.error(e));
});
socket.off('answer').on('answer',description) {
peerConnections[id].setRemoteDescription(description);
});
socket.off('share').on('share',name) {
if (!(userVideoShare.current instanceof HTMLVideoElement) || !(userVideoShare.current.srcObject)) {
return;
}
pc1Share = new RTCPeerConnection(STUN_SERVER);
peerConnectionsShare[id] = pc1Share;
if (userVideoShare.current instanceof HTMLVideoElement) {
pc1Share.addStream(userVideoShare.current.srcObject);
}
pc1Share.createOffer()
.then(sdp => pc1Share.setLocalDescription(sdp))
.then(function () {
socket.emit('shareOffer',pc1Share.localDescription,}
});
pc1Share.onaddstream = event => {
console.log(event.stream)
handleRemoteStreamAdded(event.stream,micIcon);
}
pc1Share.onicecandidate = function (event) {
if (event.candidate) {
socket.emit('shareCandidate',event.candidate);
}
};
});
socket.off('shareOffer').on('shareOffer',name) {
const peerConnection = new RTCPeerConnection(STUN_SERVER);
peerConnectionsShare[id] = peerConnection;
if (userVideoShare.current instanceof HTMLVideoElement) {
peerConnection.addStream(userVideoShare.current.srcObject);
}
peerConnection.setRemoteDescription(description)
.then(() => peerConnection.createAnswer())
.then(sdp => peerConnection.setLocalDescription(sdp))
.then(function () {
socket.emit('shareAnswer',peerConnection.localDescription);
});
peerConnection.onaddstream = event => handleRemoteStreamAdded(event.stream,micIcon);
peerConnection.onicecandidate = function (event) {
if (event.candidate) {
socket.emit('shareCandidate',event.candidate);
}
};
});
socket.off('shareCandidate').on('shareCandidate',candidate) {
peerConnectionsShare[id].addIceCandidate(new RTCIceCandidate(candidate))
.catch(e => console.error(e));
});
socket.off('shareAnswer').on('shareAnswer',description) {
peerConnectionsShare[id].setRemoteDescription(description);
});
const _startScreenCapture = () => {
if (navigator.getDisplayMedia) {
return navigator.getDisplayMedia({ video: true });
} else if (navigator.mediaDevices.getDisplayMedia) {
return navigator.mediaDevices.getDisplayMedia({ video: true });
} else {
return navigator.mediaDevices.getUserMedia({ video: { mediaSource: 'screen' } });
}
}
使用sudo
进行操作时,会像这样:
sudo
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。