Documented scripts working only on desktops?

tandelaf

New Member
Hello all, newbie here.
I want to provide my broadcasters with a simple tool, so I grabbed this piece of code that works fine on desktops (as far as I tried), but the "publish" button will not do anything on a smartphone.
Any clues?
I'm also open to an alternative solution anyone may have.

My code:

HTML:

Code:
<!DOCTYPE html>

<html lang="en">

<head>

    <script type="text/javascript" src="https://flashphoner.com/downloads/builds/flashphoner_client/wcs_api-2.0/current/flashphoner.js"></script>

    <script type="text/javascript" src="twoway.js"></script>

</head>

<body onload="init_api()">

    <div id="publish" style="width:320px;height:240px;border: solid 1px"></div>

    <br/><input type="button" onclick="connect()" value="Publish"/><br/>

    <br/>

    <div id="play" style="width:320px;height:240px;border: solid 1px"></div>

    <br/><input type="button" onclick="clickplay()" value="Play"/>

</body>

</html>
JAVASCRIPT: (twoway.js)
Code:
//Status constants

var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;

var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;

//Websocket session

var session;

//Init Flashphoner API on page load

function init_api() {

    Flashphoner.init({});

}

//Connect to WCS server over websockets

function connect() {

    session = Flashphoner.createSession({

        urlServer: "wss://157.245.88.XXX:8443"

    }).on(SESSION_STATUS.ESTABLISHED, function(session) {

        publishStream(session);

    });

}

//Publish stream

function publishStream(session) {

    session.createStream({

        name: "tandelaf",

        display: document.getElementById("publish"),

    }).publish();

}

//Playing stream

function clickplay() {

    playStream(session);

}

function playStream(session) {

    session.createStream({

        name: "tandelaf",

        display: document.getElementById("play"),

    }).play();

}
 
Last edited by a moderator:

Max

Administrator
Staff member
Hello

Take a look at full Two Way Streaming example:


Does it work on mobile browsers?

When you publish or play stream from mobile browser like iOS Safari, you would need to call playFirstVideo() function

Code:
function publishBtnClick() {
    if (validateForm("streamerForm")) {
        $('#publishStream').prop('disabled', true);
        $(this).prop('disabled', true);
        if (Browser.isSafariWebRTC()) {
            Flashphoner.playFirstVideo(localVideo, true, PRELOADER_URL).then(function() {
                publishStream();
            });
            return;
        }
        publishStream();
    }
}
See also
 
Top