I found very good project on Github, but I can not understand all of it.
I installed a signaling server (socket.io) and a turn server. I'm trying to make an app for IOS and I'm using code like:
<video height="300" id="localVideo"></video>
<video id="remotesVideos"></video>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var phonertc = cordova.require('com.dooble.phonertc.PhoneRTC');
var socket = io('http://mysait.com:3000');
socket.on("connect", function() {
socket.emit("join", "myroom");
socket.on("message", function(message) {
console.log("GOT MESSAGE:");
message.payload.sdp = message.payload.sdp.replace(/(\r\n|\n|\r)/gm,"");
// when a message is received from the signaling server,
// notify the PhoneRTC plugin.
phonertc.receiveMessage(message.payload);
});
});
socket.on('connect',function() {
alert ('is connect!');
});
phonertc.call({
isInitator: true, // Caller or callee?
turn: {
host: 'turn:mysait.com:3478',
username: 'test',
password: 'test'
},
sendMessageCallback: function (data) {
// PhoneRTC wants to send a message to your target, use
// your signaling server here to send the message.
console.log(data);
socket.emit("message", data);
},
answerCallback: function () {
alert('Callee answered!');
},
disconnectCallback: function () {
alert('Call disconnected!');
},
video: { // Remove this property if you don't want video chat
localVideo: document.getElementById('localVideo'),
remoteVideo: document.getElementById('remoteVideo')
}
});
}
</script>
I have an alert when connection is made to server, but I don't see local and remote video. Can someone suggest what could be wrong? Can you send me example of client-side, I can't find it here.
It looks like this is a very old version of the demo app. The correct link is:
https://github.com/alongubkin/phonertc/tree/master/demo
Related
I'm building a basic audio/video chat feature and all seems to work fine but i'm not able to get rid of session and it doesn't get destroyed.
I have tried it just as in the docs:
call_session = OT.initSession(params['api_key'], params['session_id']);
I get session_id from server which is using PHP SDK.
Following are event streamCreated and streamDestroyed
call_session.on('streamCreated', function(event) {
call_stream = event.stream;
var subscriber = call_session.subscribe(event.stream, 'subscriber', {
insertMode: 'append'
}, CHAT_CALL.handleError);
});
call_session.on("streamDestroyed", function(event) {
console.log("Stream " + event.stream.name + " ended. " + event.reason);
});
And here is the session connect call:
call_session.connect(params['token'], function(error) {
// If the connection is successful, publish to the session
if (error) {
CHAT_CALL.handleError(error);
} else {
// console.log("Connected !!!");
// Create a publisher
call_publisher = OT.initPublisher('publisher', {
insertMode: 'append',
width: '100%',
height: '100%',
publishAudio: enable_audio,
publishVideo: enable_video,
// style: {
// buttonDisplayMode: 'on'
// }
}, CHAT_CALL.handleError);
call_session.publish(call_publisher, CHAT_CALL.handleError);
}
});
}
But the problematic part is the the below function where i try to unpublish and disconnect session.
end_call: function(){
call_session.disconnect();
call_session.unpublish(call_publisher);
call_publisher.destroy();
}
Calling end_call gives me below error:
The publisher XYZ is trying to unpublish from a session ABC it is not attached to (it is attached to no session)
Followed by below error:
Invalid state transition: Event 'disconnect' not possible in state 'disconnected'
I've come across the SimpleWebRTC package. Trying to get it to work, but can't seem to get the remote stream coming through. I'm also using Pusher for signalling, rather than the default that comes with SimpleWebRTC.
I've set up my own connection:
var myConnection = {
pusher: new Pusher('mypusherkey', { cluster: 'ap1' } ),
channel: null,
on: function (event, callback) {
this.pusher.bind (event, callback);
},
emit: function () {
if (arguments.length == 1) {
if (arguments[0] === "join") {
this.channel = this.pusher.subscribe(arguments[1]);
}
}
else
this.channel.trigger(arguments);
},
getSessionId: function() {
return this.pusher.connection.socket_id;
},
disconnect: function() {
this.pusher.disconnect();
}
};
Then I have the SimpleWebRTC initialisation:
var webrtc = new SimpleWebRTC({
// the id/element dom element that will hold "our" video
localVideoEl: 'localVideo',
// the id/element dom element that will hold remote videos
remoteVideosEl: 'remotesVideos',
// immediately ask for camera access
autoRequestMedia: true,
debug: true,
connection: myConnection
});
// we have to wait until it's ready
webrtc.on('readyToCall', function () {
console.log('ready to join');
// you can name it anything
webrtc.joinRoom('test-video-chat');
});
Doing a simple test between 2 PCs, it's not setting up the remote stream. In the dev console apart from the intitial event hook ups, I'm not seeing any other activity happening, especially SimpleWebRTC "readyToCall" not firing.
you probably need to emit a 'connect' signal from your socket adapter to trigger this code
I am using smsCordova plugin to send sms from my ionic application but getting the error that "SMS is not defined".
I had used the cordovaSms plugin in $ionicPlatform.ready() function.
Here is my code which i am using to send the SMS :-
//use verifyNumber service
verifyNumberService.verify()
.then(
function (result) {
if (result == "Successfully data save...") {
//alert and navigate to profile Info state
$ionicPopup.alert({
title: 'Registered',
template: 'Thanks For Signup'
});
$ionicPlatform.ready(function() {
alert("in device ready function")
sendOtp();
});
$state.go('profileInfo');
}
This is the function to sendOtp() :-
function sendOtp() {
alert("inside send otp");
$cordovaSms
.send('+919765293765', "Hi there",{})
.then(function () {
// Success! SMS was sent
alert("success")
console.log('Success');
}, function (error) {
// An error occurred
alert("error");
console.log(error);
});//then
alert("send otp");
}
Azhar Khan,
If we wants to use the send sms request in cordova, then
1. we need to install this plugin in you app :
cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
2.Need to add that plugin instance($cordovaSms) in Controler function :
.controller('ThisCtrl', function($cordovaSms) {
});
Now we can send the sms throw that plugin using this code inside you controler :
document.addEventListener("deviceready", function () {
$cordovaSms.send('mobile_number', 'SMS Message', options)
.then(function() {
alert(SMS sent )
}, function(error) {
alert(Problem in sending SMS)
});
});
Thats all we need for sending SMS to any number in ionic
Have a happy code day.
The user will click on a button that will invoke the Parse Cloud function sendText()
I've tried both Live Twilio and Testing Twilio accSID and authToken
I first initialize my Twilio by:
var Twilio = require('twilio');
Twilio.initialize('accountSid', 'authToken'); //put in my corresponding <<
then I set the Parse function by:
Parse.Cloud.define('sendText', function(request, response) {
Twilio.sendSMS({
From: '+1234567890', //From Number
To: "+0987654321", //To Number
Body: "Start using Parse and Twilio!" //Message <<
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
}
It would be great to have someone tell me if something here is wrong or if there are other approaches in sending SMS through Twilio via Parse Cloud.
On the SMS Summary on Twilio, it does not even know any SMS being sent out.
Going on...
The button that calls this cloud function is:
<button type="button" class="page-scroll btn btn-xl" onclick="saveData()">CONFIRM</button>
and the js function that is called saveData() is:
function saveData() {
booking.save({
something: something,
}, {
success: function (booking) {
window.location.href = 'final.php';
Parse.Cloud.run('sendText',
{
something: something
});
},
error: function (booking, error) {
alert('Failed to save');
}
});
}
NO ERROR LOG
Twilio developer evangelist here.
You seem to be using an old Parse module which is no longer supported by us. The new module however uses a newer version of our Node module.
Some documentation for it can be found here
It also has some sample code to do what you're trying to do.
// Require and initialize the Twilio module with your credentials
var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');
// Send an SMS message
client.sendSms({
to:'+0987654321',
from: '+1234567890',
body: 'Hello world!'
}, function(err, responseData) {
if (err) {
console.log(err);
} else {
console.log(responseData.from);
console.log(responseData.body);
}
}
);
I think you will find your SMS will be sent using this version of the code. Notice how the initialization is different.
This is my original client code
var socket = io.connect('http://localhost:7048');
socket.on('channel', function (mess) {
console.log(mess);
});
socket.on('message', function (mess) {
console.log(mess);
});
How can I extend the original library so that you get something like this. Such code is used by pubnub.
var myPlugin = MYPLUGIN({
host: 'http://localhost:7048'
});
myPlugin.listen({
channel: 'channel',
message: function(m){console.log(m)},
error: function(m){console.log(m)}
});
myPlugin.listen({
channel: 'message',
message: function(m){console.log(m)},
error: function(m){console.log(m)}
});
myPlugin.unlisten({
channel : 'message',
});
If you're trying to make it like the code on pubnub just because pubnub uses this kind of syntax and you're used to it, I don't recommend on doing it, but if you have an API and you need to have a certain architecture then that's fine.
I recommend building a wrapper.
function MyPlugin(hostObj) {
function listen(listenObj) {
//your code here
}
function unlisten(unlistenObj) {
//your code here
}
//this makes your functions public
Object.defineProperties(this, {
"listen": {value: listen},
"unlisten": {value: unlisten}
});
return this;
}