#Uncaught ReferenceError:未定义safetxt#

时间:2015-05-19 11:11:34

标签: javascript html5 webrtc pubnub

未捕获的ReferenceError:未定义safetxt

我正在尝试使用pubnubwebrtc sdk构建视频和文字聊天网络应用程序我想知道我在这段代码中出错的地方;视频聊天工作正常 - 当我尝试发短信时,我有错误。

<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>

1 个答案:

答案 0 :(得分:0)

safetext()方法

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

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