Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
direktorn

Using TweenMax together with Websockets

Recommended Posts

Hi,

I want to use GSAP together with Websockets. I'm not that experienced with JS and async operations. 

 

The idea is to receive (Subscribe) to websocket events that will trigger an animation. The purpose is to display upcoming TV Programs on a website, just like notifications. They need to be animated the way my tween works now. If I get this working i'm planing to place them in a timeline instead of using delays, but as I'm new to tweens this was the easiest way for me :)

 

This works with my current code (see attached) but the nature of Websocket and the way I implement things I have two issues. 

  1. If I post multiple events to my websocket they fire and my DOM change during animation. I would need to have some sort of queue so that TweenMax is running to a "end" first. 
  2. After my first tween is done I have not really found i good way to "rest" the scene so I can trigger a new animation. I have tried clearProps and KillAll but not sure if I have been successful (mostly related to point 1 above) 

Do we have any brave sole that have used GSAP with Websockets (or Ajax) to deal with multiple events? Thanks in advance.

 

Sorry for the formatting. I'm using a timer to reload the page, this was a ugly way that allowed me to "reset" the DOM. I have the same method if my Websocket crashes. 

var conn = new ab.Session('ws://control.nebuchadnezzar.local:8080',
 function() {
conn.subscribe('NextShow', function(topic, data) {
console.log(data);

for(key in data.Program){
ticker.innerText = data.Program[key];
	TweenMax.to("#bar", 2, {left:1450,ease:Back.easeOut});
	TweenMax.to("#ticker", 2, {left:1560,ease:Back.easeOut, delay:0.5});
	TweenMax.to("#logo", 2, {left:1450,ease:Back.easeOut, delay:0.5});
        TweenMax.to("#ticker", 2, {left:1920,ease:Power2.easeOut, delay:10});
	TweenMax.to("#logo", 2, {left:1920,ease:Power2.easeOut, delay:10});
	TweenMax.to("#bar", 2, {left:1920,ease:Power2.easeOut, delay:10});
        TweenMax.to("#logo", 2, {opacity:0, delay:11});
	TweenMax.to("#ticker", 2, {opacity:0, delay:11});
	TweenMax.to("#bar", 2, {opacity:0, delay:11});

        console.log(ProgramEPG);
	setTimeout(function(){
	location.reload();
	},1000*30);

          }
});
},
        function() {
	  console.warn('WebSocket connection closed');
	   location.reload();
	 },
	 {'skipSubprotocolCheck': true, 'maxRetries': 60, 'retryDelay': 500}
	    );
Link to comment
Share on other sites

I've done stuff a lot of stuff with GSAP and sockets, like this demo here. 

See the Pen gPeeJN?editors=0010 by osublake (@osublake) on CodePen

 

It's using sockets to connect to a Firebase database. I'm using Angular to abstract away the async part, so you might not notice this by looking at the source code, but it's all done with promises.

 

I actually just made a post about using promises. See if this helps you out. 

https://greensock.com/forums/topic/16184-isactive-returns-false-even-if-animation-is-currently-playing/?p=71228

 

.

 

.

  • Like 1
Link to comment
Share on other sites

You switched over to Observables with TypeScript in Angular 2 yet Blake?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×