How to send Camera Stream from Unity to the web browser? - javascript

I am trying to connect a unity client to a browser client using Webrtc. This step is complete the two clients are now connected (Signaling is complete). What I need to do next is to send the video stream from the c# Camera object to the other peer (browser). Here's what have done which is not working and I do not know why?
The c# code :
var track = arCamera.CaptureStreamTrack(1280, 720, 3000);
localConnection.AddTrack(track);
Then I register the ontrack event for the RTCPeerConnection Object
The javascript code:
function handleTrack (e) {
console.log("Recieved a Track");
remotePeerVideo.current.srcObject = e.streams[0];
}
When I
console.log(e.streams); this is the result:
[MediaStream]
0:{active: true, id: "9322aaa7-69b6-4ef4-8f49-c457ef4ffd16"}
I add this track to the srcObj of a video element, but it does not work. Any Ideas what might be wrong or if there is another way to get the video stream from the c# Camera Object?

Related

Electron app using navigator.mediaDevices triggers antivirus "Webcam access attempt"

I have developed an electron app and for the first time ever, my antivirus (ESET) has raised "Webcam access attempt" when the app loads. Has anyone else experienced this?
My app does not use the webcam and I have no code that requires the webcam.
I do have code that accesses audio for audio recording. I have denied access to the webcam in antivirus and the app does function as designed. However, antivirus warning messages appear on every load of the app. As you can imagine, this is not cool.
This has surfaced immediately after updating ESET (v14.2.10.0), so they have some new rule that gets triggered. I have to assume that this is not an ESET over sensitivity to something (I have no idea how AV's function and ‘blaming’ the antivirus doesn’t seem like a sound response to provide users), so I am left questioning my deployment of web-apis in my code.
My audio access uses the native web-apis: AudioContext, Navigator, MediaDevices, MediaRecorder. The key lines of code are below:
// getting list of all AUDIO devices:
// const audioSources = await navigator.mediaDevices.enumerateDevices({ audio: true });
// ^ above does NOT filter by audio only
const audioSources = await navigator.mediaDevices.enumerateDevices();
// creating a recorder object:
const audioContext = new AudioContext();
const dest = audioContext.createMediaStreamDestination();
const audioParams = {
deviceId: "6e5fc2d7ffa5c6c04e06d282a5aa743e983e585a7e12118c80c0cd8646cce4b7", // this ID is from audioSources object
}
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: audioParams });
const audioIn = audioContext.createMediaStreamSource(mediaStream);
audioIn.connect(dest);
const audioOptions = {
bitsPerSecond: 128000,
mimeType: 'audio/webm; codecs=opus',
};
const recorder = new MediaRecorder(dest.stream, audioOptions);
Because navigator.mediaDevices.enumerateDevices() does not take parameters, such as { audio: true }, enumerateDevices() triggers the camera request.
I use the results of enumerateDevices() to access the device ID, which is then passed into .getUserMedia() to select the specific device. This allows users to select one or more audio inputs for the same recording.
Is there a way of just querying available media for audio devices / excluding video?
Is there another way of identifiying all available audio devices?
How else can I select what device .getUserMedia() returns as a stream?
The only existing information I could find on this was on the shut-down Atom Community forum:
Electron keeps accessing my webcam for NO REASON - two developers discovering the same behaviour in Sept'20 with different Antivirus software. No resolution.
Originally seen using Electron 8.5.0. Issue remains after updating to 13.1.2
Software versions: Electron 13.1.2, ESET 14.2.10.0

MediaElementJS Player + Reload HLS stream - Any Solution?

How do I stop showing the Network Error message and just autoreload the player when the player lose the connections with the stream?
I am using an HLS stream for this player: MediaElementJS
I found this solution in a blog but for me it is not the best option and can be difficult to set up a private proxy 24hs.
This can be solved externally by running an in-app proxy. I have the player in a wrapper that also starts up an HTTPListener. Then instead of giving the MediaElement http://server.com/file.m3u8, I rewrite this URL to http://localhost:58392/http/80/server.com/file.m3u8. FFmpeg hits the proxy with requests and the proxy parses the URL from the request, gets the content and returns it to ffmpeg.
This is my player configuration in js:
<script>
$("video").mediaelementplayer({
features: ["playpause", "volume", "progress", "airplay", "chromecast", "fullscreen"],
forceLive: true
});
playerObject = document.getElementById("player");
</script>
The solution is a two-step process:
First you need to attach an event to notify you of the player being created:
$("video").mediaelementplayer({
features: ["playpause", "volume", "progress", "airplay", "chromecast", "fullscreen"],
forceLive: true,
success: playerReady
});
Now, after the player is created, you can attach to the "ended" event of the player:
function playerReady(media, node, player) {
media.addEventListener('ended', function(e) {
//Do what you want, e.g. reload the page
});
}

How can I send push notification from javascript or c# to android - IOS and WinPhone

I implement push notification using this totarial. Now I want to send a notification from a website using server C# code or simply with a javascript code but the following link only implement sending notification using node:
var gcm = require('node-gcm');
var message = new gcm.Message();
//API Server Key
var sender = new gcm.Sender('AIzaSyCDx8v9R0fMsAsjoAffF-P3FCFWXlvwLhg');
var registrationIds = [];
// Value the payload data to send...
message.addData('message',"\u270C Peace, Love \u2764 and PhoneGap \u2706!");
message.addData('title','Push Notification Sample' );
message.addData('msgcnt','3'); // Shows up in the notification in the status bar
message.addData('soundname','beep.wav'); //Sound to play upon notification receipt - put in the www folder in app
//message.collapseKey = 'demo';
//message.delayWhileIdle = true; //Default is false
message.timeToLive = 3000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
// At least one reg id required
registrationIds.push('APA91bwu-47V0L7xB55zoVd47zOJahUgBFFuxDiUBjLAUdpuWwEcLd3FvbcNTPKTSnDZwjN384qTyfWW2KAJJW7ArZ-QVPExnxWK91Pc-uTzFdFaJ3URK470WmTl5R1zL0Vloru1B-AfHO6QFFg47O4Cnv6yBOWEFcvZlHDBY8YaDc4UeKUe7ao');
/**
* Parameters: message-literal, registrationIds-array, No. of retries, callback-function
*/
sender.send(message, registrationIds, 4, function (result) {
console.log(result);
});
I want to send notification automatically using website or something like this (I want to scheduling sending notification in some times for remind drug time to patient).
In addition, I found this : pubnub for sending notification but unfortunately, it's not work correctly. Pubnub demo doesn't work.
How can I do this? Please help me.
Can you give either of these a try if you're writing C# on the server side? :)
Azure Notification Hub
PushSharp
Personally I'd write a Windows Service that runs a loop to poll the database for any notifications it needs to send out, sends it to Azure Notification Hub or AWS Push Notifications, sleeps for awhile, and then repeats the process.
You don't want to do it on the client side of a web page because the only way the code could ever run is if you had a web browser open all the time pointing to the page.

Kurento datachannel creation and management

I'm developing a WebRTC application based in node.js and Kurento and I want to implement a chat using datachannels.
I've seen the browser javascript version and I want to integrate it in the one to one node.js example.
What I have done
1.- I've created both WebRTCEndpoints with datachannel capabilities like this: pipeline.create('WebRtcEndpoint', {useDataChannels: true}, function(error, calleeWebRtcEndpoint) {...}
2.- Then I've created a <textarea> with a <button> to send messages, and a <div> to view them.
So my question is, what servers I have to put when I create the datachannel in the client? This snippet is from the browser javascript datachannel tutorial but at the start of the file we can clearly see ICE servers are ignoring in the connection creation. Also, I don’t know how you manage them in the node.js tutorials, so I'm a bit lost here.
peerConnection = new RTCPeerConnection(servers, configuration);
channel = peerConnection.createDataChannel(getChannelName(), dataConstraints);
channel.onopen = onSendChannelStateChange;
channel.onclose = onSendChannelStateChange;
channel.onmessage = onMessage;`
Thanks for the help.
I've discovered what was I doing wrong and now the I can send messages by datachannels.
Basically what I've done is to add peerConnection option to the options object. Next that option object is passed to WebRtcPeerSendrecv connection method and it's done!
var options = {
peerConnection: peerConnection, //Must be passed as a field in options to make DataChannels work
localVideo : videoInput,
remoteVideo : videoOutput,
onicecandidate : onIceCandidate
}
webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(){...});

How to Create WebRTC + PubNub Open Source Video Chat,voice chat, using Javascript

Is it possible to Create live video and voice chat application in my website using WebRTC + PubNub.
Any one can help me to find out a good existing code and how to integrate. I am using joomla 2.5.
i need multiple and single channel video and audio streaming.
Yea they have a demo on the site you have to signup to try. http://www.pubnub.com/developers/webrtc/
Looks like you write code with the WebRTC libraries, and in PubNub fashion, the PubNub library provides methods for both subscribing and listen for new connections. (The PubNub library comes with the functionality to see what users come online and offline.) Is this what you're looking for? A sort of chat presence with ability to call users who are available? If so, probably a good idea to use PubNub.
If you are really a WebRTC beginner and are trying to get basic video calling between your Joomla website users, you could try open source SIP.js (sipjs.com) and OnSIP. That's written on top of WebRTC and SIP. You can get a quick user at getonsip.com. Like this is what making a video call looks like (starts call on page load, click end button to end the call):
In HTML
<script src="http://sipjs.com/download/sip-0.6.3.min.js">
<video id="remoteVideo"></video>
<video id="localVideo" muted="muted"></video>
<button id="endCall">End Call</button>
In JavaScript:
var session;
var endButton = document.getElementById('endCall');
endButton.addEventListener("click", function () {
session.bye();
alert("Call Ended");
}, false);
//Creates the anonymous user agent so that you can make calls
var userAgent = new SIP.UA();
//here you determine whether the call has video and audio
var options = {
media: {
constraints: {
audio: true,
video: true
},
render: {
remote: {
video: document.getElementById('remoteVideo')
},
local: {
video: document.getElementById('localVideo')
}
}
}
};
//makes the call
session = userAgent.invite('sip:youruser#yourdomain.onsip.com', options);
You can sign up for a quick user address at getonsip.com and login to the end point.

Categories

Resources