util.js 1.67 KB
var server = null;
if(window.location.protocol === 'http:')
	server = "https://janusctest.uccc.cc:24000/janus";
else
    server = "https://janusctest.uccc.cc:24000/janus";
var janus = null;
var roomhandler = null;
var feeds = [];
 //初始化
function init() {
	Janus.init({debug: "all", callback: function() {		
	    if(!Janus.isWebrtcSupported()) {
			bootbox.alert("No WebRTC support... ");
			return;
		}
	    janus = new Janus({
			server: server,
			success: function() {
				videoroom(i, body)
			},
			error: function(error) {
				Janus.error(error);
				bootbox.alert(error, function() {
				   window.location.reload();
				});
			},
			destroyed: function() {
				window.location.reload();
			}	
		})
	}
  })
}

function videoroom(i, body) {
	janus.attach({
		plugin: "janus.plugin.videoroom",
		opaqueId: "videoroom-"+Janus.randomString(12),
		success: function(pluginHandle) {
			roomhandler = pluginHandle;
			if (i == 1) {
				creatRoom(body);
			}
		},
		error: function(error) {
		},
		consentDialog: function(on) {
     	},
		mediaState: function(medium, on) {
		},
		webrtcState: function(on) {
		},
		onmessage: function(msg, jsep) {	
		},
		onlocalstream: function(stream) {
		},
		onremotestream: function(stream) {
		},
		oncleanup: function() {
		}
	});
}

function creatRoom(create) {
	Janus.log("插件 (" + roomhandler.getPlugin() + ", id=" + roomhandler.getId() + ")");
	roomhandler.send({"message": create, success: function(result) {
		var event = result["videoroom"];
		if (event === "created") {
			// url = "./home.html?name="+111+"&age="+12;
			// window.location = url;
		} else {
			Janus.debug("创建会议失败: " + result["error"]);
			janus.destroy();
		}
	  }
    });
}