gpt4 book ai didi

javascript - # Uncaught ReferenceError : safetxt is not defined #

转载 作者:行者123 更新时间:2023-11-28 07:21:01 25 4
gpt4 key购买 nike

Uncaught ReferenceError :safetxt 未定义

我正在尝试使用 pubnub 及其 webrtc sdk 构建一个视频和文本聊天 Web 应用程序,我想知道这段代码中哪里出错了;视频聊天工作正常 - 当我尝试发短信时出现错误。

<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<script src="http://stephenlb.github.io/webrtc-sdk/js/webrtc.js"></script>
<div><script>(function(){
// ~Warning~ You must get your own API Keys for non-demo purposes.
// ~Warning~ Get your PubNub API Keys: http://www.pubnub.com/get-started/
// The phone *number* can by any string value
var phone = PHONE({
number : '7898',
publish_key : 'demo',
subscribe_key : 'demo',
ssl : true
});

// As soon as the phone is ready we can make calls
phone.ready(function(){

// Dial a Number and get the Call Session
// For simplicity the phone number is the same for both caller/receiver.
// you should use different phone numbers for each user.
var session = phone.dial('9365');

});

// When Call Comes In or is to be Connected
phone.receive(function(session){
// Display Your Friend's Live Video
session.connected(function(session){
PUBNUB.$('video-out').appendChild(session.video);
});

});
var chat_in = PUBNUB.$('pubnub-chat-input');
var chat_out = PUBNUB.$('pubnub-chat-output');
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Send Chat MSG and update UI for Sending Messages
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
PUBNUB.bind( 'keydown', chat_in, function(e) {
if ((e.keyCode || e.charCode) !== 13) return true;
if (!chat_in.value.replace( /\s+/g, '' )) return true;
phone.send({ text : chat_in.value });
add_chat( '7898' + " (Me)", chat_in.value );
chat_in.value = '';
} )
function add_chat( number, text ) {
if (!text.replace( /\s+/g, '' )) return true;
var newchat = document.createElement('div');
newchat.innerHTML = PUBNUB.supplant(
'<strong>{number}: </strong> {message}', {
message : safetxt(text),
number : safetxt(number)
} );
chat_out.insertBefore( newchat, chat_out.firstChild );
}
function message( session, message ) {
add_chat( session.number, message.text );}
})();</script>

最佳答案

safetext() 方法

您可以找到演示中列出的源:https://github.com/stephenlb/webrtc-sdk/blob/gh-pages/index.html#L326-L331

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// XSS Prevention
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function safetxt(text) {
return (''+text).replace( /[<>]/g, '' );
}

关于javascript - # Uncaught ReferenceError : safetxt is not defined #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30323990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com