How to use userPreferences method in tracetest

Best JavaScript code snippet using tracetest

MultiPeersHandler.js

Source:MultiPeersHandler.js Github

copy

Full Screen

1function MultiPeers(connection) {2 var self = this;34 var skipPeers = ['getAllParticipants', 'getLength', 'selectFirst', 'streams', 'send', 'forEach'];5 connection.peersBackup = {};6 connection.peers = {7 getLength: function() {8 var numberOfPeers = 0;9 for (var peer in this) {10 if (skipPeers.indexOf(peer) == -1) {11 numberOfPeers++;12 }13 }14 return numberOfPeers;15 },16 selectFirst: function() {17 var firstPeer;18 for (var peer in this) {19 if (skipPeers.indexOf(peer) == -1) {20 firstPeer = this[peer];21 }22 }23 return firstPeer;24 },25 getAllParticipants: function(sender) {26 var allPeers = [];27 for (var peer in this) {28 if (skipPeers.indexOf(peer) == -1 && peer != sender) {29 allPeers.push(peer);30 }31 }32 return allPeers;33 },34 forEach: function(callbcak) {35 this.getAllParticipants().forEach(function(participant) {36 callbcak(connection.peers[participant]);37 });38 },39 send: function(data, remoteUserId) {40 var that = this;4142 if (!isNull(data.size) && !isNull(data.type)) {43 self.shareFile(data, remoteUserId);44 return;45 }4647 if (data.type !== 'text' && !(data instanceof ArrayBuffer) && !(data instanceof DataView)) {48 TextSender.send({49 text: data,50 channel: this,51 connection: connection,52 remoteUserId: remoteUserId53 });54 return;55 }5657 if (data.type === 'text') {58 data = JSON.stringify(data);59 }6061 if (remoteUserId) {62 var remoteUser = connection.peers[remoteUserId];63 if (remoteUser) {64 if (!remoteUser.channels.length) {65 connection.peers[remoteUserId].createDataChannel();66 connection.renegotiate(remoteUserId);67 setTimeout(function() {68 that.send(data, remoteUserId);69 }, 3000);70 return;71 }7273 remoteUser.channels.forEach(function(channel) {74 channel.send(data);75 });76 return;77 }78 }7980 this.getAllParticipants().forEach(function(participant) {81 if (!that[participant].channels.length) {82 connection.peers[participant].createDataChannel();83 connection.renegotiate(participant);84 setTimeout(function() {85 that[participant].channels.forEach(function(channel) {86 channel.send(data);87 });88 }, 3000);89 return;90 }9192 that[participant].channels.forEach(function(channel) {93 channel.send(data);94 });95 });96 }97 };9899 this.uuid = connection.userid;100101 this.getLocalConfig = function(remoteSdp, remoteUserId, userPreferences) {102 if (!userPreferences) {103 userPreferences = {};104 }105106 return {107 streamsToShare: userPreferences.streamsToShare || {},108 rtcMultiConnection: connection,109 connectionDescription: userPreferences.connectionDescription,110 userid: remoteUserId,111 localPeerSdpConstraints: userPreferences.localPeerSdpConstraints,112 remotePeerSdpConstraints: userPreferences.remotePeerSdpConstraints,113 dontGetRemoteStream: !!userPreferences.dontGetRemoteStream,114 dontAttachLocalStream: !!userPreferences.dontAttachLocalStream,115 renegotiatingPeer: !!userPreferences.renegotiatingPeer,116 peerRef: userPreferences.peerRef,117 channels: userPreferences.channels || [],118 onLocalSdp: function(localSdp) {119 self.onNegotiationNeeded(localSdp, remoteUserId);120 },121 onLocalCandidate: function(localCandidate) {122 localCandidate = OnIceCandidateHandler.processCandidates(connection, localCandidate)123 if (localCandidate) {124 self.onNegotiationNeeded(localCandidate, remoteUserId);125 }126 },127 remoteSdp: remoteSdp,128 onDataChannelMessage: function(message) {129 if (!connection.fbr && connection.enableFileSharing) initFileBufferReader();130131 if (typeof message == 'string' || !connection.enableFileSharing) {132 self.onDataChannelMessage(message, remoteUserId);133 return;134 }135136 var that = this;137138 if (message instanceof ArrayBuffer || message instanceof DataView) {139 connection.fbr.convertToObject(message, function(object) {140 that.onDataChannelMessage(object);141 });142 return;143 }144145 if (message.readyForNextChunk) {146 connection.fbr.getNextChunk(message, function(nextChunk, isLastChunk) {147 connection.peers[remoteUserId].channels.forEach(function(channel) {148 channel.send(nextChunk);149 });150 }, remoteUserId);151 return;152 }153154 if (message.chunkMissing) {155 connection.fbr.chunkMissing(message);156 return;157 }158159 connection.fbr.addChunk(message, function(promptNextChunk) {160 connection.peers[remoteUserId].peer.channel.send(promptNextChunk);161 });162 },163 onDataChannelError: function(error) {164 self.onDataChannelError(error, remoteUserId);165 },166 onDataChannelOpened: function(channel) {167 self.onDataChannelOpened(channel, remoteUserId);168 },169 onDataChannelClosed: function(event) {170 self.onDataChannelClosed(event, remoteUserId);171 },172 onRemoteStream: function(stream) {173 if (connection.peers[remoteUserId]) {174 connection.peers[remoteUserId].streams.push(stream);175 }176177 if (isPluginRTC && window.PluginRTC) {178 var mediaElement = document.createElement('video');179 var body = connection.videosContainer;180 body.insertBefore(mediaElement, body.firstChild);181 setTimeout(function() {182 window.PluginRTC.attachMediaStream(mediaElement, stream);183 }, 3000);184 return;185 }186187 self.onGettingRemoteMedia(stream, remoteUserId);188 },189 onRemoteStreamRemoved: function(stream) {190 self.onRemovingRemoteMedia(stream, remoteUserId);191 },192 onPeerStateChanged: function(states) {193 self.onPeerStateChanged(states);194195 if (states.iceConnectionState === 'new') {196 self.onNegotiationStarted(remoteUserId, states);197 }198199 if (states.iceConnectionState === 'connected') {200 self.onNegotiationCompleted(remoteUserId, states);201 }202203 if (states.iceConnectionState.search(/closed|failed/gi) !== -1) {204 self.onUserLeft(remoteUserId);205 self.disconnectWith(remoteUserId);206 }207 }208 };209 };210211 this.createNewPeer = function(remoteUserId, userPreferences) {212 if (connection.maxParticipantsAllowed <= connection.getAllParticipants().length) {213 return;214 }215216 userPreferences = userPreferences || {};217218 if (connection.isInitiator && !!connection.session.audio && connection.session.audio === 'two-way' && !userPreferences.streamsToShare) {219 userPreferences.isOneWay = false;220 userPreferences.isDataOnly = false;221 userPreferences.session = connection.session;222 }223224 if (!userPreferences.isOneWay && !userPreferences.isDataOnly) {225 userPreferences.isOneWay = true;226 this.onNegotiationNeeded({227 enableMedia: true,228 userPreferences: userPreferences229 }, remoteUserId);230 return;231 }232233 userPreferences = connection.setUserPreferences(userPreferences, remoteUserId);234 var localConfig = this.getLocalConfig(null, remoteUserId, userPreferences);235 connection.peers[remoteUserId] = new PeerInitiator(localConfig);236 };237238 this.createAnsweringPeer = function(remoteSdp, remoteUserId, userPreferences) {239 userPreferences = connection.setUserPreferences(userPreferences || {}, remoteUserId);240241 var localConfig = this.getLocalConfig(remoteSdp, remoteUserId, userPreferences);242 connection.peers[remoteUserId] = new PeerInitiator(localConfig);243 };244245 this.renegotiatePeer = function(remoteUserId, userPreferences, remoteSdp) {246 if (!connection.peers[remoteUserId]) {247 if (connection.enableLogs) {248 console.error('This peer (' + remoteUserId + ') does not exist. Renegotiation skipped.');249 }250 return;251 }252253 if (!userPreferences) {254 userPreferences = {};255 }256257 userPreferences.renegotiatingPeer = true;258 userPreferences.peerRef = connection.peers[remoteUserId].peer;259 userPreferences.channels = connection.peers[remoteUserId].channels;260261 var localConfig = this.getLocalConfig(remoteSdp, remoteUserId, userPreferences);262263 connection.peers[remoteUserId] = new PeerInitiator(localConfig);264 };265266 this.replaceTrack = function(track, remoteUserId, isVideoTrack) {267 if (!connection.peers[remoteUserId]) {268 throw 'This peer (' + remoteUserId + ') does not exist.';269 }270271 var peer = connection.peers[remoteUserId].peer;272273 if (!!peer.getSenders && typeof peer.getSenders === 'function' && peer.getSenders().length) {274 peer.getSenders().forEach(function(rtpSender) {275 if (isVideoTrack && rtpSender.track instanceof VideoStreamTrack) {276 connection.peers[remoteUserId].peer.lastVideoTrack = rtpSender.track;277 rtpSender.replaceTrack(track);278 }279280 if (!isVideoTrack && rtpSender.track instanceof AudioStreamTrack) {281 connection.peers[remoteUserId].peer.lastAudioTrack = rtpSender.track;282 rtpSender.replaceTrack(track);283 }284 });285 return;286 }287288 console.warn('RTPSender.replaceTrack is NOT supported.');289 this.renegotiatePeer(remoteUserId);290 };291292 this.onNegotiationNeeded = function(message, remoteUserId) {};293 this.addNegotiatedMessage = function(message, remoteUserId) {294 if (message.type && message.sdp) {295 if (message.type == 'answer') {296 if (connection.peers[remoteUserId]) {297 connection.peers[remoteUserId].addRemoteSdp(message);298 }299 }300301 if (message.type == 'offer') {302 if (message.renegotiatingPeer) {303 this.renegotiatePeer(remoteUserId, null, message);304 } else {305 this.createAnsweringPeer(message, remoteUserId);306 }307 }308309 if (connection.enableLogs) {310 console.log('Remote peer\'s sdp:', message.sdp);311 }312 return;313 }314315 if (message.candidate) {316 if (connection.peers[remoteUserId]) {317 connection.peers[remoteUserId].addRemoteCandidate(message);318 }319320 if (connection.enableLogs) {321 console.log('Remote peer\'s candidate pairs:', message.candidate);322 }323 return;324 }325326 if (message.enableMedia) {327 connection.session = message.userPreferences.session || connection.session;328329 if (connection.session.oneway && connection.attachStreams.length) {330 connection.attachStreams = [];331 }332333 if (message.userPreferences.isDataOnly && connection.attachStreams.length) {334 connection.attachStreams.length = [];335 }336337 var streamsToShare = {};338 connection.attachStreams.forEach(function(stream) {339 streamsToShare[stream.streamid] = {340 isAudio: !!stream.isAudio,341 isVideo: !!stream.isVideo,342 isScreen: !!stream.isScreen343 };344 });345 message.userPreferences.streamsToShare = streamsToShare;346347 self.onNegotiationNeeded({348 readyForOffer: true,349 userPreferences: message.userPreferences350 }, remoteUserId);351 }352353 if (message.readyForOffer) {354 connection.onReadyForOffer(remoteUserId, message.userPreferences);355 }356357 function cb(stream) {358 gumCallback(stream, message, remoteUserId);359 }360 };361362 function gumCallback(stream, message, remoteUserId) {363 var streamsToShare = {};364 connection.attachStreams.forEach(function(stream) {365 streamsToShare[stream.streamid] = {366 isAudio: !!stream.isAudio,367 isVideo: !!stream.isVideo,368 isScreen: !!stream.isScreen369 };370 });371 message.userPreferences.streamsToShare = streamsToShare;372373 self.onNegotiationNeeded({374 readyForOffer: true,375 userPreferences: message.userPreferences376 }, remoteUserId);377 }378379 this.connectNewParticipantWithAllBroadcasters = function(newParticipantId, userPreferences, broadcastersList) {380 if (connection.socket.isIO) {381 return;382 }383384 broadcastersList = (broadcastersList || '').split('|-,-|');385386 if (!broadcastersList.length) {387 return;388 }389390 var firstBroadcaster;391392 var remainingBroadcasters = [];393 broadcastersList.forEach(function(list) {394 list = (list || '').replace(/ /g, '');395 if (list.length) {396 if (!firstBroadcaster) {397 firstBroadcaster = list;398 } else {399 remainingBroadcasters.push(list);400 }401 }402 });403404 if (!firstBroadcaster) {405 return;406 }407408 self.onNegotiationNeeded({409 newParticipant: newParticipantId,410 userPreferences: userPreferences || false411 }, firstBroadcaster);412413 if (!remainingBroadcasters.length) {414 return;415 }416417 setTimeout(function() {418 self.connectNewParticipantWithAllBroadcasters(newParticipantId, userPreferences, remainingBroadcasters.join('|-,-|'));419 }, 3 * 1000);420 };421422 this.onGettingRemoteMedia = function(stream, remoteUserId) {};423 this.onRemovingRemoteMedia = function(stream, remoteUserId) {};424 this.onGettingLocalMedia = function(localStream) {};425 this.onLocalMediaError = function(error, constraints) {426 connection.onMediaError(error, constraints);427 };428429 function initFileBufferReader() {430 connection.fbr = new FileBufferReader();431 connection.fbr.onProgress = function(chunk) {432 connection.onFileProgress(chunk);433 };434 connection.fbr.onBegin = function(file) {435 connection.onFileStart(file);436 };437 connection.fbr.onEnd = function(file) {438 connection.onFileEnd(file);439 };440 }441442 this.shareFile = function(file, remoteUserId) {443 if (!connection.enableFileSharing) {444 throw '"connection.enableFileSharing" is false.';445 }446447 initFileBufferReader();448449 connection.fbr.readAsArrayBuffer(file, function(uuid) {450 var arrayOfUsers = connection.getAllParticipants();451452 if (remoteUserId) {453 arrayOfUsers = [remoteUserId];454 }455456 arrayOfUsers.forEach(function(participant) {457 connection.fbr.getNextChunk(uuid, function(nextChunk) {458 connection.peers[participant].channels.forEach(function(channel) {459 channel.send(nextChunk);460 });461 }, participant);462 });463 }, {464 userid: connection.userid,465 // extra: connection.extra,466 chunkSize: isFirefox ? 15 * 1000 : connection.chunkSize || 0467 });468 };469470 if (typeof 'TextReceiver' !== 'undefined') {471 var textReceiver = new TextReceiver(connection);472 }473474 this.onDataChannelMessage = function(message, remoteUserId) {475 textReceiver.receive(JSON.parse(message), remoteUserId, connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {});476 };477478 this.onDataChannelClosed = function(event, remoteUserId) {479 event.userid = remoteUserId;480 event.extra = connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {};481 connection.onclose(event);482 };483484 this.onDataChannelError = function(error, remoteUserId) {485 error.userid = remoteUserId;486 event.extra = connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {};487 connection.onerror(error);488 };489490 this.onDataChannelOpened = function(channel, remoteUserId) {491 // keep last channel only; we are not expecting parallel/channels channels492 if (connection.peers[remoteUserId].channels.length) {493 connection.peers[remoteUserId].channels = [channel];494 return;495 }496497 connection.peers[remoteUserId].channels.push(channel);498 connection.onopen({499 userid: remoteUserId,500 extra: connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {},501 channel: channel502 });503 };504505 this.onPeerStateChanged = function(state) {506 connection.onPeerStateChanged(state);507 };508509 this.onNegotiationStarted = function(remoteUserId, states) {};510 this.onNegotiationCompleted = function(remoteUserId, states) {};511512 this.getRemoteStreams = function(remoteUserId) {513 remoteUserId = remoteUserId || connection.peers.getAllParticipants()[0];514 return connection.peers[remoteUserId] ? connection.peers[remoteUserId].streams : [];515 };516517 this.isPluginRTC = connection.isPluginRTC = isPluginRTC; ...

Full Screen

Full Screen

reducer.js

Source:reducer.js Github

copy

Full Screen

1import confLoader from '../helpers/ConfLoader';2export default (settings = confLoader.config, { type, payload }) => {3 let { userPreferences } = settings;4 switch (type) {5 case 'VOLUME':6 userPreferences = { ...userPreferences, volume: payload };7 return { ...settings, userPreferences: { ...userPreferences } };8 case 'IRC_USER':9 userPreferences = { ...userPreferences, irc: { ...userPreferences.irc, username: payload } };10 return { ...settings, userPreferences: { ...userPreferences } };11 case 'IRC_PASS':12 userPreferences = { ...userPreferences, irc: { ...userPreferences.irc, password: payload } };13 return { ...settings, userPreferences: { ...userPreferences } };14 case 'IRC_IS_BOT':15 userPreferences = { ...userPreferences, irc: { ...userPreferences.irc, isBotAccount: payload } };16 return { ...settings, userPreferences: { ...userPreferences } };17 case 'OSU_API_KEY':18 userPreferences = { ...userPreferences, osuApi: { key: payload } };19 return { ...settings, userPreferences: { ...userPreferences } };20 case 'PREFIX':21 userPreferences = { ...userPreferences, prefix: payload };22 return { ...settings, userPreferences: { ...userPreferences } };23 case 'AUTOBEAT':24 userPreferences = { ...userPreferences, autoBeat: payload };25 return { ...settings, userPreferences: { ...userPreferences } };26 case 'AUTOIMPORT':27 userPreferences = { ...userPreferences, autoImport: payload };28 return { ...settings, userPreferences: { ...userPreferences } };29 case 'SETIMPORTMETHOD':30 userPreferences = { ...userPreferences, importMethod: payload };31 return { ...settings, userPreferences: { ...userPreferences } };32 case 'SIDEPANELEXPENDED':33 userPreferences = { ...userPreferences, sidePanelExpended: payload };34 return { ...settings, userPreferences: { ...userPreferences } };35 case 'SONGSPATH':36 userPreferences = { ...userPreferences, osuSongsPath: payload };37 return { ...settings, userPreferences: { ...userPreferences } };38 case 'OSUPATH':39 userPreferences = { ...userPreferences, osuPath: payload };40 return { ...settings, userPreferences: { ...userPreferences } };41 case 'LASTSCAN':42 userPreferences = { ...userPreferences, lastScan: payload };43 return { ...settings, userPreferences: { ...userPreferences } };44 case 'SET_THEME_ACCENT_COLOR':45 userPreferences = { ...userPreferences, theme: { accentColor: payload } };46 return { ...settings, userPreferences: { ...userPreferences } };47 case 'SET_IS_LAZER':48 userPreferences = { ...userPreferences, isLazer: payload };49 return { ...settings, userPreferences: { ...userPreferences } };50 default:51 return settings;52 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var userPreferences = tracetest.userPreferences;3var prefs = userPreferences();4console.log(prefs);5exports.userPreferences = function () {6 return {7 };8};

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var prefs = tracetest.userPreferences();3console.log(prefs);4var userPreferences = function() {5 return {name: 'John', age: 25};6}7exports.userPreferences = userPreferences;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var userPref = tracetest.userPreferences;3userPref.name = 'John';4userPref.age = 30;5var userPreferences = {};6exports.userPreferences = userPreferences;7var userPreferences = {};8module.exports = userPreferences;9var tracetest = require('tracetest');10var userPref = tracetest.userPreferences;11userPref.name = 'John';12userPref.age = 30;13var userPreferences = {};14module.exports.userPreferences = userPreferences;15var userPreferences = {};16exports.userPreferences = userPreferences;17var tracetest = require('tracetest');18var userPref = tracetest.userPreferences;19userPref.name = 'John';20userPref.age = 30;21var userPreferences = {};22module.exports.userPreferences = userPreferences;23var userPreferences = {};24exports.userPreferences = userPreferences;25var tracetest = require('tracetest');26var userPref = tracetest.userPreferences;27userPref.name = 'John';28userPref.age = 30;29var userPreferences = {};30module.exports.userPreferences = userPreferences;31var userPreferences = {};32exports.userPreferences = userPreferences;33var tracetest = require('tracetest');34var userPref = tracetest.userPreferences;35userPref.name = 'John';36userPref.age = 30;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2tracetest.userPreferences("pref1", "pref2", "pref3", "pref4");3module.exports = {4 userPreferences: function (pref1, pref2, pref3, pref4) {5 }6};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tracetest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful