Pusher:无法播放客户端事件

时间:2016-04-23 14:28:59

标签: javascript laravel-5 webrtc pusher


我正在开发一个带有laravel 5的会议应用程序,我决定为此实现webRTC解决方案。
所以,我使用Pusher发送信号,但我有一个问题:我使用SimplePeerJs webRTC的事情,当我触发一个事件(在订阅和其他东西之后),我有以下错误:

Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Cannot broadcast client event (connection not subscribed to channel presence-chat)"}}}.

我的代码是:

Pusher.log = function(message) {
            if (window.console && window.console.log)
            {
                window.console.log(message);
            }
        };
        var currentUser = {
            nom: '{{ auth()->user()->first_name }}',
            id: {{ auth()->user()->id }},
            stream: undefined
        };
        var pusher = new Pusher('my_app_key', {
            authEndpoint: 'pusher/auth',
            auth: {
                headers: {
                    'X-CSRF-Token': '{{ csrf_token() }}'
                },
                params: {
                    name: currentUser.name,
                    id: currentUser.id
                }
            }
        });

        var channel = pusher.subscribe('presence-chat');

        var callback = function() {
            console.log('Channel members:', channel.members);
        };
        //
        channel.bind('pusher:subscription_succeeded', callback);
        channel.bind('pusher:subscription_error', function(PusherError){
            console.log(PusherError);
        });
        channel.bind('pusher:member_added', function(){
            console.log('Member Added');
        });
        channel.bind('pusher:member_removed', function(){
            console.log('Member Removed');
        });
        //peers stuff
        var peer = new SimplePeer({ initiator: true });

        peer.on('signal', function (data) {
            channel.trigger('client-signal-' + currentUser.id,
                    {
                        userId: currentUser.id,
                        data: data
                    });
        });

        peer.on('ready', function () {
            peer.send('hey peer, how is it going?')
        });

任何想法? 感谢。

1 个答案:

答案 0 :(得分:0)

问题是,在float被触发之前,Pusher客户端没有机会连接和订阅频道。您是否尝试将同行内容移动到订阅回调中?

peer.on('signal')