javascript - # Uncaught ReferenceError : safetxt is not defined #

标签 javascript html webrtc pubnub

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/

相关文章:

javascript - Web存储API session 存储: delete all keys like XYZ

javascript - 如何禁用对 "twig"的评论?

html - 在没有表格的情况下对齐 HTML 和 CSS 中的 3 个图像

Android WebRTC 答案中的 m 行顺序与提供中的顺序不匹配。拒绝回答

webrtc - 如何使用替代监听端口配置 coturn?

webrtc - SCTP 和 webrtc

javascript - 如何在命令行上运行带有js代码的php文件?

javascript - 使用正则表达式验证任何字符串

javascript - Vuejs Bootstrap 选择文本不更新

javascript - 在移动设备上切换 bootstrap input-group-addon 和 input 的位置